通常来讲,缓存的命中率越高则表示使用缓存的收益越高,应用的性能越好(响应时间越短、吞吐量越高),抗并发的能力越强。
一、常用工具
- redis-stat,几年前的老项目
- redmon,几年前的老项目
- redis-faina,几年前的老项目
- redis-broswer,几年前的老项目
- RedisLive,几年前的老项目,由python编写的并且开源的图形化监控工具,核心服务部分只包含一个web服务和一个基于redis自带的info及monitor命令的监控服务。
- zabbix
- promethuse
1 | # Server |
二、使用
redis-stat
安装
- 通过Ruby安装
- 通过Jar方式安装
使用
- 通过web页面
redis-stat --server --daemon --auth=your_password
- http://localhost:63790
- 通过终端命令行
redis-stat --auth=your_password
,无法启动运行,看报错信息意思是有的方法已经废弃了,只能通过web端查看
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15/Library/Ruby/Gems/2.6.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:1070: warning: constant ::Fixnum is deprecated
/Library/Ruby/Gems/2.6.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:1070: warning: constant ::Fixnum is deprecated
/Library/Ruby/Gems/2.6.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:1070: warning: constant ::Fixnum is deprecated
/Library/Ruby/Gems/2.6.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:1070: warning: constant ::Fixnum is deprecated
/Library/Ruby/Gems/2.6.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:1070: warning: constant ::Fixnum is deprecated
/Library/Ruby/Gems/2.6.0/gems/si-0.1.4/lib/si/patch.rb:5: warning: constant ::Fixnum is deprecated
/Library/Ruby/Gems/2.6.0/gems/si-0.1.4/lib/si/patch.rb:9: warning: constant ::Bignum is deprecated
/Library/Ruby/Gems/2.6.0/gems/option_initializer-1.5.1/lib/option_initializer.rb:154: warning: constant ::Fixnum is deprecated
/Library/Ruby/Gems/2.6.0/gems/option_initializer-1.5.1/lib/option_initializer.rb:198: warning: constant ::Fixnum is deprecated
/Library/Ruby/Gems/2.6.0/gems/redis-3.0.7/lib/redis/client.rb:386: warning: constant ::Fixnum is deprecated
/Library/Ruby/Gems/2.6.0/gems/si-0.1.4/lib/si/module.rb:4: warning: constant ::Fixnum is deprecated
/Library/Ruby/Gems/2.6.0/gems/si-0.1.4/lib/si/module.rb:21: warning: constant ::Fixnum is deprecated
/Library/Ruby/Gems/2.6.0/gems/si-0.1.4/lib/si/module.rb:10: warning: constant ::Fixnum is deprecated
undefined method `display_width' for #<String:0x00007fe7c5225678>
Did you mean? display- 通过web页面
redmon
- 安装
sudo gem install redmon
- 启动
redmon
- 查看
http://0.0.0.0:4567/
- 安装
RedisLive(较早的工具,后期已不见维护,调试时因为版本问题各种出错,暂时放弃)
安装RedisLive,clone或直接下载zip压缩包
安装依赖
- tornado
pip install tornado
- redis.py
pip install redis
- python-dateutil
pip install python-dateutil
- 指定目录
pip install tornado --target /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
- 指定版本
pip install -v tornado==2.1.1
- 指定目录
- tornado
cd RedisLive(zip解压后不叫此名字)
cp redis-live.conf.example redis-live.conf
编辑redis-live.conf
- RedisServers是要监控的实例
- RedisStatsServer则是监控信息临时写入的实例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28{
"RedisServers":
[
{
"server": "154.17.59.99",
"port" : 6379
},
{
"server": "localhost",
"port" : 6380,
"password" : "some-password"
}
],
"DataStoreType" : "redis",
"RedisStatsServer":
{
"server" : "ec2-184-72-166-144.compute-1.amazonaws.com",
"port" : 6385
},
"SqliteStatsStore" :
{
"path": "to your sql lite file"
}
}启动
./redis-monitor.py --duration=120
- 报错,一般是由版本兼容导致的修改内容如下
redisprovider.py
,改完后重试正常或直接修改文件开头#! /usr/bin/env python3.8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#30行
# self.conn.zadd(server + ":memory", str(timeutils.convert_to_epoch(timestamp)), data)
self.conn.zadd(server + ":memory", data)
#60行
command_count_key = server + ":CommandCount:" + epoch
# pipeline.zincrby(command_count_key, command, 1)
pipeline.zincrby(command_count_key, 1, command)
command_count_key = server + ":DailyCommandCount:" + current_date
# pipeline.zincrby(command_count_key, command, 1)
pipeline.zincrby(command_count_key, 1, command)
key_count_key = server + ":KeyCount:" + epoch
# pipeline.zincrby(key_count_key, keyname, 1)
pipeline.zincrby(key_count_key, 1, keyname)
key_count_key = server + ":DailyKeyCount:" + current_date
# pipeline.zincrby(key_count_key, keyname, 1)
pipeline.zincrby(key_count_key, 1, keyname)- 扩展
1
2
3
4
5
6
7python与redis旧版本数据库的交互:
zadd: db.zadd(REDIS_KEY, score, member)
zincrby: db.zincrby(REDIS_KEY, member, increment)
python与redis新版本数据库交互:
zadd:db.zadd(REDIS_KEY, {member:score})
zincrby:db.zincrby(REDIS_KEY, increment, menber)- 报错,一般是由版本兼容导致的修改内容如下
启动
./redis-live.py
- 报错
- 直接修改文件开头
#! /usr/bin/env python3.8
- 直接修改文件开头
1
2
3
4
5
6
7Traceback (most recent call last):
File "./redis-live.py", line 3, in <module>
import tornado.ioloop
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tornado/ioloop.py", line 67
def fileno(self) -> int:
^
SyntaxError: invalid syntax- 报错
- 加入以下代码
1
2
3import sys
sys.path.append("api/controller")
sys.path.append("dataprovider")
- 加入以下代码
1
2
3
4
5
6Traceback (most recent call last):
File "./redis-live.py", line 15, in <module>
from api.controller.ServerListController import ServerListController
File "/usr/local/RedisLive/src/api/controller/ServerListController.py", line 1, in <module>
from BaseController import BaseController
ModuleNotFoundError: No module named 'BaseController'报错
TabError: inconsistent use of tabs and spaces in indentation
- 修改
api/util/timeutils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15def convert_to_epoch(timestamp):
if (type(timestamp) is datetime.date):
timestamp = datetime.datetime.fromordinal(timestamp.toordinal())
timestamp = timestamp.replace(tzinfo=None)
diff = (timestamp - datetime.datetime(1970, 1, 1))
seconds = int(total_seconds(diff))
return seconds
def convert_to_epoch1(timestamp):
if (type(timestamp) is datetime.date):
timestamp = datetime.datetime.fromordinal(timestamp.toordinal())
timestamp = timestamp.replace(tzinfo=None)
diff = (timestamp - datetime.datetime(1970, 1, 1))
seconds = int(total_seconds(diff))
return seconds- 修改
报错
TypeError: '>' not supported between instances of 'NoneType' and 'int'
- 报错
zabbix
安装MySQ,建议5.7版本
-
- 下载源码包
wget https://cdn.zabbix.com/zabbix/sources/stable/4.0/zabbix-4.0.32.tar.gz
- 解压
tar -zxvf zabbix-4.0.32.tar.gz
cd zabbix-4.0.32
- 下载源码包
promethuse
三、参考
一、概念
传统上所谓压力测试(stress testing)是指将整个金融机构或资产组合置于某一特定的(主观想象的)极端市场情况下,如假设利率骤升100个基本点,某一货币突然贬值30%
,股价暴跌20%
等异常的市场变化,然后测试该金融机构或资产组合在这些关键市场变量突变的压力下的表现状况,看是否能经受得起这种市场的突变。
在软件测试中,压力测试(Stress Test),也称为强度测试、负载测试,通过模拟实际应用的软硬件环境及用户使用过程的系统负荷,长时间或超大负荷地运行测试软件,来测试被测系统的性能、可靠性、稳定性等。
redis做压测可以用自带的redis-benchmark工具,用法如下:
1 | Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests>] [-k <boolean>] |
二、使用
- 50个客户端,并发10000请求:
redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 10000 -t get -a 123456
1 | ====== GET ====== |
- 50个客户端,并发10000请求,4线程处理(6.0.0):
redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 10000 -t get -a 123456 --threads 4
1 | ====== GET ====== |
- 只统计最终结果
redis-benchmark -h 127.0.0.1 -p 6379 -a 123456 -q
1 | PING_INLINE: 69930.07 requests per second |