场景介绍
redis-benchmark 是 redis 官方自带的性能测试工具,通过不同的参数选择,可以有效的测试 redis 实例的性能
操作步骤
Redis-benchmark使用说明
(base) [root@rudonx src]# ./redis-benchmark --help
Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests>] [-k <boolean>]
-h <hostname> Server hostname (default 127.0.0.1)
-p <port> Server port (default 6379)
-s <socket> Server socket (overrides host and port)
-a <password> Password for Redis Auth
--user <username> Used to send ACL style 'AUTH username pass'. Needs -a.
-c <clients> Number of parallel connections (default 50)
-n <requests> Total number of requests (default 100000)
-d <size> Data size of SET/GET value in bytes (default 3)
--dbnum <db> SELECT the specified db number (default 0)
--threads <num> Enable multi-thread mode.
--cluster Enable cluster mode.
--enable-tracking Send CLIENT TRACKING on before starting benchmark.
-k <boolean> 1=keep alive 0=reconnect (default 1)
-r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD
Using this option the benchmark will expand the string __rand_int__
inside an argument with a 12 digits number in the specified range
from 0 to keyspacelen-1. The substitution changes every time a command
is executed. Default tests use this to hit random keys in the
specified range.
-P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline).
-e If server replies with errors, show them on stdout.
(no more than 1 error per second is displayed)
-q Quiet. Just show query/sec values
--precision Number of decimal places to display in latency output (default 0)
--csv Output in CSV format
-l Loop. Run the tests forever
-t <tests> Only run the comma separated list of tests. The test
names are the same as the ones produced as output.
-I Idle mode. Just open N idle connections and wait.
命令示例
- 使用 200 个并发连接、10000 个请求检测端口为 6379 的 Redis 服务器性能
redis-benchmark -h xxx.xxx.xx.xx -p 6379 -a xxxxx -n 10000 -c 200
- 测试获取大小为 200 字节的数据包的性能
redis-benchmark -h xxx.xxx.xx.xx -p 6379 -a xxxxx -d 200
- 仅使用 SET测试,key 数量为 100 万
redis-benchmark -h xxx.xxx.xx.xx -p 6379 -a xxxxx -t set -n 1000000 -r 100000000
- 仅测试少量命令,如 ping,set,get,并将结果输出到 CSV 中
redis-benchmark -h xxx.xxx.xx.xx -p 6379 -a xxxxx -t ping,set,get -n 100000 --csv