=
最近排查redis的问题和优化,真费劲儿。
功夫都在细节处。
=
测试暂时用的脚本如下,还是能发现不少问题的。
-c并发数,
-n请求数,
-q仅仅输出简要结果避免太长,
-d以字节的形式指定 SET/GET 值的数据大小,
-r(Use random keys 且 指定key的长度,比如30)
./redis-benchmark -n 1000000 -q
./redis-benchmark -n 1000000 -q -r 30
./redis-benchmark -n 1000000 -q -r 50
./redis-benchmark -n 1000000 -q -r 80
./redis-benchmark -n 1000000 -q -r 30
./redis-benchmark -n 1000000 -q -r 30 -c 50
./redis-benchmark -n 1000000 -q -r 30 -c 50 -d 1024
./redis-benchmark -n 1000000 -q -r 30 -c 50 -d 2048
./redis-benchmark -n 1000000 -q -r 30 -d 398092
=
#首先看看标准文档,其实总比各种文要全。排查问题,很多还得弄的仔细些。
./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
-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).
-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
--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.
Examples:
Run the benchmark with the default configuration against 127.0.0.1:6379:
$ redis-benchmark
Use 20 parallel clients, for a total of 100k requests, against 192.168.1.1:
$ redis-benchmark -h 192.168.1.1 -p 6379 -n 100000 -c 20
Fill 127.0.0.1:6379 with about 1 million keys only using the SET test:
$ redis-benchmark -t set -n 1000000 -r 100000000
Benchmark 127.0.0.1:6379 for a few commands producing CSV output:
$ redis-benchmark -t ping,set,get -n 100000 --csv
Benchmark a specific command line:
$ redis-benchmark -r 10000 -n 10000 eval 'return redis.call("ping")' 0
Fill a list with 10000 random elements:
$ redis-benchmark -r 10000 -n 10000 lpush mylist __rand_int__
On user specified command lines __rand_int__ is replaced with a random integer
with a range of values selected by the -r option.
#例子
测试命令事例:
1、redis-benchmark -h 192.168.1.201 -p 6379 -c 100 -n 100000
100个并发连接,100000个请求,检测host为localhost 端口为6379的redis服务器性能
2、redis-benchmark -h 192.168.1.201 -p 6379 -q -d 100
测试存取大小为100字节的数据包的性能
3、redis-benchmark -t set,lpush -n 100000 -q
只测试某些操作的性能
4、redis-benchmark -n 100000 -q script load "redis.call('set','foo','bar')"
只测试某些数值存取的性能
中文参考:redis-benchmark http://www.runoob.com/redis/redis-benchmarks.html
redis-benchmark使用方法总结 https://blog.csdn.net/xubo245/article/details/48320689 中文翻译:
-h <hostname> Server hostname (default 127.0.0.1) //服务主机名
-p <port> Server port (default 6379) //服务器端口号
-s <socket> Server socket (overrides host and port) //socket,覆盖host和port
-a <password> Password for Redis Auth //密码
-c <clients> Number of parallel connections (default 50) //并行请求的客户端数量,默认50
-n <requests> Total number of requests (default 100000) //请求的总量,默认100000
-d <size> Data size of SET/GET value in bytes (default 2) //set或get的数据尺寸,单位是字节,默认是2
-dbnum <db> SELECT the specified db number (default 0) //选择指定的数据号
-k <boolean> 1=keep alive 0=reconnect (default 1) //布尔量,1代表保持活跃,0代表重连
-r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD //set/get/incr使用随机的keys,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). //管道请求,默认是1,没管道(并行?)
-q Quiet. Just show query/sec values //安静,仅仅展示每秒的查询值
--csv Output in CSV format //输出按CSV格式
-l Loop. Run the tests forever
-t <tests> Only run the comma separated list of tests. The test //仅仅运行tests
names are the same as the ones produced as output.
-I Idle mode. Just open N idle connections and wait. //闲置模型,进打开N个闲置链接且等待
=
=