数据库
首页 > 数据库> > redis压测

redis压测

作者:互联网

【1】TCP压测

【1.1】tcp局域网压测

当前实例,配置文件中已经开启了 4 个线程

(1)单线程

CPU使用:300%-340%

redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 50 -n 1000000 --threads 1 -t get,set,lpush

(2)4线程

redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 50 -n 1000000 --threads 4 -t get,set,lpush

CPU使用:290%-330%

结果如下:

[root@bf-ltredis-4 ~]# redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 50 -n 1000000 --threads 4 -t get,set,lpush

SET: 26722.25 requests per second, p50=1.759 msec

GET: 27276.20 requests per second, p50=1.719 msec

LPUSH: 26908.49 requests per second, p50=1.751 msec

 

[root@bf-ltredis-4 ~]# redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 50 -n 1000000 --threads 1 -t get,set,lpush

SET: 26541.39 requests per second, p50=1.711 msec

GET: 28498.96 requests per second, p50=1.599 msec

LPUSH: 26726.53 requests per second, p50=1.719 msec

-------------------------------------------------------------------------------------------------------

当前实例,配置文件中已经开启了 1 个线程

(1)单线程

CPU使用:50%

redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 50 -n 1000000 --threads 1 -t get,set,lpush

(2)4线程

redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 50 -n 1000000 --threads 4 -t get,set,lpush

CPU使用:50%

结果和上面一样

 

【1.2】本地测试

当前实例,配置文件中已经开启了 1 个线程

(1)单线程

CPU使用:100

redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 50 -n 1000000 --threads 1 -t get,set,lpush

(2)4线程

redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 50 -n 1000000 --threads 4 -t get,set,lpush

CPU使用:100%

结果如下:

[root@bf-ltredis-3 6387_redis]# redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 50 -n 1000000 --threads 1 -t get,set,lpush

SET: 68226.79 requests per second, p50=0.447 msec

GET: 72521.58 requests per second, p50=0.343 msec

LPUSH: 72806.70 requests per second, p50=0.447 msec

 

[root@bf-ltredis-3 6387_redis]# redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 50 -n 1000000 --threads 4 -t get,set,lpush

SET: 67535.62 requests per second, p50=0.711 msec

GET: 76663.60 requests per second, p50=0.615 msec

LPUSH: 60375.54 requests per second, p50=0.767 msec

 

-------------------------------------------------------------------------------------------------------

当前实例,配置文件中已经开启了 4 个线程

(1)单线程

CPU使用:写时400%,读时 130%

redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 50 -n 1000000 --threads 1 -t get,set,lpush

(2)4线程

redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 50 -n 1000000 --threads 4 -t get,set,lpush

CPU使用:写时400%,读时 130%

结果如下:

[root@bf-ltredis-3 6387_redis]# redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 50 -n 1000000 --threads 1 -t get,set,lpush

SET: 68166.33 requests per second, p50=0.407 msec

GET: 72243.90 requests per second, p50=0.335 msec

LPUSH: 61996.29 requests per second, p50=0.471 msec

 

[root@bf-ltredis-3 6387_redis]# redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 50 -n 1000000 --threads 4 -t get,set,lpush

SET: 117082.30 requests per second, p50=0.343 msec

GET: 132502.98 requests per second, p50=0.303 msec

LPUSH: 97162.84 requests per second, p50=0.423 msec

 

【1.3】结论

(1)redis 1个线程时

本地压测:无论客户端是几个线程连接过来,处理效率一样

(2)redis 4个线程时

本地压测:当客户端只有一个线程访问时,效率与redis 1个线程时相同;当客户端使用多个线程连接时,4线程的redis 效率是单线程的 1.5-2倍左右

 

【2】集群压测

【2.1】压测单线程

当前实例,配置文件中已经开启了 4 个线程

(1)redis-benchmark -h 192.168.191.176 -p 6381 -a 123456 --cluster -d 3 -q -c 50 -n 1000000 --threads 1 -t get,set,lpush

CPU使用:写时250-320%,读时 150%左右

[root@bf-ltredis-4 /]# redis-benchmark -h 192.168.191.176 -p 6381 -a 123456 --cluster -d 3 -q -c 50 -n 1000000 --threads 1 -t get,set,lpush

WARNING: master node 192.168.191.176:6382 has no slots, skipping...

Cluster has 3 master nodes:

 

Master 0: 367152fbf6401b4316a4ae913cb4fb3d57bc7782 192.168.191.70:6385

Master 1: 11ac5cf5004f22a55ee0afa2b221d120ad768f7d 192.168.191.211:6384

Master 2: f5dc23c602b57f6b09b4909d01289ff4d80220ed 192.168.191.70:6386

 

SET: 35473.57 requests per second, p50=1.199 msec

GET: 38270.19 requests per second, p50=1.071 msec

LPUSH: 37145.72 requests per second, p50=1.167 msec

 

【1】单实例,配置文件线程4

