1.redis-benchmark

redis-benchmark可以为redis做基准性能测试,提供了很多选项帮助开发运维。
(1)-c 
-c(clients)选项代表客户端的并发数量(默认50)

(2)-n 
-n(num)选项代表客户端请求总量(默认100,000)
--100个客户端,总共执行20000个请求。
[root@oracle1 data]# redis-benchmark -h 192.168.1.7 -p 6379 -c 100 -n 20000
====== PING_INLINE ======
  20000 requests completed in 0.57 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
49.63% <= 2 milliseconds
98.78% <= 3 milliseconds
99.21% <= 4 milliseconds
99.79% <= 5 milliseconds
100.00% <= 5 milliseconds
34843.21 requests per second

====== PING_BULK ======
  20000 requests completed in 0.57 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
51.69% <= 2 milliseconds
98.40% <= 3 milliseconds
99.39% <= 4 milliseconds
99.89% <= 5 milliseconds
100.00% <= 5 milliseconds
35026.27 requests per second

====== SET ======
  20000 requests completed in 0.58 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
49.27% <= 2 milliseconds
97.72% <= 3 milliseconds
99.50% <= 4 milliseconds
99.88% <= 5 milliseconds
100.00% <= 5 milliseconds
34423.41 requests per second

====== GET ======
  20000 requests completed in 0.57 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
51.57% <= 2 milliseconds
98.76% <= 3 milliseconds
99.82% <= 4 milliseconds
100.00% <= 4 milliseconds
35211.27 requests per second

====== INCR ======
  20000 requests completed in 0.58 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
49.83% <= 2 milliseconds
97.85% <= 3 milliseconds
99.26% <= 4 milliseconds
99.89% <= 5 milliseconds
100.00% <= 5 milliseconds
34602.07 requests per second

====== LPUSH ======
  20000 requests completed in 0.59 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
49.62% <= 2 milliseconds
97.26% <= 3 milliseconds
98.09% <= 4 milliseconds
98.81% <= 5 milliseconds
99.34% <= 6 milliseconds
99.50% <= 11 milliseconds
99.58% <= 12 milliseconds
99.88% <= 13 milliseconds
100.00% <= 13 milliseconds
33898.30 requests per second

====== RPUSH ======
  20000 requests completed in 0.58 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
48.92% <= 2 milliseconds
97.01% <= 3 milliseconds
98.54% <= 4 milliseconds
99.66% <= 5 milliseconds
100.00% <= 5 milliseconds
34246.57 requests per second

====== LPOP ======
  20000 requests completed in 0.58 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
49.26% <= 2 milliseconds
98.32% <= 3 milliseconds
99.69% <= 4 milliseconds
99.94% <= 5 milliseconds
100.00% <= 5 milliseconds
34602.07 requests per second

====== RPOP ======
  20000 requests completed in 0.57 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
50.76% <= 2 milliseconds
98.92% <= 3 milliseconds
99.75% <= 4 milliseconds
100.00% <= 4 milliseconds
35026.27 requests per second

====== SADD ======
  20000 requests completed in 0.58 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
49.67% <= 2 milliseconds
98.08% <= 3 milliseconds
99.72% <= 4 milliseconds
100.00% <= 4 milliseconds
34602.07 requests per second

====== HSET ======
  20000 requests completed in 0.57 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
51.12% <= 2 milliseconds
98.88% <= 3 milliseconds
99.62% <= 4 milliseconds
99.89% <= 5 milliseconds
100.00% <= 5 milliseconds
35211.27 requests per second

====== SPOP ======
  20000 requests completed in 0.58 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
50.87% <= 2 milliseconds
98.22% <= 3 milliseconds
99.56% <= 4 milliseconds
100.00% <= 5 milliseconds
100.00% <= 5 milliseconds
34722.22 requests per second

====== LPUSH (needed to benchmark LRANGE) ======
  20000 requests completed in 0.58 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
48.15% <= 2 milliseconds
97.52% <= 3 milliseconds
99.39% <= 4 milliseconds
99.88% <= 5 milliseconds
100.00% <= 5 milliseconds
34305.32 requests per second

====== LRANGE_100 (first 100 elements) ======
  20000 requests completed in 0.58 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
47.92% <= 2 milliseconds
98.85% <= 3 milliseconds
99.53% <= 4 milliseconds
99.83% <= 5 milliseconds
100.00% <= 5 milliseconds
34246.57 requests per second

====== LRANGE_300 (first 300 elements) ======
  20000 requests completed in 0.58 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
47.85% <= 2 milliseconds
98.06% <= 3 milliseconds
99.56% <= 4 milliseconds
99.92% <= 5 milliseconds
100.00% <= 5 milliseconds
34188.04 requests per second

====== LRANGE_500 (first 450 elements) ======
  20000 requests completed in 0.61 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
45.88% <= 2 milliseconds
96.69% <= 3 milliseconds
98.61% <= 4 milliseconds
99.36% <= 5 milliseconds
99.50% <= 12 milliseconds
99.75% <= 13 milliseconds
100.00% <= 13 milliseconds
33057.85 requests per second

====== LRANGE_600 (first 600 elements) ======
  20000 requests completed in 0.59 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
47.00% <= 2 milliseconds
98.02% <= 3 milliseconds
99.57% <= 4 milliseconds
99.99% <= 5 milliseconds
100.00% <= 5 milliseconds
33783.79 requests per second

====== MSET (10 keys) ======
  20000 requests completed in 0.62 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
38.78% <= 2 milliseconds
95.46% <= 3 milliseconds
99.28% <= 4 milliseconds
99.82% <= 5 milliseconds
100.00% <= 5 milliseconds
32154.34 requests per second

大约每秒可以执行3.5W个命令。

(3)-q 
-q选项仅仅显示redis-benchmark的requests per second;

[root@oracle1 data]# redis-benchmark -h 192.168.1.7 -p 6379 -c 100 -n 20000 -q
PING_INLINE: 34904.01 requests per second
PING_BULK: 35149.38 requests per second
SET: 35335.69 requests per second
GET: 34305.32 requests per second
INCR: 34364.26 requests per second
LPUSH: 34246.57 requests per second
RPUSH: 34071.55 requests per second
LPOP: 34782.61 requests per second
RPOP: 33726.81 requests per second
SADD: 34364.26 requests per second
HSET: 34542.32 requests per second
SPOP: 33840.95 requests per second
LPUSH (needed to benchmark LRANGE): 34602.07 requests per second
LRANGE_100 (first 100 elements): 33898.30 requests per second
LRANGE_300 (first 300 elements): 34305.32 requests per second
LRANGE_500 (first 450 elements): 34602.07 requests per second
LRANGE_600 (first 600 elements): 34071.55 requests per second
MSET (10 keys): 32894.74 requests per second

(4)-r 
在一个空的redis上,执行redis-benchmark会发现只有三个键。
如果想插入更多的键,可以使用-r,插入更多随机的键。

[root@oracle1 data]# redis-benchmark -h 192.168.1.7 -p 6379 -c 100 -n 20000  -r 10000
====== PING_INLINE ======
  20000 requests completed in 0.57 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
51.01% <= 2 milliseconds
99.06% <= 3 milliseconds
99.64% <= 4 milliseconds
99.90% <= 5 milliseconds
100.00% <= 5 milliseconds
35273.37 requests per second

................................

-r 10000,代表只对后四位做随机处理。不代表个数。

(5)-P 
表示每个请求pipeline的数据量(默认为1)
[root@oracle1 data]# redis-benchmark -h 192.168.1.7 -p 6379 -c 100 -n 20000  -r 10000 -P 1000
====== PING_INLINE ======
  20000 requests completed in 0.07 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 44 milliseconds
10.01% <= 45 milliseconds
20.00% <= 56 milliseconds
44.06% <= 57 milliseconds
68.11% <= 58 milliseconds
92.15% <= 59 milliseconds
100.00% <= 59 milliseconds
289855.09 requests per second

====== PING_BULK ======
  20000 requests completed in 0.06 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 33 milliseconds
5.01% <= 44 milliseconds
21.84% <= 45 milliseconds
45.89% <= 46 milliseconds
67.54% <= 47 milliseconds
91.58% <= 48 milliseconds
100.00% <= 48 milliseconds
344827.59 requests per second

(6)-k 
该选项表示客户端是否使用keepalive,1为使用,0为不使用。默认值为1;
[root@oracle1 data]# redis-benchmark -h 192.168.1.7 -p 6379 -c 100 -n 20000  -r 10000 -P 1000 -k 1
====== PING_INLINE ======
  20000 requests completed in 0.07 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 57 milliseconds
4.82% <= 58 milliseconds
31.27% <= 59 milliseconds
55.32% <= 60 milliseconds
79.37% <= 61 milliseconds
100.00% <= 61 milliseconds
281690.12 requests per second

[root@oracle1 data]# redis-benchmark -h 192.168.1.7 -p 6379 -c 100 -n 20000  -r 10000 -P 1000 -k 0
WARNING: keepalive disabled, you probably need 'echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse' for Linux and 'sudo sysctl -w net.inet.tcp.msl=1000' for Mac OS X in order to use a lot of clients/requests
====== PING_INLINE ======
  20000 requests completed in 0.07 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 0

0.00% <= 44 milliseconds
10.01% <= 55 milliseconds
24.43% <= 56 milliseconds
46.08% <= 57 milliseconds
70.13% <= 58 milliseconds
94.18% <= 59 milliseconds
100.00% <= 59 milliseconds
294117.62 requests per second

(7)-t 对指定命令执行基准测试
[root@oracle1 data]# redis-benchmark -h 192.168.1.7 -p 6379 -c 100 -n 20000  -r 10000 -P 1000 -k 0 -t get,set
WARNING: keepalive disabled, you probably need 'echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse' for Linux and 'sudo sysctl -w net.inet.tcp.msl=1000' for Mac OS X in order to use a lot of clients/requests
====== SET ======
  20000 requests completed in 0.09 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 0

0.00% <= 24 milliseconds
7.28% <= 25 milliseconds
20.02% <= 26 milliseconds
30.94% <= 27 milliseconds
41.87% <= 28 milliseconds
54.60% <= 29 milliseconds
65.53% <= 30 milliseconds
76.44% <= 31 milliseconds
87.36% <= 32 milliseconds
100.00% <= 32 milliseconds
224719.09 requests per second

====== GET ======
  20000 requests completed in 0.08 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 0

0.00% <= 25 milliseconds
9.10% <= 26 milliseconds
22.75% <= 27 milliseconds
38.68% <= 28 milliseconds
52.33% <= 29 milliseconds
65.98% <= 30 milliseconds
81.90% <= 31 milliseconds
95.56% <= 32 milliseconds
100.00% <= 32 milliseconds
238095.23 requests per second

(8)--csv 
将结果输出到csv格式。
[root@oracle1 data]# redis-benchmark -h 192.168.1.7 -p 6379 -c 100 -n 20000  -r 10000 -P 1000 -k 1 -t get,set --csv
"SET","219780.22"
"GET","227272.73"

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