On Sun, Sep 16, 2012 at 9:26 AM, Michael Hampicke <gentoo-u...@hadt.biz> wrote: > Am 16.09.2012 08:55, schrieb Jarry: >> Hi, >> strange thing happened to my web-server (apache-2.2.22-r1): >> it started forking untill it used all ram/swap and stopped >> responding. I counted ~60 apache processes running (ps -a), >> all sleeping, top showed no load except all memory being used. >> Log-files showed nothing suspicious to me, except for a few >> "GET / HTTP/1.1 200 40" messages at the time when apache >> was already unable to send reply. >> >> Apparently my apache is not correctly configured when it >> "forked to death", but maybe someone can help me. I have >> about 1GB memory for apache. What should I change in my >> config so that apache never runs out of memory? >> >> server-info: >> Timeouts: connection: 60 keep-alive: 15 >> MPM Name: Prefork >> MPM Information: Max Daemons: 150 Threaded: no Forked: yes >> Module Name: prefork.c >> 31: StartServers 5 >> 32: MinSpareServers 5 >> 33: MaxSpareServers 10 >> 34: MaxClients 150 >> >> Jarry >> > > > Hi, > > try reducing MaxClients to 64, StartServers and MinSpareServers to 2 and > then observe how things develop. If you then feel apache is to slow to > respond to request under load, try increasing MinSpareServer one at a > time. But always keep in mind: every fork of apache eats your memory.
And sucks up system entropy. And increases connection latency, if you've already got a request waiting on that fork to spin up. I have StartServers, MinSpareServers, MaxSpareServers and MaxClients all pegged to the same value. And on the server in question, they'll all pegged to '10'. I have MaxRequestsPerChild set to 20000, so that any leaky processes get cleaned up. Because I need to fit a lot of operation into a limited space, I need to be able to reasonably predict how much RAM is going to be in use by each of my services. A "MaxClients" of 10 may seem small, but that's what Squid is for; only requests Squid couldn't cache get passed on to Apache. The server I'm describing is a VM with 4GB of RAM, and is also running MySQL, squid and memcached. For those playing with the numbers in their head, each of these numbers reflect RES (code+data resident in RAM): * Each Apache process is consuming 80-100MB of RAM. * Squid is consuming 666MB of RAM * memcached is consuming 822MB of RAM * mysqld is consuming 886MB of RAM * The kernel is using 110MB of RAM for buffers * The kernel is using 851MB of RAM for file cache (which benefits squid). And, not RAM, but potentially of interest for the curious: * The MySQL db is consuming 3.8GB on disk. * The Squid cache is about 9.2GB on disk. -- :wq