还是sina平台压力测试那档子事,已经拖了一周了,还没好,很烦心,静下来心总结下
硬件环境
- cpu:Intel(R) Xeon(R) CPU E5506 @ 2.13GHz 8 核
- memory :8GB
- Disk : Sata 硬盘 65GB
应用软件及其各自接口
- Apache 2.2.17
- DB: Mysqlnd 5.0.7
- NoSql:Tokyocabinet 1.4.47,Tokyotyrant 1.1.41
- PHP:PHP 5.3.5
- PHP扩展:Tokyo_tyrant 0.6.0,xhprof-0.9.2,eaccelerator-0.9.6.1
- 压力测试:loadRunner(sina),webbench-1.5.tar.gz( 本地 )
- 系统检测:dstat-0.7.2
过程
sina工程师使用loadRunner以30并发测试我们提供的测试接口,同时在本地系统上运行监控程序,查看运行情况
1.dstat-0.7.2
#tar -jxvf dstat-0.7.2.tar.bz2 #cd dstat-0.7.2 #./dstat -tclmsgdn --nocolor
可以每秒刷新如下系统数据,(因为太长,只列出涉及到的条目)
- total-cpu-usage:usr sys idl wai hiq siq
- memory-usage:used buff cach free
- swap:used free
- dsk/total:read writ
2.系统命令
#iostat -x
结果如下
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda 0.09 9.53 0.29 2.14 11.07 93.45 43.10 0.19 78.01 3.16 0.77
3.系统命令
#iostat -d -m 1 10
结果如下
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda 2.43 0.01 0.05 1469 12406
sda1 0.00 0.00 0.00 0 0
sda2 0.00 0.00 0.00 0 0
sda3 2.42 0.01 0.05 1467 12406
---
sina得出的结论是:1.cpu,内存没有饱和,硬盘写数据量偏大,写等待拖延了时间,每秒处理的请求数偏低
只能再做优化
- 安装xhprof,查看php运行效率,分析功能代码模块耗时,发现文件解析模块耗时严重,将文件解析部分改由管理员后台初始化完成,数据存放于nosql中
- 安装eaccelerator,提升php速度,还是有明显的加速
- 代码优化,例如,尽量将in_array方法有isset代替等
- mysql配置修改,my.cnf中max_connections调整至1000
- apache配置修改,调整max_connect
xhprof(相关的路径要注意填写正确):
if(function_exists('xhprof_enable')) {
xhprof_enable();
}
// 测试代码
...
...
...
if(function_exists('xhprof_disable')) {
$xhprof_data = xhprof_disable();
include_once "xhprof_lib/utils/xhprof_lib.php";
include_once "xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
$identifier = 'index-page';
$run_id = $xhprof_runs->save_run($xhprof_data, $identifier);
echo "<a target=\"_blank\" href=\"../xhprof_html/index.php?run=$run_id&source=$identifier\">view xhprof </a>";
}
mysql(my.cnf):
[mysqld] // 新加一行 max_connections=1000
apache(httpd.conf):
<IfModule prefork.c> StartServers 10 MinSpareServers 20 MaxSpareServers 50 ServerLimit 2000 MaxClients 2000 MaxRequestsPerChild 4000 </IfModule>
---
我们自己测试结果跟sina差距了10倍甚至更多,暂时还没有明确找到原因,不排除网络原因
sina工程师提供的建议:可以做下磁盘阵列加快写的速度,否则涉及写的话,瓶颈马上显现了,仅供参考,你们再讨论下