Redis 性能测试 (基准测试)
# Redis 性能到底有多高
结论:在我的这台服务器上(Redis 6.2.5),单机的 QPS 大约在 8.3w+
这里找到了 阿里云和腾讯云的 Redis 产品的性能数据可以参考
- 阿里云 Redis :https://help.aliyun.com/document_detail/26350.html (opens new window)
- 腾讯云 Redis : https://cloud.tencent.com/document/product/239/17952 (opens new window)
- UCloud Redis : https://docs.ucloud.cn/database/uredis/test (opens new window) 只提供测试方法,不提供性能规格
# 如何测试自己的 Redis 性能
其实,Redis 自身就带了测试的工具 redis-benchmark
只需要直接执行 指令即可
如果你是基于 Docker 安装的 Redis,是需要进入到容器内部在使用 redis-benchmark 。
进入容器指令为:
docker exec -it docker_redis /bin/bash
其中 docker_redis 是容器名字
[root@bulk redis]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
586aa4254074 redis:6.2.5 "docker-entrypoint.s…" 2 weeks ago Up 57 minutes 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp docker_redis
[root@bulk redis]# docker exec -it docker_redis /bin/bash
1
2
3
4
2
3
4
# redis-benchmark 语法说明
redis-benchmark [-h ] [-p ] [-c ] [-n ] [-k ]
option | 说明 |
---|---|
-h | 服务主机地址, 默认 127.0.0.1 |
-p | 服务端口, 默认 6379 |
-s | 指定连接的 Redis 服务地址,用于覆盖 -h 和 -p 参数 |
-a | Redis 认证密码 |
–user | Used to send ACL style ‘AUTH username pass’. Needs-a. |
-c | 并发连接数, 默认: 50 |
-n | 总的 请求数 |
-d | SET/GET值的数据大小(字节)(默认值3) |
–dbnum | 选择指定的数据库号(默认为0) |
–threads | 启用多线程模式。 |
–cluster | 启用群集模式。 |
–enable-tracking | 在开始基准测试之前发送客户端跟踪。 |
-k | 是否保持连接。默认会持续保持连接。1=keep alive 0=reconnect (default 1) |
-r | 对SET/GET/INCR使用随机键,对 SADD 使用随机值,ZADD 的随机成员和分数。使用此选项,基准将展开字符串 rand_int 在指定范围内具有 12 位数字的参数中从 0 到 keyspacelen-1。每次执行命令时替换都会更改已执行。默认测试使用它来命中指定范围。 |
-P | 默认情况下,Redis 客户端一次请求只发起一个命令。通过 -P 参数,可以设置使用 pipelining 功能,一次发起指定个请求,从而提升 QPS。 |
-e | 如果服务器回复有错误,请在标准输出上显示它们。(每秒显示的错误不超过1个) |
-q | 精简输出结果。即只展示每个命令的 QPS 测试结果 |
–precision | 延迟输出中显示的小数位数(默认为0) |
–csv | 以CSV格式输出 |
-l | 循环。永远运行测试 |
-t | 只运行逗号分隔的测试列表。测试名称与作为输出生成的名称相同。 |
-I | 空闲模式。只需打开N个空闲连接并等待。 |
–version | 输出版本并退出 |
# 快速测试
测试指令为
[root@bulk redis]# redis-benchmark
1
注意
如果执行出现了 ERROR: NOAUTH Authentication required.
的异常,有可能是因为你的 Redis 是有密码的,
这时你要是用指定密码 ==> redis-benchmark -a your-password
redis-benchmark 指令,会测试很多的执行,输出也很长,整个过程也是比较慢
输出的结果如下(这里只截取了一部分,显然观察起来很费劲)
[root@bulk redis]# docker exec -it docker_redis /bin/bash
root@586aa4254074:/data# redis-benchmark -a your-password
====== SET ======
100000 requests completed in 1.16 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
Latency by percentile distribution:
0.000% <= 0.103 milliseconds (cumulative count 1)
50.000% <= 0.295 milliseconds (cumulative count 55206)
75.000% <= 0.311 milliseconds (cumulative count 79989)
87.500% <= 0.327 milliseconds (cumulative count 90495)
93.750% <= 0.343 milliseconds (cumulative count 94738)
96.875% <= 0.367 milliseconds (cumulative count 96891)
98.438% <= 0.407 milliseconds (cumulative count 98611)
99.219% <= 0.455 milliseconds (cumulative count 99239)
99.609% <= 0.583 milliseconds (cumulative count 99622)
99.805% <= 0.791 milliseconds (cumulative count 99805)
99.902% <= 0.935 milliseconds (cumulative count 99903)
99.951% <= 1.687 milliseconds (cumulative count 99952)
99.976% <= 2.007 milliseconds (cumulative count 99983)
99.988% <= 2.015 milliseconds (cumulative count 99991)
99.994% <= 2.023 milliseconds (cumulative count 99994)
99.997% <= 2.031 milliseconds (cumulative count 99999)
99.999% <= 2.039 milliseconds (cumulative count 100000)
100.000% <= 2.039 milliseconds (cumulative count 100000)
Cumulative distribution of latencies:
0.001% <= 0.103 milliseconds (cumulative count 1)
0.024% <= 0.207 milliseconds (cumulative count 24)
70.050% <= 0.303 milliseconds (cumulative count 70050)
98.611% <= 0.407 milliseconds (cumulative count 98611)
99.458% <= 0.503 milliseconds (cumulative count 99458)
99.686% <= 0.607 milliseconds (cumulative count 99686)
99.757% <= 0.703 milliseconds (cumulative count 99757)
99.814% <= 0.807 milliseconds (cumulative count 99814)
99.877% <= 0.903 milliseconds (cumulative count 99877)
99.924% <= 1.007 milliseconds (cumulative count 99924)
99.926% <= 1.103 milliseconds (cumulative count 99926)
99.935% <= 1.503 milliseconds (cumulative count 99935)
99.944% <= 1.607 milliseconds (cumulative count 99944)
99.953% <= 1.703 milliseconds (cumulative count 99953)
99.959% <= 1.807 milliseconds (cumulative count 99959)
99.967% <= 1.903 milliseconds (cumulative count 99967)
99.983% <= 2.007 milliseconds (cumulative count 99983)
100.000% <= 2.103 milliseconds (cumulative count 100000)
Summary:
throughput summary: 85984.52 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.302 0.096 0.295 0.351 0.431 2.039
====== GET ======
100000 requests completed in 1.17 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
Latency by percentile distribution:
0.000% <= 0.087 milliseconds (cumulative count 1)
50.000% <= 0.295 milliseconds (cumulative count 52172)
75.000% <= 0.311 milliseconds (cumulative count 77804)
87.500% <= 0.327 milliseconds (cumulative count 89703)
93.750% <= 0.343 milliseconds (cumulative count 94422)
96.875% <= 0.375 milliseconds (cumulative count 97232)
98.438% <= 0.407 milliseconds (cumulative count 98458)
99.219% <= 0.455 milliseconds (cumulative count 99258)
99.609% <= 0.519 milliseconds (cumulative count 99622)
99.805% <= 0.855 milliseconds (cumulative count 99806)
99.902% <= 0.911 milliseconds (cumulative count 99909)
99.951% <= 3.655 milliseconds (cumulative count 99952)
99.976% <= 4.031 milliseconds (cumulative count 99976)
99.988% <= 4.247 milliseconds (cumulative count 99988)
99.994% <= 4.359 milliseconds (cumulative count 99994)
99.997% <= 4.423 milliseconds (cumulative count 99997)
99.998% <= 4.471 milliseconds (cumulative count 99999)
99.999% <= 4.495 milliseconds (cumulative count 100000)
100.000% <= 4.495 milliseconds (cumulative count 100000)
Cumulative distribution of latencies:
0.003% <= 0.103 milliseconds (cumulative count 3)
0.025% <= 0.207 milliseconds (cumulative count 25)
66.796% <= 0.303 milliseconds (cumulative count 66796)
98.458% <= 0.407 milliseconds (cumulative count 98458)
99.557% <= 0.503 milliseconds (cumulative count 99557)
99.742% <= 0.607 milliseconds (cumulative count 99742)
99.787% <= 0.703 milliseconds (cumulative count 99787)
99.800% <= 0.807 milliseconds (cumulative count 99800)
99.902% <= 0.903 milliseconds (cumulative count 99902)
99.923% <= 1.007 milliseconds (cumulative count 99923)
99.950% <= 3.103 milliseconds (cumulative count 99950)
99.980% <= 4.103 milliseconds (cumulative count 99980)
100.000% <= 5.103 milliseconds (cumulative count 100000)
Summary:
throughput summary: 85397.09 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.304 0.080 0.295 0.351 0.431 4.495
====== INCR ======
100000 requests completed in 1.17 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
Latency by percentile distribution:
0.000% <= 0.127 milliseconds (cumulative count 1)
50.000% <= 0.303 milliseconds (cumulative count 62725)
75.000% <= 0.319 milliseconds (cumulative count 81197)
87.500% <= 0.335 milliseconds (cumulative count 90143)
93.750% <= 0.359 milliseconds (cumulative count 94527)
96.875% <= 0.399 milliseconds (cumulative count 97071)
98.438% <= 0.447 milliseconds (cumulative count 98617)
99.219% <= 0.503 milliseconds (cumulative count 99221)
99.609% <= 0.615 milliseconds (cumulative count 99632)
99.805% <= 0.847 milliseconds (cumulative count 99824)
99.902% <= 0.959 milliseconds (cumulative count 99903)
99.951% <= 1.159 milliseconds (cumulative count 99953)
99.976% <= 1.423 milliseconds (cumulative count 99981)
99.988% <= 1.431 milliseconds (cumulative count 99988)
99.994% <= 1.447 milliseconds (cumulative count 99998)
99.998% <= 1.463 milliseconds (cumulative count 99999)
99.999% <= 1.495 milliseconds (cumulative count 100000)
100.000% <= 1.495 milliseconds (cumulative count 100000)
Cumulative distribution of latencies:
0.000% <= 0.103 milliseconds (cumulative count 0)
0.048% <= 0.207 milliseconds (cumulative count 48)
62.725% <= 0.303 milliseconds (cumulative count 62725)
97.354% <= 0.407 milliseconds (cumulative count 97354)
99.221% <= 0.503 milliseconds (cumulative count 99221)
99.602% <= 0.607 milliseconds (cumulative count 99602)
99.707% <= 0.703 milliseconds (cumulative count 99707)
99.747% <= 0.807 milliseconds (cumulative count 99747)
99.887% <= 0.903 milliseconds (cumulative count 99887)
99.912% <= 1.007 milliseconds (cumulative count 99912)
99.942% <= 1.103 milliseconds (cumulative count 99942)
99.958% <= 1.207 milliseconds (cumulative count 99958)
99.962% <= 1.303 milliseconds (cumulative count 99962)
99.969% <= 1.407 milliseconds (cumulative count 99969)
100.000% <= 1.503 milliseconds (cumulative count 100000)
Summary:
throughput summary: 85251.49 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.306 0.120 0.303 0.367 0.479 1.495
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# 精简测试
redis-benchmark -t set,get,incr -n 1000000 -q
1
- 通过
-t
参数,设置仅仅测试 SET/GET/INCR 命令 - 通过
-n
参数,设置每个测试执行 1000000 次操作。 - 通过
-q
参数,设置精简输出结果。
执行结果如下:
root@586aa4254074:/data# redis-benchmark -a your-password -t set,get,incr -n 1000000 -q
SET: 84918.48 requests per second, p50=0.303 msec
GET: 83416.75 requests per second, p50=0.303 msec
INCR: 83913.73 requests per second, p50=0.303 msec
1
2
3
4
2
3
4
从结果可以看出,在我的这台服务器上,单机的一个 QPS 大约在 8.3w 左右
# pipeline 测试
在一些业务场景,我们希望通过 Redis pipeline 功能,批量提交命令给 Redis Server ,从而提升性能。测试指令如下
redis-benchmark -t set,get,incr -n 1000000 -q -P 10
1
- 通过
-P
参数,设置每个 pipeline 执行 10 次 Redis 命令。 执行结果如下:
root@586aa4254074:/data# redis-benchmark -a your-password -t set,get,incr -n 1000000 -q -P 10
SET: 625782.19 requests per second, p50=0.687 msec
GET: 799360.50 requests per second, p50=0.423 msec
INCR: 697836.75 requests per second, p50=0.607 msec
1
2
3
4
2
3
4
从结果对比可以看出,通过 pipeline 的性能有了 8-10 倍左右的提升
上次更新: 2023/01/16, 18:12:53