摘要:
测试redis的aof写入速度,
- 仅测试追加写, 关闭aof重写功能
- 配置每秒flush一次磁盘
向redis填充数据:
单点redis配置:
port 6379
daemonize no
pidfile redis.pid
protected-mode no
cluster-enabled no
cluster-config-file nodes.conf
cluster-node-timeout 5000
save ""
appendonly yes
appendfsync everysec
replica-read-only yes
cluster-migration-barrier 1
logfile "redis.log"
loglevel notice
slowlog-log-slower-than 10000
slowlog-max-len 128
cluster-node-timeout 3000
repl-diskless-sync no
unixsocket ./redis.sock
auto-aof-rewrite-percentage 0
填充数据环境准备:
使用python实现, 需要安装对应的模块
redis模块用于测试单点写入
redis-py-cluster模块用于测试cluster集群写入
python3 -m pip install redis
python3 -m pip install redis-py-cluster
填充数据脚本:
# -*- coding:utf-8 -*-
import redis
import time
import random
from concurrent.futures import ProcessPoolExecutor
from rediscluster import RedisCluster
# cluster
startup_nodes = [
{"host":"127.0.0.1", "port":7000},
{"host":"127.0.0.1", "port":7001},
{"host":"127.0.0.1", "port":7002},
{"host":"127.0.0.1", "port":7003}
]
# r = RedisCluster(startup_nodes=startup_nodes, decode_responses=True)
# sin
r = redis.Redis(host='127.0.0.1', port=6379, password='')
def try_pipeline():
start = time.time()
with r.pipeline(transaction=False) as p:
for i in range(1, 1000000):
for i in range (1, 100):
index1 = random.randint(0,1000000)
index2 = random.randint(0,1000000)
index3 = random.randint(0,1000000)
key = "key_" + str(index1) + "_" + str(index2)
value = "value_" + str(index3) + "_" + "9p3gbQjrUOjm5yFARiwrnqoBzswhfJZXcTOetMsSYyxjSluPoJeRR9T2vYKlZc6XxgenvtPHUPu6x1nI7ZdSISJEuDrrScOCG199p3gbQjrUOjm5yFARiwrnqoBzswhfJZXcTOetMsSYyxjSluPoJeRR9T2vYKlZc6XxgenvtPHUPu6x1nI7ZdSISJEuDrrScOCG19"
p.set(key, value)
p.execute()
print("ok")
try_pipeline()
数据收集:
使用iotop
#!/bin/bash
echo iotop -b -o -n 10 -d 5 -t > ./iotop.log
iotop -b -o -n 10 -d 5 -t > ./iotop.log
结果:
[root@bj-prev2-node-db-oc201 sin-redis]# cat iotop.log | grep "M/s"
14:16:32 Total DISK READ : 2.26 M/s | Total DISK WRITE : 73.37 K/s
14:16:32 Actual DISK READ: 4.93 M/s | Actual DISK WRITE: 696.65 K/s
b'14:16:32 1125978 be/4 54321 2.25 M/s 1615.79 B/s 0.00 % 0.20 % ora_m002_lhrcdb2'
14:16:42 Total DISK READ : 7.88 K/s | Total DISK WRITE : 507.34 M/s
14:16:42 Actual DISK READ: 7.88 K/s | Actual DISK WRITE: 471.07 M/s
b'14:16:42 3926476 be/4 root 0.00 B/s 507.25 M/s 0.00 % 0.00 % redis-server *:6379'
14:16:47 Total DISK READ : 0.00 B/s | Total DISK WRITE : 619.96 M/s
14:16:47 Actual DISK READ: 805.61 B/s | Actual DISK WRITE: 603.68 M/s
b'14:16:47 3926476 be/4 root 0.00 B/s 619.90 M/s 0.00 % 0.00 % redis-server *:6379'
14:16:52 Total DISK READ : 2.36 K/s | Total DISK WRITE : 480.28 M/s
14:16:52 Actual DISK READ: 2.36 K/s | Actual DISK WRITE: 479.70 M/s
b'14:16:52 3926476 be/4 root 0.00 B/s 480.18 M/s 0.00 % 0.00 % redis-server *:6379'
14:16:57 Total DISK READ : 0.00 B/s | Total DISK WRITE : 183.06 M/s
14:16:57 Actual DISK READ: 0.00 B/s | Actual DISK WRITE: 158.89 M/s
b'14:16:57 3926476 be/4 root 0.00 B/s 183.00 M/s 0.00 % 0.00 % redis-server *:6379'
14:17:02 Total DISK READ : 803.30 K/s | Total DISK WRITE : 635.41 M/s
14:17:02 Actual DISK READ: 969.31 K/s | Actual DISK WRITE: 674.41 M/s
b'14:17:02 3926476 be/4 root 0.00 B/s 635.33 M/s 0.00 % 0.00 % redis-server *:6379'
14:17:07 Total DISK READ : 860.64 K/s | Total DISK WRITE : 634.45 M/s
14:17:07 Actual DISK READ: 5.09 M/s | Actual DISK WRITE: 627.27 M/s
b'14:17:07 3926476 be/4 root 734.22 K/s 634.38 M/s 0.00 % 0.26 % redis-server *:6379'
14:17:13 Total DISK READ : 814.78 K/s | Total DISK WRITE : 152.41 M/s
14:17:13 Actual DISK READ: 849.35 K/s | Actual DISK WRITE: 195.60 M/s
b'14:17:13 3926476 be/4 root 0.00 B/s 152.36 M/s 0.00 % 0.00 % redis-server *:6379'
峰值:
14:17:02 Total DISK READ : 803.30 K/s | Total DISK WRITE : 635.41 M/s
14:17:02 Actual DISK READ: 969.31 K/s | Actual DISK WRITE: 674.41 M/s
b'14:17:02 3926476 be/4 root 0.00 B/s 635.33 M/s 0.00 % 0.00 % redis-server *:6379'