测算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: 14.66% <= 1 milliseconds14.15% <= 2 milliseconds23.87% <= 3 milliseconds33.59% <= 4 milliseconds43.13% <= 5 milliseconds52.69% <= 6 milliseconds62.08% <= 7 milliseconds71.43% <= 8 milliseconds80.66% <= 9 milliseconds89.10% <= 10 milliseconds95.23% <= 11 milliseconds98.76% <= 12 milliseconds99.59% <= 13 milliseconds99.78% <= 14 milliseconds99.87% <= 15 milliseconds99.95% <= 16 milliseconds99.99% <= 17 milliseconds100.00% <= 17 milliseconds44150.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<string,string> mpVal; parserInfo(strVal,mpVal); map<string,string>::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.48Time: 1 Process:43741 TPS:43610.17Time: 1 Process:38935 TPS:38779.88Time: 1 Process:31724 TPS:31597.61Time: 1 Process:32169 TPS:32008.96Time: 1 Process:31634 TPS:31476.62Time: 1 Process:46007 TPS:45823.71Time: 1 Process:50460 TPS:50258.96Time: 1 Process:47309 TPS:47167.50Time: 1 Process:50511 TPS:50359.92...
Posted by: 大CC | 14MAR,2015
博客:blog.me115.com [订阅]
微博:新浪微博