PHP failed to ptrace(PEEKDATA) pid 1918: Input/output error (5)或者 increase pm.start_servers解决
admin
2023-06-21 17:02:21
0

今天网站出现负载很大,cpu占用率超高,网站延迟很大,前台出现此错误信息:

[19-Sep-2016 23:30:38] WARNING: [pool www] child 31954, script '/var/www/html/casino.21pink.com/public/index.php' (request: "POST /index.php") executing too slow (2.407095 sec), logging
[19-Sep-2016 23:30:38] WARNING: [pool www] child 31943, script '/var/www/html/casino.21pink.com/public/index.php' (request: "POST /index.php") executing too slow (2.062648 sec), logging
[19-Sep-2016 23:30:38] WARNING: [pool www] child 31941, script '/var/www/html/casino.21pink.com/public/index.php' (request: "POST /index.php") executing too slow (2.666022 sec), logging
[19-Sep-2016 23:30:38] WARNING: [pool www] child 30382, script '/var/www/html/casino.21pink.com/public/index.php' (request: "POST /index.php") executing too slow (2.021010 sec), logging
[19-Sep-2016 23:30:38] WARNING: [pool www] child 29797, script '/var/www/html/casino.21pink.com/public/index.php' (request: "POST /index.php") executing too slow (2.554333 sec), logging
[19-Sep-2016 23:39:27] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 2 idle, and 68 total children
[19-Sep-2016 23:40:58] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 81 total children
[19-Sep-2016 23:40:59] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 3 idle, and 86 total children
[19-Sep-2016 23:41:00] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 2 idle, and 88 total children
[19-Sep-2016 23:41:01] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 91 total children

从信息看,应该是php进程较少:

经过查看发现进程确实很少,解决如下:

修改配置文件增加进程

vim /usr/local/php/etc/php-fpm.ini
pm = dynamic  #动态模式
pm.max_children = 512  #静态开启的进程数
pm.start_servers = 128 #动态模式的起始进程数
pm.min_spare_servers = 128 #动态模式最小进程数
pm.max_spare_servers = 512 #动态模式最大进程数

数值设置,参考自己的实际硬件配置,可以参考 内存/20M 来计算。

重新加载进程

/etc/init.d/php-fpm reload

等待了一点时间发现又报错:

[19-Sep-2016 23:30:20] WARNING: [pool www] child 7782, script '/var/www/html/casino.21pink.com/public/index.php' (request: "POST /index.php") executing too slow (2.224150 sec), logging
[19-Sep-2016 23:30:08] ERROR: failed to ptrace(PEEKDATA) pid 7663: Input/output error (5)
[19-Sep-2016 23:30:20] WARNING: [pool www] child 31952, script '/var/www/html/casino.21pink.com/public/index.php' (request: "POST /index.php") executing too slow (2.045803 sec), logging
[19-Sep-2016 23:30:20] ERROR: failed to ptrace(PEEKDATA) pid 31952: Input/output error (5)

查找资料如下:

It usrears you have request_slowlog_timeout enabled. This normally takes any request longer than N seconds, logs that it was taking a long time, then logs a stack trace of the script so you can see what it was doing that was taking so long.


In your case, the stack trace (to determine what the script is doing) is failing. If you're running out of processes, it is because either:


After php-fpm stops the process to trace it, the process fails to resume because of the error tracing it

The process is resuming but continues to run forever.

My first guess would be to disable request_slowlog_timeout. Since it's not working right, it may be doing more harm than good. If this doesn't fix the issue of running out of processes, then set the php.ini max_execution_time to something that will kill the script for sure.

大概说是设置了slowlog和php的最大执行时间。

解决:

禁止slowlog

vim php-fpm.conf
;request_slowlog_timeout = 10s
;slowlog = /usr/local/log/php-fpm/ckl-slow.log

修改最大执行时间:

vim php.ini
max_execution_time = 60

重启进程:

/etc/init.d/php-fpm reload

等待一段时间,发现一切正常。

查看TCP连接相关:

[root@GreenZonewebapp2 php-fpm.d]# ss -s
Total: 323 (kernel 675)
TCP:   4538 (estab 12, closed 4518, orphaned 0, synrecv 0, timewait 4518/0), ports 0
Transport Total     IP        IPv6
*      675       -         -        
RAW      0         0         0        
UDP      5         4         1        
TCP      20        19        1        
INET      25        23        2        
FRAG      0         0         0

同时发现系统TIMEWAIT 较多,所以优化了一些内核相关参数 

#vim /etc/sysctl.conf   进行内核的相关优化
# sysct -p
bash: sysct: command not found
[root@sapi etc]# sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.somaxconn = 262144
kernel.sysrq = 0
kernel.core_uses_pid = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
vm.swappiness = 0
fs.file-max = 409600

  过一阵再查看:

# ss -s
Total: 281 (kernel 362)
TCP:   520 (estab 22, closed 493, orphaned 0, synrecv 0, timewait 493/0), ports 475
 
Transport Total     IP        IPv6
*         362       -         -        
RAW       0         0         0        
UDP       1         1         0        
TCP       27        27        0        
INET      28        28        0        
FRAG      0         0         0


相关内容

热门资讯

面对中国,“发达国家犯的最大错... 【文/观察者网 阮佳琪】在2026年北京国际汽车展览会这一全球规模最大的车展举办期间(4月24日至5...
全新问界M9感知系统公布:搭载... PChome 5月27日消息,今日,在全新问界M9发布会中,华为常务董事、产品投资评审委员会主任、终...
看见2030!一起打开河南“十... 5月28日,“开局起步‘十五五’”河南专场新闻发布会在郑州举行。发布会以“奋...
杭州通报非法代孕窝点情况 5月28日,据“天天看临平”公众号,浙江省杭州市临平区今日联合调查处置组发布情况通报。针对群众反映临...
维他科技取得上悬窗用铰链专利,... 国家知识产权局信息显示,广东维他科技有限公司取得一项名为“一种上悬窗用铰链”的专利,授权公告号CN2...
韩国前总统尹锡悦涉嫌作伪证案一... 新华社首尔5月28日电(记者 黄昕欣)据韩联社消息,韩国前总统尹锡悦涉嫌在前国务总理韩德洙涉内乱案...
许君以昌 商通四海——解码城商... 地标“许昌之门”广场上的“许君以昌”石刻,尽显汉魏古都的开放与厚重。在许昌智能继电器股份有限公司装配...
华为成立半导体公司:从自研5G... 快科技5月26日消息,2026国际电路与系统研讨会上,华为公司董事、半导体业务部总裁何庭波在题为半导...
坚决打好“三夏”攻坚战 全力确... 河南日报讯(全媒体记者 李宗宽 王娟)5月27日,副省长李酌赴南阳调研“三夏”生产工作。李酌先后来到...
津巴布韦宣布将14种关键矿产强... 津巴布韦政府近日发布《矿产分类与宣言》,正式将锂、镍、钴、石墨等14种矿产列为受股权和出口管制的“关...