文章目录
redis性能压测
redis性能压测工具–redis-benchmark
如果要对 redis 进行性能压测,可以选择 redis 自带的压测工具 redis-benchmark。
进入到 /usr/local/software/redis-6.0.9/src 下,使用如下命令开始 redis 性能压测:
./redis-benchmark -h 10.0.0.4 -p 6379 -a redis-pass -c 5000 -n 50000 -d 50
使用 redis-benchmark -h 命令可以查看 redis-benchmark 相关参数,如下所示:
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
--user <username> Used to send ACL style 'AUTH username pass'. Needs -a.
-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 3)
--dbnum <db> SELECT the specified db number (default 0)
--threads <num> Enable multi-thread mode.
--cluster Enable cluster mode.
--enable-tracking Send CLIENT TRACKING on before starting benchmark.
-k <boolean> 1=keep alive 0=reconnect (default 1)
-r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD,
random members and scores for ZADD.
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
--precision Number of decimal places to display in latency output (default 0)
--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.
redis-benchmark 相关参数解释说明
redis-benchmark 压测结果
redis-benchmark 压测结果如下所示:
[root@mq1 src]# ./redis-benchmark -h 10.0.0.4 -p 6379 -a redis-pass -c 5000 -n 50000 -d 50
====== PING_INLINE ======
50000 requests completed in 0.74 seconds
5000 parallel clients
50 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": yes
multi-thread: no
0.00% <= 18 milliseconds
0.11% <= 19 milliseconds
0.30% <= 20 milliseconds
0.78% <= 21 milliseconds
1.13% <= 22 milliseconds
1.36% <= 23 milliseconds
1.71% <= 24 milliseconds
2.31% <= 25 milliseconds
3.44% <= 26 milliseconds
5.26% <= 27 milliseconds
7.53% <= 28 milliseconds
9.69% <= 29 milliseconds
11.74% <= 30 milliseconds
13.81% <= 31 milliseconds
15.82% <= 32 milliseconds
17.74% <= 33 milliseconds
20.13% <= 34 milliseconds
22.83% <= 35 milliseconds
25.27% <= 36 milliseconds
27.70% <= 37 milliseconds
30.22% <= 38 milliseconds
32.75% <= 39 milliseconds
35.68% <= 40 milliseconds
39.77% <= 41 milliseconds
45.01% <= 42 milliseconds
50.80% <= 43 milliseconds
55.11% <= 44 milliseconds
58.44% <= 45 milliseconds
61.85% <= 46 milliseconds
64.59% <= 47 milliseconds
67.36% <= 48 milliseconds
69.99% <= 49 milliseconds
72.79% <= 50 milliseconds
75.65% <= 51 milliseconds
78.24% <= 52 milliseconds
80.39% <= 53 milliseconds
82.34% <= 54 milliseconds
84.34% <= 55 milliseconds
86.57% <= 56 milliseconds
87.80% <= 57 milliseconds
88.93% <= 58 milliseconds
89.99% <= 59 milliseconds
90.70% <= 60 milliseconds
92.08% <= 61 milliseconds
92.78% <= 62 milliseconds
93.35% <= 63 milliseconds
93.93% <= 64 milliseconds
94.44% <= 65 milliseconds
94.70% <= 66 milliseconds
95.02% <= 67 milliseconds
95.29% <= 68 milliseconds
95.53% <= 69 milliseconds
95.73% <= 70 milliseconds
96.04% <= 71 milliseconds
96.34% <= 72 milliseconds
96.64% <= 73 milliseconds
97.06% <= 74 milliseconds
97.44% <= 75 milliseconds
97.78% <= 76 milliseconds
97.90% <= 77 milliseconds
98.17% <= 78 milliseconds
98.32% <= 79 milliseconds
98.49% <= 80 milliseconds
98.71% <= 81 milliseconds
98.78% <= 82 milliseconds
98.97% <= 83 milliseconds
99.12% <= 84 milliseconds
99.26% <= 85 milliseconds
99.41% <= 86 milliseconds
99.57% <= 87 milliseconds
99.72% <= 88 milliseconds
99.86% <= 89 milliseconds
100.00% <= 89 milliseconds
67659.00 requests per second
......
redis-benchmark 压测踩坑
踩坑一:Can’t create socket: Too many open files
问题描述:
linux 系统默认 open file 是 1024,程序打开的文件 /socket 连接数量超过系统设定值。可以通过 ulimit -a 命令查看,如下所示:
解决方案:
- 通过 ulimit -n 命令临时扩大 open file,如下所示:
ulimit -n 40960
- 修改 /etc/security/limits.conf 文件永久生效扩大 open file,在文件最后加上以下代码,如下所示:
* soft nofile 40960
* hard nofile 40960
踩坑二:Cannot assign requested address
问题描述:
这是由于 redis-benchmark 的压力测试时频繁的连服务器,数据量较大的时候,因为每次链接都在很短的时间内结束,致使不少的 TIME_WAIT,以致于用光了可用的端口号,因此新的链接没办法绑定端口,即 “Cannot assign requestedaddress”。
解决方案:
执行以下命令:
# 开启对于TCP时间戳的支持,若该项设置为0,则下面一项设置不起作用
sysctl -w net.ipv4.tcp_timestamps=1
# 表示开启TCP连接中TIME-WAIT sockets的快速回收
sysctl -w net.ipv4.tcp_tw_recycle=1
然而,执行上述命令后,再次使上述命令进行压测,仍然出现上述问题。因为上述命令设置的请求数和连接数比较大,所以尝试性的减小了其数值,执行之后成功开启 redis-benchmark 的压力测试,如下所示: