=
最近排查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
-h
-p
-s
-a
-c
-n
-d
-dbnum
-k
-r
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
-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
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
-p
-s
-a
-c
-n
-d
-dbnum
-k
-r
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
-q Quiet. Just show query/sec values //安静,仅仅展示每秒的查询值
--csv Output in CSV format //输出按CSV格式
-l Loop. Run the tests forever
-t
names are the same as the ones produced as output.
-I Idle mode. Just open N idle connections and wait. //闲置模型,进打开N个闲置链接且等待
=
=