mysql show processlist 列出了许多进程 sleep 和 info = null?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4053744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:34:54  来源:igfitidea点击:

Mysql show processlist lists many processes sleep and info = null?

mysqlmysql-management

提问by AlfaTeK

I'm injecting a stress test into my web app that connects to a mysql server and I'm monitoring the show processlist of mysql.

我正在将压力测试注入到连接到 mysql 服务器的 Web 应用程序中,并且我正在监视 mysql 的显示进程列表。

When the load is high (high swap i/o) I get many processes like that:

当负载很高(高交换 i/o)时,我会得到很多这样的进程:

| 97535 | db| localhost | userA | Sleep   |  515 |         | NULL 
| 97536 | db| localhost | userA | Sleep   |  516 |         | NULL 
| 97786 | db| localhost | userA | Sleep   |  343 |         | NULL 
| 97889 | db| localhost | userA | Sleep   |  310 |         | NULL 

But I can't understand why are they still there and are not killed? This eventually leads to my app using all max_connections and stop processing incoming requests...

但我不明白为什么他们还在那里并且没有被杀?这最终导致我的应用程序使用所有 max_connections 并停止处理传入请求...

Any idea what are those processes and what are they doing there :) ?

知道这些过程是什么以及他们在那里做什么:)?

回答by Keith Randall

Those are idle connections being held by a client. You should make sure that whatever client library you are using (JDBC, ...) is configured to not keep unused connections open so long, or that your # clients * max # of connections isn't too big.

这些是客户端持有的空闲连接。您应该确保您使用的任何客户端库(JDBC,...)都配置为不会将未使用的连接保持打开太长时间,或者您的 # clients * max # of connections 不会太大。

回答by zpon

My guess is that you are using persistent connections, e.g. pconnectin php:

我的猜测是您正在使用持久连接,例如php 中的pconnect

[..] when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection

[..] 连接时,该函数将首先尝试查找已使用相同主机、用户名和密码打开的(持久)链接。如果找到,将返回它的标识符而不是打开新连接

and

[..] the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain openfor future use

[..] 脚本执行结束时,不会关闭与 SQL 服务器的连接。相反,该链接将保持打开状态以备将来使用

I had a similar situation, and was using Codeigniter with pconnect turned on. After turning it to off (see how) every connection was closed down properly after use, and my MySQL processlist was empty.

我遇到了类似的情况,并且在打开 pconnect 的情况下使用 Codeigniter。将其关闭(查看如何)后,每个连接在使用后都正确关闭,并且我的 MySQL 进程列表为空。

Performance: The above does not argue about performance, but simply tries to explain why you might see a lot of Sleeping connections in MySQL. It might not be negative, with regard to performance, to have the connections stay active. More info at: http://www.mysqlperformanceblog.com/2006/11/12/are-php-persistent-connections-evil/

性能:上面没有讨论性能,只是试图解释为什么你可能会在 MySQL 中看到很多睡眠连接。就性能而言,让连接保持活动状态可能不是负面的。更多信息请访问:http: //www.mysqlperformanceblog.com/2006/11/12/are-php-persistent-connections-evil/