TIME_WAIT 连接过多

发布于 2024-07-17 21:02:25 字数 309 浏览 5 评论 0原文

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

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

有什么建议么?

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.

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.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

画中仙 2024-07-24 21:02:26

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

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

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

Each time_wait connection is a connection that has been closed.

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.

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

戒ㄋ 2024-07-24 21:02:26

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

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

红衣飘飘貌似仙 2024-07-24 21:02:26

我们遇到了类似的问题,我们的 Web 服务器全部冻结,因为我们的 php 正在连接到 mysql 服务器,该服务器被设置为对传入连接进行反向主机查找。

当速度很慢时,它工作得很好,但在负载下,响应时间会急剧增加,所有 apache 服务器都会陷入 time_wait 状态。

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

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.

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文