redis:redis-benchmark 女爷i 2022-09-15 11:44 157阅读 0赞 redis-benchmark可以为redis做基准性测试,它提供了很多选项帮助开发和运维人员测试redis的相关属性 # 选项 # 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 -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 2) --dbnum <db> SELECT the specified db number (default 0) -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). -q Quiet. Just show query/sec values --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. ## \-c、-n ## * `-c(clients)`选项代表客户端的并发数量 * \-`n(num)`选项代表客户端请求总量(默认是10000)。 例如redis-benchmark -c 100 -n 20000代表100个客户端同时请求Redis,一共执行20000次。 redis-benchmark会对各类数据结构的命令进行测试,并给出性能指标 ====== GET ====== 20000 requests completed in 0.17 seconds 100 parallel clients 3 bytes payload keep alive: 1 95.92% <= 1 milliseconds 99.75% <= 2 milliseconds 100.00% <= 2 milliseconds 116959.06 requests per second 例如上面一共执行了20000次操作,在0.17秒完成,每个请求是3个字节,95.92%的命令执行时间小于1毫秒,Redis每秒可以处理116959.06次get请求。 ## \-q ## \-q选项仅仅显示redis-benchmark的requests per second1信息: [root@Redis ~]# redis-benchmark -c 100 -n 20000 -q PING_INLINE: 113636.37 requests per second PING_BULK: 121951.22 requests per second SET: 115606.94 requests per second GET: 118343.20 requests per second INCR: 116959.06 requests per second LPUSH: 113636.37 requests per second LPOP: 113636.37 requests per second SADD: 114285.72 requests per second SPOP: 108695.65 requests per second LPUSH (needed to benchmark LRANGE): 104166.66 requests per second LRANGE_100 (first 100 elements): 46403.71 requests per second LRANGE_300 (first 300 elements): 19940.18 requests per second LRANGE_500 (first 450 elements): 11750.88 requests per second LRANGE_600 (first 600 elements): 11117.29 requests per second MSET (10 keys): 85470.09 requests per second ## \-r:向redis插入更多的随机键 ## 一个空的Redis上执行了redis-benchmark会发现只有三个键: [root@chenxing2 redis]# redis-cli 127.0.0.1:6379> dbsize (integer) 3 127.0.0.1:6379> keys * 1) "key:__rand_int__" 2) "counter:__rand_int__" 3) "mylist" 如果想向Redis插入更多的键,可以执行使用-r(random)选项,可以向Redis插入更多的随机键。 [root@chenxing2 redis]# redis-benchmark -c 100 -n 20000 -r 10000 \-r选项会在key、counter键上加一个12位的后缀,-r 10000代表只对后四位做随机处理(-r不是随机数的个数), 例如上面操作后,key的数量和结果结构如下: 127.0.0.1:6379> dbsize (integer) 18656 127.0.0.1:6379> scan 0 1) "5120" 2) 1) "counter:000000002683" 2) "key:000000008908" 3) "counter:000000005887" 4) "counter:000000008039" 5) "key:000000001037" 6) "key:000000004592" 7) "counter:000000003728" 8) "counter:000000009443" 9) "counter:000000000413" 10) "key:000000009427" ## \-p ## \-p选项代表每个请求pipline的数据量(默认位1). ## \-k < boolean> ## \-k选项代表客户端是否使用keepalive,1为使用,0为不使用,默认值为1. ## \-t ## \-t选项可以对指定命令进行基准测试 [root@chenxing2 redis]# redis-benchmark -t get,set -q SET: 96246.39 requests per second GET: 106951.88 requests per second ## –csv ## –csv选项会将结果按照CSV格式输出,便于后续处理,如导出到Execl等。 [root@chenxing2 redis]# redis-benchmark -t get,set -q --csv "SET","101010.10" "GET","106837.61"
还没有评论,来说两句吧...