Web php服務器高進程數分析
現象:1臺WEB應用的PHP服務器間歇性高進程數,ZABBIX監控到的進程數趨勢如下:分析過程:1. 通過開啓php-fpm的slow log得到請求slow次數...
<iframe id="cproIframe_u944267" width="250" height="250" src="http://pos.baidu.com/acom?adn=3&at=231&aurl=&cad=1&ccd=24&cec=UTF-8&cfv=15&ch=0&col=zh-CN&conOP=0&cpa=1&dai=2&dis=0<r=http%3A%2F%2Fwww.5iops.com%2Fhtml%2Fproblem%2F<u=http%3A%2F%2Fwww.5iops.com%2Fhtml%2F2012%2Fproblem_0613%2F104.html&lunum=6&n=qudao123_cpr&pcs=1345x659&pis=10000x10000&ps=591x213&psr=1366x768&pss=1345x873&qn=4eb6a22eeb0b86ee&rad=&rsi0=250&rsi1=250&rsi5=2&rss0=%23FFFFFF&rss1=%23FFFFFF&rss2=%230000FF&rss3=%23444444&rss4=%23008000&rss5=&rss6=%23e10900&rss7=&scale=&skin=&td_id=944267&tn=text_default_250_250&tpr=1419349807002&ts=1&xuanting=0&dtm=BAIDU_DUP2_SETJSONADSLOT&dc=2&di=u944267" align="center,center" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true"></iframe>
分析過程:
1. 通過開啓php-fpm的slow log得到請求slow次數統計
[root@5iops-php php]# cat /home/logs/php/php-fpm-slow.log |grep 'pool www' | awk -F: '{ print $1":"$2 }' | sort | uniq –c
在21:55,22:08,22:15,23:23, 00:44 幾個時間點上符合High php process的趨勢。
2. Slow log顯示slow均發生在/home/5iops/php/includes/phprpc/phprpc_client.php:第399行
[13-Jun-2012 00:01:06] [pool www] pid 3803
script_filename = /home/5iops/web/clientweb/application/index.php
[0x000000001fd5f1c8] fgets() /home/5iops/php/includes/phprpc/phprpc_client.php:399
[0x000000001fd5eff0] _post() /home/5iops/php/includes/phprpc/phprpc_client.php:270
[0x000000001fd5ee58] invoke() /home/5iops/webroot/clientweb/v1.5.4/application/utils/orm/driver/phprpc/client.php:33
[0x00007fff19a04f20] __call() unknown:0
3. 查看源碼發現爲:PHPRPC Client 3.0調用
$request =
"POST $url HTTP/{$this->_http_version}\r\n" .
"Host: {$this->_server['host']}:{$this->_server['port']}\r\n" .
"User-Agent: PHPRPC Client 3.0 for PHP\r\n" .
$auth .
$connection .
$cookie .
$request_id .
"Accept: */*\r\n" .
"Accept-Encoding: gzip,deflate\r\n" .
"Content-Type: application/x-www-form-urlencoded; charset={$this->_charset}\r\n" .
"Content-Length: {$content_len}\r\n" .
"\r\n" .
$request_body;
fputs($this->_socket, $request, strlen($request));
while (!feof($this->_socket)) {
$header = array();
$line = fgets($this->_socket); -- 第399 行
if (empty($line)) continue;
if (preg_match('/HTTP\/(\d\.\d)\s+(\d+)([^(\r|\n)]*)(\r\n|$)/i', $line, $match)) {
$this->_http_version = $match[1];
$status = (int)$match[2];
$status_message = trim($match[3]);
if ($status != 100 && $status != 200) {
$this->_disconnect();
return new PHPRPC_Error($status, $status_message);
}
}
結論:
後端PHPRPC Client 3.0調用超時引起