【1.1】压测

  

 

 


redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 10 -n 10000000 --threads 1 -t get,set,lpush -P 10
SET: 209244.42 requests per second, p50=0.423 msec
GET: 250037.52 requests per second, p50=0.343 msec
LPUSH: 192871.47 requests per second, p50=0.463 msec

[root@bf-ltredis-2 ~]# redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 20 -n 10000000 --threads 1 -t get,set,lpush -P 10
SET: 212282.69 requests per second, p50=0.839 msec
GET: 247261.58 requests per second, p50=0.695 msec
LPUSH: 200304.47 requests per second, p50=0.903 msec

[root@bf-ltredis-2 ~]# redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 30 -n 10000000 --threads 1 -t get,set,lpush -P 10
SET: 223333.92 requests per second, p50=1.207 msec
GET: 256482.61 requests per second, p50=1.023 msec
LPUSH: 215810.25 requests per second, p50=1.263 msec

[root@bf-ltredis-2 ~]# redis-benchmark -h 192.168.191.82 -p 6387 -a 123456 -d 3 -q -c 50 -n 10000000 --threads 1 -t get,set,lpush -P 10
SET: 240830.39 requests per second, p50=1.871 msec
GET: 270584.72 requests per second, p50=1.623 msec
LPUSH: 230260.88 requests per second, p50=1.951 msec

【1.2】单线程压测 结论

  

 

 

如上图我们可以发现,在pipline =10,客户端连接为20个时,就几乎达到了性能最大值;
且 GET 时 耗费 CPU更少

【2】集群,全线程4

【2.1】集群架构

实例与监控对应关系
+ 192.168.191.176:6381 =》 192.168.191.176:9121
+ 192.168.191.176:6382 =》 192.168.191.176:9122
+ 192.168.191.211:6383 =》 192.168.191.211:9121
+ 192.168.191.211:6384 =》 192.168.191.211:9122
+ 192.168.191.70:6385 =》 192.168.191.70:9121
+ 192.168.191.70:6386 =》 192.168.191.70:9122
其中 6384/6385/6386 是主库,主从关系如下:
6384=》6381 , 6385=》6382 , 6386=》6383
  

 

 

【2.2】集群4线程压测

[root@bf-ltredis-3 ~]# redis-benchmark --cluster -h 192.168.191.176 -p 6381 -a 123456 -d 3 -q -c 30 -n 10000000 --threads 1 -t get,set,lpush -P 10
Cluster has 3 master nodes:

Master 0: 367152fbf6401b4316a4ae913cb4fb3d57bc7782 192.168.191.70:6385
Master 1: 11ac5cf5004f22a55ee0afa2b221d120ad768f7d 192.168.191.211:6384
Master 2: f5dc23c602b57f6b09b4909d01289ff4d80220ed 192.168.191.70:6386

SET: 251717.97 requests per second, p50=0.887 msec
GET: 299868.06 requests per second, p50=0.767 msec
LPUSH: 263852.22 requests per second, p50=0.911 msec

[root@bf-ltredis-3 ~]# redis-benchmark --cluster -h 192.168.191.176 -p 6381 -a 123456 -d 3 -q -c 60 -n 10000000 --threads 1 -t get,set,lpush -P 10
Cluster has 3 master nodes:

Master 0: 367152fbf6401b4316a4ae913cb4fb3d57bc7782 192.168.191.70:6385
Master 1: 11ac5cf5004f22a55ee0afa2b221d120ad768f7d 192.168.191.211:6384
Master 2: f5dc23c602b57f6b09b4909d01289ff4d80220ed 192.168.191.70:6386

SET: 283857.06 requests per second, p50=1.599 msec
GET: 301677.34 requests per second, p50=1.487 msec
LPUSH: 279259.41 requests per second, p50=1.631 msec

[root@bf-ltredis-3 ~]# redis-benchmark --cluster -h 192.168.191.176 -p 6381 -a 123456 -d 3 -q -c 120 -n 10000000 --threads 1 -t get,set,lpush -P 10
Cluster has 3 master nodes:

Master 0: 367152fbf6401b4316a4ae913cb4fb3d57bc7782 192.168.191.70:6385
Master 1: 11ac5cf5004f22a55ee0afa2b221d120ad768f7d 192.168.191.211:6384
Master 2: f5dc23c602b57f6b09b4909d01289ff4d80220ed 192.168.191.70:6386

SET: 294915.66 requests per second, p50=3.007 msec
GET: 320266.44 requests per second, p50=2.743 msec
LPUSH: 298552.03 requests per second, p50=3.079 msec

[root@bf-ltredis-3 ~]# redis-benchmark --cluster -h 192.168.191.176 -p 6381 -a 123456 -d 3 -q -c 180 -n 10000000 --threads 1 -t get,set,lpush -P 10
Cluster has 3 master nodes:

