根据Redis 两个版本的测试结果对比得出以下结论
一、Redis 2.6主从同步在网络闪断的情况下会自动开启新的端口进行重新链,同时会进行一下操作:
1、断开链接的从会向主发送SYNC命令
2、然后主fork进程导出rdb文件发送到从
3、从接收到完整的数据后,清空Redis内数据然后在从RDB中恢复
但是根据测试结果发现以下问题:
1、多个主从关系同时断开的时候,主导出RDB文件时,会占用大量内存
2、从接收到完整数据后,恢复数据的时候,会清空数据,这时候由于Redis数据量很大,目前10G左右内存恢复速度大约1分钟左右,这一分钟内,很多请求无法获取数据
3、在从RDB恢复数据的过程中,部分请求会被阻塞,导致请求超时(目前报警无法获取数据根次有关)
二、Redis 2.8.8 没有发现以上问题,因为Redis 2.8链接闪断重新连接后,从会从断开之前的主从同步进度开始继续同步,不会有全量恢复的问题
三、Redis 2.8 和 Redis 2.6 在进行save操作的时候,save过程中所有的请求都会被阻塞,导致前端请求失败,所以不要再查询的从上进行save操作
根据以上得出建议:
1、Redis 升级到 2.8 以上,保证数据主从同步时候的可用性
2、不要直接在Redis从或主上进行save操作,可以按王彬的建议在关键节点增加新的从用于save备份使用
3、建议优化Redis存储,单个端口存储数据不要过大,这样可以保证单个端口挂掉数据数据时候的速度,和影响面积
Redis 2.8和SSDB性能对比
SSDB 1.6.8.6
顺序写 : 1.645 ms/op 59.4 MB/s
随机写 : 1.679 ms/op 58.2 MB/s
顺序读 : 1.286 ms/op 75.9 MB/s
随机读 : 1.225 ms/op 79.7 MB/s
rpush : 1.546 ms/op 63.2 MB/s
lpop : 1.303 ms/op 74.9 MB/s
Redis 2.8.8
顺序写 : 1.617 ms/op 60.4 MB/s
随机写 : 1.214 ms/op 80.4 MB/s
顺序读 : 1.156 ms/op 84.5 MB/s
随机读 : 1.153 ms/op 84.7 MB/s
rpush : 1.222 ms/op 79.9 MB/s
lpop : 1.153 ms/op 84.7 MB/s
以下测试,是测试的某个业务接口,所以不代表Redis的性能,需要由以下多种情况的对比,来得到结论。
Redis 2.6 直接查询主时候的 压测信息
Concurrency Level: 50 Time taken for tests: 65.615809 seconds Complete requests: 200000 Failed requests: 0 Write errors: 0 Total transferred: 7234636173 bytes HTML transferred: 7171835859 bytes Requests per second: 3048.05 [#/sec] (mean) Time per request: 16.404 [ms] (mean) Time per request: 0.328 [ms] (mean, across all concurrent requests) Transfer rate: 107673.35 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.6 0 2 Processing: 5 15 1.7 15 59 Waiting: 4 11 1.4 11 57 Total: 5 15 1.8 16 59 Percentage of the requests served within a certain time (ms) 50% 16 66% 16 75% 17 80% 17 90% 18 95% 18 98% 20 99% 20 100% 59 (longest request)
Redis 2.6 直接查询主并且有从正在wait_bgsave时候的 压测信息
Concurrency Level: 50 Time taken for tests: 66.575526 seconds Complete requests: 200000 Failed requests: 0 Write errors: 0 Total transferred: 7234643440 bytes HTML transferred: 7171842812 bytes Requests per second: 3004.11 [#/sec] (mean) Time per request: 16.644 [ms] (mean) Time per request: 0.333 [ms] (mean, across all concurrent requests) Transfer rate: 106121.30 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.6 0 2 Processing: 10 15 4.6 15 252 Waiting: 7 11 4.5 11 247 Total: 10 16 4.5 16 252 Percentage of the requests served within a certain time (ms) 50% 16 66% 16 75% 17 80% 17 90% 18 95% 19 98% 20 99% 22 100% 252 (longest request)
Redis 2.6 查询从时候的 压测结果
Concurrency Level: 50 Time taken for tests: 68.835666 seconds Complete requests: 200000 Failed requests: 0 Write errors: 0 Total transferred: 7234623168 bytes HTML transferred: 7171822854 bytes Requests per second: 2905.47 [#/sec] (mean) Time per request: 17.209 [ms] (mean) Time per request: 0.344 [ms] (mean, across all concurrent requests) Transfer rate: 102636.64 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 42.4 0 3000 Processing: 3 15 21.4 15 3017 Waiting: 2 11 21.4 11 3011 Total: 3 16 47.5 16 3021 Percentage of the requests served within a certain time (ms) 50% 16 66% 16 75% 17 80% 17 90% 18 95% 19 98% 21 99% 22 100% 3021 (longest request)
Redis 2.6 查询从并且 由于网络闪断 正在与主进行 同步操作
Concurrency Level: 50 Time taken for tests: 125.321846 seconds Complete requests: 200000 Failed requests: 193893 (Connect: 0, Length: 193893, Exceptions: 0) Write errors: 0 Total transferred: 7014619430 bytes HTML transferred: 6952844946 bytes Requests per second: 1595.89 [#/sec] (mean) Time per request: 31.330 [ms] (mean) Time per request: 0.627 [ms] (mean, across all concurrent requests) Transfer rate: 54660.97 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.6 0 3 Processing: 10 30 231.8 15 14278 Waiting: 7 26 232.0 11 14277 Total: 10 30 231.8 16 14278 Percentage of the requests served within a certain time (ms) 50% 16 66% 16 75% 17 80% 17 90% 18 95% 19 98% 355 99% 430 100% 14278 (longest request)
Redis 2.8.8 查询从时候的 压测结果
Concurrency Level: 50 Time taken for tests: 68.335567 seconds Complete requests: 200000 Failed requests: 0 Write errors: 0 Total transferred: 7234728872 bytes HTML transferred: 7171927302 bytes Requests per second: 2926.73 [#/sec] (mean) Time per request: 17.084 [ms] (mean) Time per request: 0.342 [ms] (mean, across all concurrent requests) Transfer rate: 103389.27 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 46.0 0 3001 Processing: 3 15 24.5 15 2855 Waiting: 2 11 24.5 11 2852 Total: 3 16 52.1 16 3022 Percentage of the requests served within a certain time (ms) 50% 16 66% 16 75% 17 80% 17 90% 18 95% 18 98% 19 99% 20 100% 3022 (longest request)
Redis 2.8.8 查询从并且 由于网络闪断 正在与主进行 同步操作
Concurrency Level: 50 Time taken for tests: 67.968708 seconds Complete requests: 200000 Failed requests: 0 Write errors: 0 Total transferred: 7234653576 bytes HTML transferred: 7171852948 bytes Requests per second: 2942.53 [#/sec] (mean) Time per request: 16.992 [ms] (mean) Time per request: 0.340 [ms] (mean, across all concurrent requests) Transfer rate: 103946.23 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 46.0 0 3001 Processing: 3 15 1.9 15 30 Waiting: 2 11 1.5 11 23 Total: 3 16 46.0 16 3026 Percentage of the requests served within a certain time (ms) 50% 16 66% 16 75% 17 80% 17 90% 18 95% 18 98% 19 99% 20 100% 3026 (longest request)