一个集成redis-benchmark的redis压测的脚本
支持 单节点 主从 sentinel cluster (sentinel的还没写)
出于高可用的考虑,你还可以用高可用的ip做压力测试
需要调用redis-benchmark 用来测试不同版本redis7 同样写入速率和相同数据量下 redis占用内存大小
写了很多def,改天统一合并到一个类里面去
使用方式
python3 newtest.py -h xxxxxx -P 6379 -t 2 -a xxxxxx <可选> -H xxxx
#!/usr/bin/python3
import argparse
import subprocess
import sys
from datetime import datetime
import redis
standalone = 0
sentinel = 1
cluster = 2
v = 6
ips = ''
shard1_ip = ''
shard2_ip = ''
shard3_ip = ''
if v == 6:
flush = "92619_dont_run_flushall_rudely"
elif v == 7:
flush = "92618_dont_run_flushall_rudely"
# cmd = "/home/redis/redistest/src/redis-benchmark -h {} --cluster -p 6379 -q -a {} -p 6379 -t set " \
# "--threads 8 -P 100 -q -r 10000 -d 1024".format(
# ips, passwd)
def getredis_used_Mem(ip, passwd, port):
r = redis.StrictRedis(host=ip, password=passwd, port=port)
mem = r.info()['used_memory']
r.close()
return mem
def init_mem(ip, passwd, port):
r = redis.StrictRedis(host=ip, password=passwd, port=port)
r.execute_command(flush)
r.close()
def humansize(iput):
b = 1
B = b * 1024
MB = B * 1024
GB = MB * 1024
TB = GB * 1024
if iput > TB:
return str(iput / TB) + " TB"
elif iput > GB:
return str(iput / GB) + " GB"
elif iput > MB:
return str(iput