一次web性能 优化 日志
最近一台服务器 总是load 高,查查问题在哪
/etc/nginx/php5.conf
增加
access_log /var/log/nginx/access_all_log log_all;
nginx.conf 增加
log_format log_all '[$time_local] $status $remote_addr $host $request - $remote_user ' '$status $body_bytes_sent "$http_referer" "$http_user_agent" "$gzip_ratio" $request_time';
将所有网站的日志汇总到一个文件 加上domain
查看比较慢的请求
tail -f /var/log/nginx/access_all_log | awk '{if($NF*10>20){print $0}}'
打开慢速查询日志,查看 哪些php脚本慢
/etc/php5/cgi/php-fpm.conf
<value name="request_terminate_timeout">30s</value>
The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
'0s' means 'off'
<value name="request_slowlog_timeout">2s</value>
The log file for slow requests
<value name="slowlog">/var/log/php-fpm-slow.log</value>
===================
我们参考日志
Nov 11 11:23:02.781886 pid 26473 (pool default)
script_filename = /home/www/xxxx/www/index.php
[0x00007fff26976230] fopen() /var/www/libs/jsonRPCClient.php:140
[0x00007fff26976310] __call() unknown:0
[0x00007fff269765b0] getXyzWords() unknown:0
[0x00007fff269768e0] call_user_func_array() /var/www/libs/intf/client/base.php:43
[0x00007fff269769c0] __call() unknown:0
[0x00007fff26978220] getXyzWords() /var/www/xxxx/www/protected/controllers/IndexController.php:215
[0x00007fff269786b0] actionIndexNew() /var/www/libs/yii/web/actions/CInlineAction.php:50
[0x00007fff26978ac0] runWithParams() /var/www/libs/yii/web/CController.php:300
[0x00007fff26978e60] runAction() /var/www/libs/yii/web/CController.php:278
[0x00007fff269793c0] runActionWithFilters() /var/www/libs/yii/web/CController.php:257
[0x00007fff26979980] run() /var/www/libs/yii/web/CWebApplication.php:277
[0x00007fff26979f80] runController() /var/www/libs/yii/web/CWebApplication.php:136
[0x00007fff2697a3f0] processRequest() /var/www/libs/yii/base/CApplication.php:158
[0x00007fff2697ac40] run() /var/www/xxxx/www/index.php:46
Nov 11 11:23:11.919255 pid 26501 (pool default)
script_filename = /home/www/xxxx/bbs/forumdisplay.php
[0x00007fff2694b6e0] mysql_query() /var/www/xxxx/bbs/include/db_mysql.class.php:66
[0x00007fff26958840] query() /var/www/xxxx/bbs/include/request.func.php:212
[0x00007fff26959fc0] updaterequest() /var/www/xxxx/bbs/include/request.func.php:32
[0x00007fff2695ad50] parse_request() /var/www/xxxx/bbs/include/request/rowcombine.inc.php:29
[0x00007fff26967ed0] +++ dump failed
观察一段时间 基本可以找到问题
ok
性能问题排重完毕