1、使用top命令
top
查看占用cpu高的进程
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
13827 apache 20 0 297m 11m 3688 S 98.4 0.0 0:00.88 php-fpm
2、使用strace跟踪
strace -p 13827
发现大量超时
poll([{fd=5, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
poll([{fd=5, events=POLLIN|POLLERR|POLLHUP}], 1, 60000) = 1 ([{fd=5, revents=POLLIN}])
recvfrom(5, "$-1\r\n", 8192, MSG_DONTWAIT, NULL, NULL) = 5
poll([{fd=5, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
poll([{fd=5, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
sendto(5, "*2\r\n$3\r\nGET\r\n$28\r\n___user_pos_up"..., 48, MSG_DONTWAIT, NULL, 0) = 48
poll([{fd=5, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
poll([{fd=5, events=POLLIN|POLLERR|POLLHUP}], 1, 60000) = 1 ([{fd=5, revents=POLLIN}])
recvfrom(5, "$-1\r\n", 8192, MSG_DONTWAIT, NULL, NULL) = 5
poll([{fd=5, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
poll([{fd=5, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
sendto(5, "*2\r\n$3\r\nGET\r\n$28\r\n___user_pos_up"..., 48, MSG_DONTWAIT, NULL, 0) = 48
poll([{fd=5, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
poll([{fd=5, events=POLLIN|POLLERR|POLLHUP}], 1, 60000) = 1 ([{fd=5, revents=POLLIN}])
recvfrom(5, "$-1\r\n", 8192, MSG_DONTWAIT, NULL, NULL) = 5
poll([{fd=5, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
poll([{fd=5, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
sendto(5, "*2\r\n$3\r\nGET\r\n$28\r\n___user_pos_up"..., 48, MSG_DONTWAIT, NULL, 0) = 48
poll([{fd=5, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
poll([{fd=5, events=POLLIN|POLLERR|POLLHUP}], 1, 60000) = 1 ([{fd=5, revents=POLLIN}])
recvfrom(5, "$-1\r\n", 8192, MSG_DONTWAIT, NULL, NULL) = 5
3、设置php-fpm.conf的超时时间,打开慢日志
[root@iZ25b738b71Z nginx] whereis php-fpm
php-fpm: /usr/sbin/php-fpm /etc/php-fpm.conf /etc/php-fpm.d /usr/share/man/man8/php-fpm.8.gz
[root@iZ25b738b71Z nginx] whereis php-fpm
php-fpm: /usr/sbin/php-fpm /etc/php-fpm.conf /etc/php-fpm.d /usr/share/man/man8/php-fpm.8.gz
[root@iZ25b738b71Z nginx] vi /etc/php-fpm.conf
注意看php-fpm.conf里有没有参数
request_slowlog_timeout
如果没有
[root@iZ25b738b71Z nginx] cd /etc/php-fpm.d/
[root@iZ25b738b71Z php-fpm.d] vi www.conf
修改参数
request_slowlog_timeout = 2
slowlog = /var/log/php-fpm/www-slow.log
4、接下来查看慢日志,看发生了什么
[root@iZ25b738b71Z php-fpm.d] vi /var/log/php-fpm/www-slow.log
可以排查出问题所在
网友评论