Apache 套接字未关闭?

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

Apache sockets not closing?

pythonapacheurllib2cherrypymod-proxy

提问by Eli Courtwright

I have a web application written using CherryPy, which is run locally on 127.0.0.1:4321. We use mod-rewrite and mod-proxy to have Apache act as a reverse proxy; Apache also handles our SSL encryption and may eventually be used to transfer all of our static content.

我有一个使用 CherryPy 编写的 Web 应用程序,它在127.0.0.1:4321. 我们使用 mod-rewrite 和 mod-proxy 让 Apache 作为反向代理;Apache 还处理我们的 SSL 加密,最终可能会用于传输我们所有的静态内容。

This all works just fine for small workloads. However, I recently used urllib2to write a stress-testing script that would simulate a workload of 100 clients. After some time, each client gets a 503 error from Apache, indicating that Apache cannot connect to 127.0.0.1:4321. CherryPy is functioning properly, but my Apache error log reveals lines like the following:

这一切都适用于小型工作负载。但是,我最近曾经urllib2编写过一个压力测试脚本来模拟 100 个客户端的工作负载。一段时间后,每个客户端都会收到来自 Apache 的 503 错误,表明 Apache 无法连接到127.0.0.1:4321. CherryPy 运行正常,但我的 Apache 错误日志显示如下几行:

[Thu Oct 02 12:55:44 2008] [error] (OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted. : proxy: HTTP: attempt to connect to 127.0.0.1:4321 (*) failed

[Thu Oct 02 12:55:44 2008] [error] (OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted. : proxy: HTTP: attempt to connect to 127.0.0.1:4321 (*) failed

Googling for this error reveals that Apache has probably run out of socket file descriptors. Since I only have 100 clients running, this implies that the connections are not being closed, either between my urllib2connection and Apache (I am definitely calling .close()on the return value of urlopen), or between Apache and CherryPy.

谷歌搜索这个错误表明 Apache 可能已经用完了套接字文件描述符。由于我只有 100 个客户端在运行,这意味着连接没有被关闭,无论是在我的urllib2连接和 Apache之间(我肯定是在调用.close()的返回值urlopen),或者在 Apache 和 CherryPy 之间。

I've confirmed that my urllib2request is sending an HTTP Connection: closeheader, although Apache is configured with KeepAlive Onif that matters.

我已经确认我的urllib2请求正在发送一个 HTTPConnection: close标头,尽管 Apache 配置了KeepAlive On如果这很重要。

In case it matters, I'm using Python 2.5, Apache 2.2, CherryPy 3.0.3, and the server is running on Windows Server 2003.

以防万一,我使用的是 Python 2.5、Apache 2.2、CherryPy 3.0.3,并且服务器在 Windows Server 2003 上运行。

So what's my next step to stop this problem?

那么我的下一步是什么来阻止这个问题?

回答by fumanchu

SetEnv proxy-nokeepalive 1would probably tell you right away if the problem is keepalive between Apache and CP. See the mod_proxy docsfor more info.

SetEnv proxy-nokeepalive 1如果问题是 Apache 和 CP 之间的 keepalive,可能会立即告诉您。有关更多信息,请参阅mod_proxy 文档

回答by user9895

You might run the netstat command and see if you have a bunch of sockets in the TIME_WAIT state. Depending on your MaxUserPort setting you might be severly limited in the number of ports available to use. In addition the TcpTimedWaitDelay is usually set to 240 seconds so any sockets that are used cannot be reused for four minutes.

您可以运行 netstat 命令并查看是否有一堆处于 TIME_WAIT 状态的套接字。根据您的 MaxUserPort 设置,您可以使用的端口数量可能会受到严重限制。此外,TcpTimedWaitDelay 通常设置为 240 秒,因此使用的任何套接字在四分钟内都不能重复使用。

There's more good information here --> http://smallvoid.com/article/winnt-tcpip-max-limit.html

这里有更多好的信息--> http://smallvoid.com/article/winnt-tcpip-max-limit.html