I have a web application written using CherryPy that runs locally on 127.0.0.1:4321 . We use mod-rewrite and mod-proxy so that Apache acts as a reverse proxy; Apache also handles our SSL encryption and can ultimately be used to migrate all of our static content.
All this is great for small workloads. However, I recently used urllib2 to write a stress testing script that would simulate a workload of 100 clients. After a while, each client receives a 503 error from Apache, indicating that Apache cannot connect to 127.0.0.1:4321 . CherryPy is working fine, but my Apache error log shows lines like:
[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
Google for this error shows that Apache probably ran out of socket file descriptors. Since I only have 100 clients, this means the connections are not closing, either between my urllib2 connection and Apache (I definitely call .close() on the returned urlopen value), or between Apache and CherryPy.
I confirmed that my urllib2 request sends an HTTP Connection: close header, although Apache is configured with KeepAlive On , if that matters.
In case it matters, I use Python 2.5, Apache 2.2, CherryPy 3.0.3, and the server runs on Windows Server 2003.
So what is my next step to stop this problem?
source share