I run a fairly busy webserver. It's pretty standard: Apache with mod_php on FreeBSD 7.1. It connects to a separate MySQL server. It serves lots of static images.

Users have been complaining of slow response times. Today I got very slow load times, then a "could not connect, try again" from my web browser.

Looking at top showed that the server was practically idle! Yet it was refusing any more connections. After a minute or so, it began responding again (though still slowly).

netstat -s includes

161796 listen queue overflows

but I'm not sure that's the problem, since I've increased somaxconn.

I must be hitting some resource limit. What else should I look at to diagnose the problem?


Perhaps you've got a relatively small MaxClients, keepalives on with a long-ish timeout, and quite a lot of requests.

Browsers will generally hold a connection open for 30 seconds or so if you let them - so don't set keepalive too long.

Having keepalive on for a short period is beneficial to your users - but it does use up resources. Are you able to see the Apache scoreboard (i.e. server-status page?) ? Are all your slots consumed in 'K' state?

In general mixing application serving (your PHP app) and high-volume static files is a bad idea, they have different requirements. A fat Apache process (like ones with PHP in) is going to be wasting lots of memory serving static images that could be served by a thin one instead. Consider putting them in separate sets of physical servers, or on separate server instances on the same set of servers (with very different configs)

  • Thanks, that was it. The scoreboard showed that all slots were full. Decreasing the keepalive was the key. Thanks! – Rick Nov 13 '09 at 2:12

First. Your bottleneck is almost certainly MySQL backend (or network between frontend and backend). So you've got idling frontend.
Second. You may wish to serve static via nginx/lighttpd if it's really highload webserver.
Third. I've posted quick manual about FreeBSD sysctl tuning, you may find it useful.

PS. There is also apache directive ListenBacklog you may wish to increase it along with MaxClients.

  • Those sysctl tuning recommendations were very helpful... – Bill B Nov 12 '09 at 13:44

Apache's MaxClients is a big one. You can view what the current client/connection count is by enabling mod_status and running "apachectl status" or loading "http://localhost/server-status" in a web browser from the web server


Depending on the scale of your static image serving, you might look into running something like lighttpd along side it to serve images. It tends to do much better with just static images. Lighttpd (lighty) is just that, light and will serve static content much more quickly and tuned a bit will likely not run into these limitations. The same could be done with Apache, but Apache is a bit hefty for just static content.


Is it doing reverse DNS lookups? (disable them)

Is avahi-daemon running? (kill it)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.