redis做压测可以用自带的redis-benchmark工具,使用简单
(venv_py36) [root@auditsql ~]# which redis-benchmark
/usr/bin/redis-benchmark
压测命令:redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 10000
压测需要一段时间,因为它需要依次压测多个命令的结果,如:get、set、incr、lpush等等,所以我们需要耐心等待,如果只需要压测某个命令,如:get,那么可以在以上的命令后加一个参数-t(红色部分):
1、redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 10000 -t get
(venv_py36) [root@auditsql ~]# redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 10000 -t get
====== GET ======
10000 requests completed in 0.12 seconds
50 parallel clients
3 bytes payload
keep alive: 1
96.17% <= 1 milliseconds
97.35% <= 2 milliseconds
98.97% <= 3 milliseconds
99.01% <= 6 milliseconds
99.17% <= 7 milliseconds
99.58% <= 8 milliseconds
99.70% <= 9 milliseconds
100.00% <= 9 milliseconds
80645.16 requests per second
2、redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 10000 -t set
(venv_py36) [root@auditsql ~]# redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 10000 -t set
====== SET ======
10000 requests completed in 0.12 seconds
50 parallel clients
3 bytes payload
keep alive: 1
96.55% <= 1 milliseconds
98.01% <= 2 milliseconds
98.04% <= 3 milliseconds
98.99% <= 4 milliseconds
99.63% <= 5 milliseconds
99.92% <= 6 milliseconds
100.00% <= 6 milliseconds
81967.21 requests per second
这样看起来数据很多,如果我们只想看最终的结果,可以带上参数-q,完整的命令如下:
3、redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 10000 -q
(venv_py36) [root@auditsql ~]# redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 10000 -q
PING_INLINE: 90090.09 requests per second
PING_BULK: 108695.65 requests per second
SET: 99009.90 requests per second
GET: 107526.88 requests per second
INCR: 105263.16 requests per second
LPUSH: 103092.78 requests per second
RPUSH: 104166.66 requests per second
LPOP: 99009.90 requests per second
RPOP: 100000.00 requests per second
SADD: 104166.66 requests per second
HSET: 95238.10 requests per second
SPOP: 104166.66 requests per second
LPUSH (needed to benchmark LRANGE): 99009.90 requests per second
LRANGE_100 (first 100 elements): 35211.27 requests per second
LRANGE_300 (first 300 elements): 13071.90 requests per second
LRANGE_500 (first 450 elements): 8952.55 requests per second
LRANGE_600 (first 600 elements): 6734.01 requests per second
MSET (10 keys): 69444.45 requests per second