简体   繁体   English

Apache / PHP进程在与MySQL交互时挂起

[英]Apache/PHP processes hanging while interacting with MySQL

We're seeing some strange behaviour and we're not sure if it's a problem with apache, php, mysql or the OS, so over to the big brains of stackoverflow! 我们看到一些奇怪的行为,我们不确定它是否是apache,php,mysql或操作系统的问题,所以对于stackoverflow的大脑!

We have Apache and mod_php talking to a mysql5 server. 我们有Apache和mod_php与mysql5服务器通信。 Sometimes, a process will choose to hang, trying to read from a file descriptor. 有时,进程会选择挂起,尝试从文件描述符中读取。

Firing up strace one on of them (all hanging processes showed the same results) gave this : 在它们上面填一个strace(所有悬挂过程显示相同的结果)给出了:

[root@prweb133v ~]# strace -p 8450
Process 8450 attached - interrupt to quit
read(57,  <unfinished ...>

So what was it trying to read? 那它试图读什么呢?

[root@prweb133v ~]# lsof -p 8450
...
...
httpd   8450 apache   57u  IPv4    5546599             TCP
prweb133v.local:36615->hadat.local:mysql (ESTABLISHED)

That's our mysql server! 那是我们的mysql服务器! Ok, so maybe it was trying to read the results of a query, I thought. 好的,所以也许它试图读取查询的结果,我想。 Checking the processlist on the mysql server, the connection was established but in a state of SLEEP. 检查mysql服务器上的进程列表,建立了连接但处于SLEEP状态。

Hmmmm. Hmmmm。

So then I checked netstat to see who was trying to send/receive what. 那么我检查了netstat以查看谁正在尝试发送/接收内容。

On the webserver : 在网络服务器上:

[root@prweb133v ~]# netstat -t -n -a | grep 36615
tcp        0      5 172.23.179.6:36615          172.23.179.67:3306         
ESTABLISHED 

and on the mysql server there was an established connection but 0 in the send or receive queues. 并且在mysql服务器上有一个已建立的连接,但在发送或接收队列中为0。

Any idea what these mysterious 5 bytes could be, or why they randomly don't get the the mysql server? 知道这些神秘的5个字节是什么,或者为什么他们随机不得到mysql服务器?

Cheers! 干杯!

Mike 麦克风

Someone e-mailled me from this page, so I went back to the OP and got this update on the eventual fix we used: 有人通过这个页面给我发了电子邮件,所以我回到OP并获得了我们使用的最终修复的更新:

It's been a while, but as far as I remember this was due to some network error between the web server and the mysql server. 已经有一段时间了,但据我记得这是由于Web服务器和mysql服务器之间的一些网络错误。 We were using persistent connections, so the resource was still held open by apache although somewhere along the network the connection had died without either server being aware of it, I think that was due to a poorly configured (or written) firewall. 我们使用的是持久连接,所以资源仍然由apache保持打开,虽然网络中的某个地方连接已经死亡而没有任何服务器意识到它,我认为这是由于配置不当(或写入)的防火墙。

We stopped using persistent connections and the problem went away. 我们停止使用持久连接,问题就消失了。

What mysql-engine are you using (myisam, innodb, ...)? 您使用的是什么mysql-engine(myisam,innodb,...)? Do you use mysql or mysqli interface on the php side? 你在php端使用mysql或mysqli接口吗?

I would give the "log" and "log_slow_queries" in the mysql config file a try (possibly to a ramdisk) along with wading trough the output for "SHOW GLOBAL STATUS;" 我会在mysql配置文件中尝试“log”和“log_slow_queries”(可能是ramdisk)以及通过“SHOW GLOBAL STATUS”输出的涉水 in the mysql shell (every server variable that ends in "*_waits" or is connection related). 在mysql shell中(每个服务器变量以“* _waits”结尾或与连接相关)。

Do you have altered any part in the "Fine tuning" section of the mysql config file? 你有没有改变mysql配置文件的“微调”部分的任何部分? Changed some buffers? 换了一些缓冲区?

In the php.ini, do you have a default value (60) for mysql.connect_timeout? 在php.ini中,你有mysql.connect_timeout的默认值(60)吗? Setting "mysql.trace_mode" to "on" won't hurt for a while. 将“mysql.trace_mode”设置为“on”不会有一段时间的伤害。

You also might want to stress-test, if possible, different parts/URLs of your app with a tool like "ab" in order to narrow it down. 您也可能希望使用“ab”等工具对应用程序的不同部分/ URL进行压力测试,以缩小范围。

Or: When using apache with prefork module, locally start only one server ("Startservers 1", "MaxSpareServers 0", something like that) and stress test until it hangs. 或者:当apache与prefork模块一起使用时,本地只启动一个服务器(“Startservers 1”,“MaxSpareServers 0”,类似的东西)并进行压力测试直到它挂起。 Then the logs could be of more value. 然后日志可能更有价值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM