简体   繁体   English

Apache套接字没有关闭?

[英]Apache sockets not closing?

I have a web application written using CherryPy, which is run locally on 127.0.0.1:4321 . 我有一个使用CherryPy编写的Web应用程序,它在本地运行于127.0.0.1:4321 We use mod-rewrite and mod-proxy to have Apache act as a reverse proxy; 我们使用mod-rewrite和mod-proxy让Apache充当反向代理; Apache also handles our SSL encryption and may eventually be used to transfer all of our static content. Apache还处理我们的SSL加密,最终可能用于传输所有静态内容。

This all works just fine for small workloads. 这一切都适用于小型工作负载。 However, I recently used urllib2 to write a stress-testing script that would simulate a workload of 100 clients. 但是,我最近使用urllib2编写了一个压力测试脚本,可以模拟100个客户端的工作负载。 After some time, each client gets a 503 error from Apache, indicating that Apache cannot connect to 127.0.0.1:4321 . 一段时间后,每个客户端从Apache收到503错误,表明Apache无法连接到127.0.0.1:4321 CherryPy is functioning properly, but my Apache error log reveals lines like the following: 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

Googling for this error reveals that Apache has probably run out of socket file descriptors. 谷歌搜索此错误表明Apache可能已用完套接字文件描述符。 Since I only have 100 clients running, this implies that the connections are not being closed, either between my urllib2 connection and Apache (I am definitely calling .close() on the return value of urlopen ), or between Apache and CherryPy. 由于我只运行了100个客户端,这意味着我的urllib2连接和Apache之间没有关闭连接(我肯定在urlopen的返回值上调用.close() ),或者在Apache和CherryPy之间。

I've confirmed that my urllib2 request is sending an HTTP Connection: close header, although Apache is configured with KeepAlive On if that matters. 我已经确认我的urllib2请求正在发送HTTP Connection: 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? 那么我的下一步是什么阻止这个问题呢?

You might run the netstat command and see if you have a bunch of sockets in the TIME_WAIT state. 您可以运行netstat命令,看看是否有一堆处于TIME_WAIT状态的套接字。 Depending on your MaxUserPort setting you might be severly limited in the number of ports available to use. 根据您的MaxUserPort设置,您可能会严重限制可用端口的数量。 In addition the TcpTimedWaitDelay is usually set to 240 seconds so any sockets that are used cannot be reused for four minutes. 此外,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

SetEnv proxy-nokeepalive 1 would probably tell you right away if the problem is keepalive between Apache and CP. 如果Apache和CP之间存在问题, SetEnv proxy-nokeepalive 1可能会马上告诉你。 See the mod_proxy docs for more info. 有关详细信息,请参阅mod_proxy文档

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

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