Sometimes, too many http requests, and hence too many httpd processes, "pile up", meaning the first ones take too long to respond, then the following ones queue up, and it takes forever to respond to all of them, and hence more requests pile up, exponentially, until the whole server collapses.
I have already tried limiting MaxClients to about as many as the server can handle without collapsing. However, while this does prevent Apache from spawning more processes, it does not seem to avoid more requests to pile up.
That is, if MaxClients is limited to 100, the 101st and following requests don't get an error, but rarher, for some reason, they are queued and wait until Apache is able to spawn more processes to handle them. So, this only prevents the whole operating system from falling with Apache, but this doesn't avoid the web server's saturation.
What can I do so that, being N=MaxClients, the N+1th request that finds the server too busy, immediately receives an error response, or is immediately denied connection (at whatever level)?
This is on Debian, and Apache is using prefork.
As an aside, just to show why I'm assuming the above approach could make sense, I have verified that when this avalanche effect happens, if I restart the apache server (which takes a fraction of a second), the server immediately goes back to normal, even if it is still under the same load, and after that it will work smoothly, usually for a long while until a new "avalanche" happens. In contrast, if I do nothing, the server will never recover.