redis做压测可以用自带的redis-benchmark工具,使用简单,效果也比较不错。
linux下一般无需下载,windows下redis-benchmark压力测试工具下载地址:http://www.daixiaorui.com/source/18.html(解压后的redis-benchmark.exe)
压测命令:redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 10000
-c表示连接数
-n表示请求数
更多参数请输入 --help 查看~
压测需要一段时间,因为它需要依次压测多个命令的结果,如:get、set、incr、lpush等等,所以我们需要耐心等待,如果只需要压测某个命令,如:get,那么可以在以上的命令后加一个参数-t(红色部分):
redis-benchmark -h 127.0.0.1 -p 6086 -c 50 -n 10000 -t get
压测结果:
[root@1234 ~]# redis-benchmark -h 127.0.0.1 -p 6086 -c 50 -n 10000 -t get
====== GET ======
10000 requests completed in 0.15 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.16% <= 1 milliseconds
100.00% <= 1 milliseconds
68027.21 requests per second
不带-t的压测结果如下:
[root@1234 ~]# redis-benchmark -h 127.0.0.1 -p 6086 -c 50 -n 10000
====== PING_INLINE ======
10000 requests completed in 0.15 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.35% <= 1 milliseconds
100.00% <= 1 milliseconds
67114.09 requests per second
====== PING_BULK ======
10000 requests completed in 0.15 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.38% <= 1 milliseconds
100.00% <= 1 milliseconds
66666.66 requests per second
====== SET ====== (处理set的性能)
10000 requests completed in 0.17 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.11% <= 1 milliseconds
99.51% <= 25 milliseconds
100.00% <= 25 milliseconds
57142.86 requests per second
====== GET ====== (处理get请求的性能)
10000 requests completed in 0.15 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.09% <= 1 milliseconds
99.51% <= 11 milliseconds
100.00% <= 12 milliseconds
66666.66 requests per second
====== INCR ======
10000 requests completed in 0.15 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.33% <= 1 milliseconds
100.00% <= 1 milliseconds
66666.66 requests per second
====== LPUSH ======
10000 requests completed in 0.16 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.20% <= 1 milliseconds
100.00% <= 1 milliseconds
64516.13 requests per second
====== LPOP ======
10000 requests completed in 0.16 seconds
50 parallel clients
3 bytes payload
keep alive: 1
98.56% <= 1 milliseconds
99.51% <= 14 milliseconds
100.00% <= 14 milliseconds
61349.69 requests per second
====== SADD ======
10000 requests completed in 0.15 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.36% <= 1 milliseconds
100.00% <= 1 milliseconds
67114.09 requests per second
====== SPOP ======
10000 requests completed in 0.14 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.32% <= 1 milliseconds
100.00% <= 1 milliseconds
69930.07 requests per second
====== LPUSH (needed to benchmark LRANGE) ======
10000 requests completed in 0.15 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.47% <= 1 milliseconds
100.00% <= 1 milliseconds
67567.57 requests per second
====== LRANGE_100 (first 100 elements) ======
10000 requests completed in 0.14 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.41% <= 1 milliseconds
100.00% <= 1 milliseconds
72992.70 requests per second
====== LRANGE_300 (first 300 elements) ======
10000 requests completed in 0.14 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.41% <= 1 milliseconds
100.00% <= 1 milliseconds
72463.77 requests per second
====== LRANGE_500 (first 450 elements) ======
10000 requests completed in 0.14 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.35% <= 1 milliseconds
100.00% <= 1 milliseconds
68965.52 requests per second
====== LRANGE_600 (first 600 elements) ======
10000 requests completed in 0.15 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.37% <= 1 milliseconds
100.00% <= 1 milliseconds
66225.17 requests per second
====== MSET (10 keys) ======
10000 requests completed in 0.17 seconds
50 parallel clients
3 bytes payload
keep alive: 1
94.94% <= 1 milliseconds
100.00% <= 1 milliseconds
58479.53 requests per second
这样看起来很冗余,如果我们只想看最终的结果,可以带上参数-q,完整的命令如下:
redis-benchmark -h 127.0.0.1 -p 6086 -c 50 -n 10000 -q
显示结果为:
[root@1234 ~]# redis-benchmark -h 127.0.0.1 -p 6086 -c 50 -n 10000 -q
PING_INLINE: 66225.17 requests per second
PING_BULK: 65789.48 requests per second
SET: 66666.66 requests per second
GET: 69444.45 requests per second
INCR: 62893.08 requests per second
LPUSH: 65789.48 requests per second
LPOP: 68027.21 requests per second
SADD: 64935.07 requests per second
SPOP: 67114.09 requests per second
LPUSH (needed to benchmark LRANGE): 62893.08 requests per second
LRANGE_100 (first 100 elements): 69444.45 requests per second
LRANGE_300 (first 300 elements): 68965.52 requests per second
LRANGE_500 (first 450 elements): 68965.52 requests per second
LRANGE_600 (first 600 elements): 68965.52 requests per second
MSET (10 keys): 59171.60 requests per second
温馨提示:
压测结果跟机器的性能有关,其中windows下压测的结果要比在linux下差一大截。