测算Redis处理实际生产请求的QPS/TPS
Benchmark工具
redis发布版本中自带了redis-benchmark性能测试工具;
示例:
使用50个并发连接,发出100000个请求,每个请求的数据为2kb,
测试host为127.0.0.1 端口为6379的redis服务器性能:
./redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 100000 -d 2
...
====== SADD ======
100000 requests completed in 2.27 seconds
500 parallel clients
3 bytes payload
keep alive: 1
4.66% <= 1 milliseconds
14.15% <= 2 milliseconds
23.87% <= 3 milliseconds
33.59% <= 4 milliseconds
43.13% <= 5 milliseconds
52.69% <= 6 milliseconds
62.08% <= 7 milliseconds
71.43% <= 8 milliseconds
80.66% <= 9 milliseconds
89.10% <= 10 milliseconds
95.23% <= 11 milliseconds
98.76% <= 12 milliseconds
99.59% <= 13 milliseconds
99.78% <= 14 milliseconds
99.87% <= 15 milliseconds
99.95% <= 16 milliseconds
99.99% <= 17 milliseconds
100.00% <= 17 milliseconds
44150.11 requests per second
我们关注结果最后一行:每秒44150.11个请求,既QPS4.4万;
但这里的数据都只是测试数据,测出来的QPS不能代表实际生产的处理能力;
测算redis处理实际生产请求的QPS/TPS
在实际生产中,我们需要关心这个指标,在我们的应用场景中,
redis能够处理的最大的(QPS/TPS)是多少?
测量redis QPS的方式有两种:
-
估计生产的报文大小,使用benchmark工具指定-d数据块大小来模拟;
-
使用redis-cli中info统计信息计算差值;
redis-cli的info命令中有一项total_commands_processed表示:从启动到现在处理的所有命令总数,可以通过统计两次info指令间的差值来计算QPS:
//返回redis-cli info中total_commands_processed的结果
long getCmdProcessNum(redisContext *c)
{
string strVal;
getInfo(c,strVal);
map mpVal;
parserInfo(strVal,mpVal);
map::iterator iter = mpVal.find("total_commands_processed");
if(iter != mpVal.end())
{
return atol(iter->second.c_str());
}
cout << "[err] not found total_commands_processed" << endl;
return 0;
}
程序实现很简单,就不全贴在这里了,完整代码详见github:
https://github.com/me115/cppset/tree/master/redisTPS
在实际生产中,运行这个程序来统计实际的QPS。
运行示例:
/opt/app/redisTPS#./redisTPS
Time: 1 Process:40962 TPS:40839.48
Time: 1 Process:43741 TPS:43610.17
Time: 1 Process:38935 TPS:38779.88
Time: 1 Process:31724 TPS:31597.61
Time: 1 Process:32169 TPS:32008.96
Time: 1 Process:31634 TPS:31476.62
Time: 1 Process:46007 TPS:45823.71
Time: 1 Process:50460 TPS:50258.96
Time: 1 Process:47309 TPS:47167.50
Time: 1 Process:50511 TPS:50359.92
...
Posted by: 大CC | 14MAR,2015
博客:blog.me115.com [订阅]
微博:新浪微博