apache TIME_WAIT 连接过多

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/813790/
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-09-13 17:32:57  来源:igfitidea点击:

Too many TIME_WAIT connections

apachetcptime-wait

提问by Brent Baisley

We have a fairly busy website (1 million page views/day) using Apache mod proxy that keeps getting overloaded with connections (>1,000) in the TIME_WAIT state. The connections are to port 3306 (mysql), but mysql only shows a few connections (show process list) and is performing fine. We have tried changing a bunch of things (keep alive on/off), but nothing seems to help. All other system resources are within reasonable range.

我们有一个相当繁忙的网站(每天 100 万次页面浏览),它使用 Apache mod 代理,在 TIME_WAIT 状态下连接(>1,000)一直过载。连接是到端口 3306 (mysql),但 mysql 只显示几个连接(显示进程列表)并且运行良好。我们尝试过改变很多东西(保持开启/关闭),但似乎没有任何帮助。所有其他系统资源都在合理范围内。

I've searched around, which seems to indicate changing the tcp_time_wait_interval. But that seems a bit drastic. I've worked on busy website before, but never had this problem.

我四处搜索,这似乎表明更改了 tcp_time_wait_interval。但这似乎有点激烈。我以前在繁忙的网站上工作过,但从未遇到过这个问题。

Any suggestions?

有什么建议?

回答by Craig Lewis

Each time_wait connection is a connection that has been closed.

每个 time_wait 连接都是一个已经关闭的连接。

You're probably connecting to mysql, issuing a query, then disconnecting. Repeat for each query on the page. Consider using a connection pooling tool, or at very least, a global variable that holds on to your database connection. If you use a global, you'll have to close the connection at the end of the page. Hopefully you have someplace common you can put that, like a footer include.

您可能正在连接到 mysql,发出查询,然后断开连接。对页面上的每个查询重复此操作。考虑使用连接池工具,或者至少是一个保持数据库连接的全局变量。如果您使用全局,则必须在页面末尾关闭连接。希望您有一些常见的地方可以放置,例如页脚包含。

As a bonus, you should get a faster page load. MySQL is quick to connect, but not having to re-connect is even faster.

作为奖励,您应该获得更快的页面加载。MySQL 可以快速连接,但无需重新连接甚至更快。

回答by Gilles Rayrat

If your client applications are using JDBC, you might be hitting this bug: http://bugs.mysql.com/bug.php?id=56979I believe that php has the same problem Cheers, Gilles.

如果您的客户端应用程序使用 JDBC,您可能会遇到这个错误: http://bugs.mysql.com/bug.php?id=56979我相信 php 也有同样的问题 干杯,Gilles。

回答by xkcd150

We had a similar problem, where our web servers all froze up because our php was making connections to a mysql server that was set up to do reverse host lookups on incoming connections.

我们遇到了类似的问题,我们的 web 服务器都死机了,因为我们的 php 正在连接到一个 mysql 服务器,该服务器被设置为对传入的连接进行反向主机查找。

When things were slow it worked fine, but under load the responstimes shot through the roof and all the apache servers got stuck in time_wait.

当事情变慢时,它工作正常,但在负载下,响应时间会飞速发展,所有 apache 服务器都卡在 time_wait 中。

The way we figured the problem out was through using xdebug to create profiling data on the scripts under high load, and looking at that. the mysql_connect calls took up 80-90% of the execution time.

我们解决问题的方法是使用 xdebug 在高负载下在脚本上创建分析数据,然后查看它。mysql_connect 调用占用了 80-90% 的执行时间。