nosqlredis数据库压力测试基准工具redis-benchmark怎么用

这篇文章将为大家详细讲解有关NOSQL redis数据库压力测试基准工具redis-benchmark怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

成都服务器托管,创新互联建站提供包括服务器租用、资阳移动机房、带宽租用、云主机、机柜租用、主机租用托管、CDN网站加速、域名注册等业务的一体化完整服务。电话咨询:18982081108

1,查看基准测试工具的用法
[root@langfang src]# pwd
/redis_dir/redis-4.0.9/src
[root@langfang src]# ./redis-benchmark  -help
Invalid option "-help" or option argument missing


Usage: redis-benchmark [-h ] [-p ] [-c ] [-n ] [-k ]


 -h      Server hostname (default 127.0.0.1) -h 连接REDIS服务器IP,默认为127.0.0.1
 -p          Server port (default 6379)    -P REDIS服务器端口 ,默认为6379
 -s        Server socket (overrides host and port)  -S 服务器套接字(覆盖主机和端口)
 -a      Password for Redis Auth --A REDIS AUTH的认证密码
 -c       Number of parallel connections (default 50)  --c 表示并发连接数量,默认50个
 -n      Total number of requests (default 100000)  ---n 请求的总数量,默认为100000,即10万
 -d          Data size of SET/GET value in bytes (default 3) --D 表示SET GET的大小,默认大小为3
 --dbnum       SELECT the specified db number (default 0)  --dbnum 指定连接哪个数据库,默认为0号数据库
 -k       1=keep alive 0=reconnect (default 1)  -k 布尔类型,1为保持连接,默认值;0为重连
 -r   Use random keys for SET/GET/INCR, random values for SADD --r 为SET GET INCR操作使用随机的键,为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        Pipeline requests. Default 1 (no pipeline).  --P 与管道技术有关,请求的次数,默认为1,即禁用管道技术,假如服务器报错,显示报错信息
 -e                 If server replies with errors, show them on stdout.  
                    (no more than 1 error per second is displayed) --仅仅每秒显示1个报错
 -q                 Quiet. Just show query/sec values  -Q 安静,仅仅显示 每秒 查询值
 --csv              Output in CSV format --CSV 以CSV格式输出
 -l                 Loop. Run the tests forever -L 一直压测,不停止
 -t         Only run the comma separated list of tests. The test -T   -L 运行以 逗 号分隔的测试列表,指定具体的压力测试场景,比如是set or mget or get and so on
                    names are the same as the ones produced as output.
 -I                 Idle mode. Just open N idle connections and wait. --L 空闲模式,只是打开N个空闲连接然后等待


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.
[root@langfang src]# 










2,redis-benchmark默认压力测试
--压力测试结论包括  压力测试消耗时间及每秒最大处理的请求数以及各种的压力测试场景的不同子节
[root@langfang src]# ./redis-benchmark 
====== PING_INLINE ======    ---概述的名称
  100000 requests completed in 1.51 seconds  --概要结论,消耗 1.51秒 完成 10万次请求
  50 parallel clients
  3 bytes payload
  keep alive: 1


96.26% <= 1 milliseconds
99.96% <= 2 milliseconds
100.00% <= 2 milliseconds
66181.34 requests per second   --每秒完成 6.6万左右请求


====== PING_BULK ======
  100000 requests completed in 1.70 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


93.00% <= 1 milliseconds
99.98% <= 2 milliseconds
100.00% <= 2 milliseconds
58788.95 requests per second


====== SET ======
  100000 requests completed in 1.69 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


92.51% <= 1 milliseconds
99.95% <= 2 milliseconds
100.00% <= 2 milliseconds
59241.71 requests per second


====== GET ======
  100000 requests completed in 1.53 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


96.22% <= 1 milliseconds
99.97% <= 2 milliseconds
100.00% <= 2 milliseconds
65402.22 requests per second


====== INCR ======
  100000 requests completed in 1.55 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


95.60% <= 1 milliseconds
100.00% <= 2 milliseconds
100.00% <= 2 milliseconds
64683.05 requests per second


====== LPUSH ======
  100000 requests completed in 1.52 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


94.17% <= 1 milliseconds
99.99% <= 2 milliseconds
100.00% <= 2 milliseconds
65573.77 requests per second


====== RPUSH ======
  100000 requests completed in 1.57 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


94.06% <= 1 milliseconds
99.97% <= 2 milliseconds
100.00% <= 2 milliseconds
63734.86 requests per second


====== LPOP ======
  100000 requests completed in 1.51 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


94.25% <= 1 milliseconds
99.98% <= 2 milliseconds
100.00% <= 2 milliseconds
66269.05 requests per second


====== RPOP ======
  100000 requests completed in 1.52 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


95.01% <= 1 milliseconds
99.95% <= 2 milliseconds
100.00% <= 2 milliseconds
65919.58 requests per second



====== LPUSH (needed to benchmark LRANGE) ======
  100000 requests completed in 1.50 seconds
  50 parallel clients




====== LRANGE_500 (first 450 elements) ======
  100000 requests completed in 10.29 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


3.16% <= 1 milliseconds
22.80% <= 2 milliseconds
46.08% <= 3 milliseconds
65.75% <= 4 milliseconds
81.96% <= 5 milliseconds
94.78% <= 6 milliseconds




====== MSET (10 keys) ======
  100000 requests completed in 2.06 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


57.05% <= 1 milliseconds
98.41% <= 2 milliseconds
99.98% <= 3 milliseconds
100.00% <= 3 milliseconds
48567.27 requests per second




[root@langfang src]# 




3,还是各种压测场景,不过是20个并发,10万次请求,连接指定REDIS服务器
[root@langfang src]# ./redis-benchmark -h 127.0.0.1 -p 6379 -n 100000 -c 20
====== PING_INLINE ======
  100000 requests completed in 1.63 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1


99.69% <= 1 milliseconds
100.00% <= 1 milliseconds
61312.08 requests per second


====== PING_BULK ======
  100000 requests completed in 1.67 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1




4,指定测试场景比如 GET AND SET 以及随机键的数量以及请求个数
[root@langfang src]# ./redis-benchmark  -t set,get -n 100000 -r 1000
====== SET ======
  100000 requests completed in 1.60 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


94.68% <= 1 milliseconds
99.93% <= 2 milliseconds
100.00% <= 2 milliseconds
62656.64 requests per second


====== GET ======
  100000 requests completed in 1.68 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


93.91% <= 1 milliseconds
99.93% <= 2 milliseconds
100.00% <= 2 milliseconds
59488.40 requests per second




5,csv格式输出
[root@langfang src]# ./redis-benchmark -t ping,get,set -n 1000 --csv
"PING_INLINE","52631.58"
"PING_BULK","55555.56"
"SET","52631.58"
"GET","52631.58"


6,运行特定的命令行
[root@langfang src]# ./redis-benchmark  -r 1000 -n 100000 eval 'return redis.call("ping")'
====== eval return redis.call("ping") ======
  100000 requests completed in 1.56 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


95.66% <= 1 milliseconds
99.93% <= 2 milliseconds
100.00% <= 2 milliseconds
63979.53 requests per second




7, Fill a list with 10000 random elements  以随机指定的范围元素填充list
[root@langfang src]# ./redis-benchmark  -r 10000 -n 1000 lpush mylist _rand_init__
====== lpush mylist _rand_init__ ======
  1000 requests completed in 0.02 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


87.20% <= 1 milliseconds
99.50% <= 2 milliseconds
100.00% <= 2 milliseconds
47619.05 requests per second




[root@langfang src]# ./redis-benchmark  -r 10000 -n 1000 set mylist _rand_init__
====== set mylist _rand_init__ ======
  1000 requests completed in 0.02 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


86.40% <= 1 milliseconds
100.00% <= 1 milliseconds
47619.05 requests per second




8,静默方式压力测试
[root@langfang src]# ./redis-benchmark  -t set,get -n 100000 -r 1000
====== SET ======
  100000 requests completed in 1.58 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


94.99% <= 1 milliseconds
99.96% <= 2 milliseconds
100.00% <= 2 milliseconds
63211.12 requests per second


====== GET ======
  100000 requests completed in 1.60 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


95.21% <= 1 milliseconds
99.99% <= 2 milliseconds
100.00% <= 2 milliseconds
62617.41 requests per second


--可见静默方式只显示每次处理的请求数以及压力测试场景
[root@langfang src]# ./redis-benchmark  -t set,get -n 100000 -r 1000 -q
SET: 63091.48 requests per second
GET: 64724.92 requests per second




9,redis-cli可以直接附上操作命令
[root@langfang src]# ./redis-cli flushall
OK
[root@langfang src]# ./redis-cli dbsize
(integer) 0
[root@langfang src]# 




10,--r表示产生的随机键的数量,数量大可以模拟 键不命中情况
[root@langfang src]# ./redis-cli dbsize
(integer) 0
[root@langfang src]# ./redis-benchmark  -t set -r 8888 -n 100000
====== SET ======
  100000 requests completed in 1.61 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


94.16% <= 1 milliseconds
99.93% <= 2 milliseconds
99.95% <= 3 milliseconds
100.00% <= 3 milliseconds
62305.30 requests per second




[root@langfang src]# ./redis-cli dbsize
(integer) 8888
[root@langfang src]# 




11,默认情况是处理1个请求然后顺序接着处理下1个请求,但可以通过-P 管道技术,并发处理多个请求,下述效果非常明显,成9倍左右的差异
(同时处理多条命令需要PIPELINE管道技术)


[root@langfang src]# ./redis-benchmark -t get,set -n 100000 -q
SET: 64516.13 requests per second
GET: 64516.13 requests per second






[root@langfang src]# ./redis-benchmark -t get,set -n 100000 -P 16 -q
SET: 452488.69 requests per second
GET: 529100.56 requests per second

关于“nosql redis数据库压力测试基准工具redis-benchmark怎么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


网页标题:nosqlredis数据库压力测试基准工具redis-benchmark怎么用
文章来源:http://pwwzsj.com/article/ijscip.html