Master 0: 367152fbf6401b4316a4ae913cb4fb3d57bc7782 192.168.191.70:6385
Master 1: 11ac5cf5004f22a55ee0afa2b221d120ad768f7d 192.168.191.211:6384
Master 2: f5dc23c602b57f6b09b4909d01289ff4d80220ed 192.168.191.70:6386

SET: 310896.94 requests per second, p50=4.359 msec
GET: 320667.00 requests per second, p50=4.079 msec
LPUSH: 299760.19 requests per second, p50=4.663 msec

[root@bf-ltredis-3 ~]# redis-benchmark --cluster -h 192.168.191.176 -p 6381 -a 123456 -d 3 -q -c 300 -n 10000000 --threads 1 -t get,set,lpush -P 10
Cluster has 3 master nodes:

Master 0: 367152fbf6401b4316a4ae913cb4fb3d57bc7782 192.168.191.70:6385
Master 1: 11ac5cf5004f22a55ee0afa2b221d120ad768f7d 192.168.191.211:6384
Master 2: f5dc23c602b57f6b09b4909d01289ff4d80220ed 192.168.191.70:6386

SET: 318369.94 requests per second, p50=7.079 msec
GET: 358204.69 requests per second, p50=5.767 msec
LPUSH: 319335.78 requests per second, p50=7.199 msec

[root@bf-ltredis-3 ~]# redis-benchmark --cluster -h 192.168.191.176 -p 6381 -a 123456 -d 3 -q -c 150 -n 10000000 --threads 4 -t get,set,lpush -P 10
Cluster has 3 master nodes:

Master 0: 367152fbf6401b4316a4ae913cb4fb3d57bc7782 192.168.191.70:6385
Master 1: 11ac5cf5004f22a55ee0afa2b221d120ad768f7d 192.168.191.211:6384
Master 2: f5dc23c602b57f6b09b4909d01289ff4d80220ed 192.168.191.70:6386

SET: 351840.12 requests per second, p50=3.527 msec
GET: 418550.12 requests per second, p50=2.991 msec
LPUSH: 334235.75 requests per second, p50=3.815 msec

【2.3】集群压测 结论

实例与监控对应关系
+ 192.168.191.176:6381 =》 192.168.191.176:9121
+ 192.168.191.176:6382 =》 192.168.191.176:9122
+ 192.168.191.211:6383 =》 192.168.191.211:9121
+ 192.168.191.211:6384 =》 192.168.191.211:9122
+ 192.168.191.70:6385 =》 192.168.191.70:9121
+ 192.168.191.70:6386 =》 192.168.191.70:9122
其中 6384/6385/6386 是主库,主从关系如下:
6384=》6381 , 6385=》6382 , 6386=》6383

  

 

 

从上面的图可以看出,集群是可以平均分部连接信息到各个主节点的;
在1000W压测中,客户端连接并发超过 120,基本在SET相关操作时,CPU就上 300%了,GET 耗费的 CPU 资源少很多;
我们可以看到 get/set 请求基本平均分散在所有主节点上;

【3】代理压测

实例与监控对应关系
+ 192.168.191.176:6381 =》 192.168.191.176:9121
+ 192.168.191.176:6382 =》 192.168.191.176:9122
+ 192.168.191.211:6383 =》 192.168.191.211:9121
+ 192.168.191.211:6384 =》 192.168.191.211:9122
+ 192.168.191.70:6385 =》 192.168.191.70:9121
+ 192.168.191.70:6386 =》 192.168.191.70:9122
其中 6384/6385/6386 是主库,主从关系如下:
6384=》6381 , 6385=》6382 , 6386=》6383

【3.1】压测

[root@bf-ltredis-2 ~]# redis-benchmark -h 192.168.191.82 -p 7617 -d 3 -q -c 300 -n 10000000 --threads 4 -t get,set,lpush -P 10
ERROR: failed to fetch CONFIG from 192.168.191.82:7617
WARN: could not fetch server CONFIG
SET: 253479.00 requests per second, p50=11.239 msec
GET: 296920.94 requests per second, p50=9.207 msec
LPUSH: 247114.94 requests per second, p50=11.487 msec

[root@bf-ltredis-2 ~]# redis-benchmark -h 192.168.191.82 -p 7617 -d 3 -q -c 300 -n 10000000 --threads 8 -t get,set,lpush -P 100
ERROR: failed to fetch CONFIG from 192.168.191.82:7617
WARN: could not fetch server CONFIG
SET: 313018.44 requests per second, p50=91.903 msec
GET: 863334.19 requests per second, p50=32.335 msec
LPUSH: 259848.23 requests per second, p50=111.487 msec

【3.2】代理压测 结论

  

CPU始终无法突破 100%,用上多线程;
压测时,我压测了 get/set/lpop,那么在get的时候,只会对一个主实例操作,set时也是;



 

标签:压测,msec,redis,per,second,192.168,requests,p50
来源: https://www.cnblogs.com/gered/p/15959466.html