0%

redis压力测试

压力测试(Stress Test),也称为强度测试、负载测试,通过模拟实际应用的软硬件环境及用户使用过程的系统负荷,长时间或超大负荷地运行测试软件,来测试被测系统的性能、可靠性、稳定性等。

一、概念

      传统上所谓压力测试(stress testing)是指将整个金融机构或资产组合置于某一特定的(主观想象的)极端市场情况下,如假设利率骤升100个基本点,某一货币突然贬值30%,股价暴跌20%等异常的市场变化,然后测试该金融机构或资产组合在这些关键市场变量突变的压力下的表现状况,看是否能经受得起这种市场的突变。

      在软件测试中,压力测试(Stress Test),也称为强度测试、负载测试,通过模拟实际应用的软硬件环境及用户使用过程的系统负荷,长时间或超大负荷地运行测试软件,来测试被测系统的性能、可靠性、稳定性等。

redis做压测可以用自带的redis-benchmark工具,用法如下:

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
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.

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. 50个客户端,并发10000请求:redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 10000 -t get -a 123456
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
====== GET ======
10000 requests completed in 0.14 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

0.01% <= 0.2 milliseconds
4.93% <= 0.3 milliseconds
36.01% <= 0.4 milliseconds
61.16% <= 0.5 milliseconds
89.49% <= 0.6 milliseconds
94.82% <= 0.7 milliseconds
96.98% <= 0.8 milliseconds
97.92% <= 0.9 milliseconds
98.47% <= 1.0 milliseconds
99.04% <= 1.1 milliseconds
99.43% <= 1.2 milliseconds
99.69% <= 1.3 milliseconds
99.81% <= 1.4 milliseconds
99.91% <= 1.5 milliseconds
100.00% <= 1.5 milliseconds
72992.70 requests per second
  1. 50个客户端,并发10000请求,4线程处理(6.0.0):redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 10000 -t get -a 123456 --threads 4
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
====== GET ======
10000 requests completed in 0.12 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: yes
threads: 4

0.03% <= 0.1 milliseconds
0.80% <= 0.2 milliseconds
3.29% <= 0.3 milliseconds
10.22% <= 0.4 milliseconds
36.53% <= 0.5 milliseconds
82.34% <= 0.6 milliseconds
90.32% <= 0.7 milliseconds
94.44% <= 0.8 milliseconds
96.65% <= 0.9 milliseconds
98.01% <= 1.0 milliseconds
98.92% <= 1.1 milliseconds
99.32% <= 1.2 milliseconds
99.56% <= 1.3 milliseconds
99.75% <= 1.4 milliseconds
99.92% <= 1.5 milliseconds
99.97% <= 1.6 milliseconds
100.00% <= 1.7 milliseconds
85470.09 requests per second
  1. 只统计最终结果redis-benchmark -h 127.0.0.1 -p 6379 -a 123456 -q
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
PING_INLINE: 69930.07 requests per second
PING_BULK: 56689.34 requests per second
SET: 60422.96 requests per second
GET: 60753.34 requests per second
INCR: 61087.36 requests per second
LPUSH: 53619.30 requests per second
RPUSH: 58754.41 requests per second
LPOP: 53590.57 requests per second
RPOP: 56625.14 requests per second
SADD: 56274.62 requests per second
HSET: 56497.18 requests per second
SPOP: 56882.82 requests per second
ZADD: 52994.17 requests per second
ZPOPMIN: 56882.82 requests per second
LPUSH (needed to benchmark LRANGE): 54975.26 requests per second
LRANGE_100 (first 100 elements): 13368.98 requests per second
LRANGE_300 (first 300 elements): 5611.36 requests per second
LRANGE_500 (first 450 elements): 3538.19 requests per second
LRANGE_600 (first 600 elements): 2504.45 requests per second
MSET (10 keys): 30293.85 requests per second

三、参考

  1. 参考一