Shared item
1 shares
Zak B. Elep: Apache2 Worker MPM on Low Memory Servers
via Planet Ubuntu by (author unknown) on May 09, 2008
If you're running Apache2 on a memory-constrained system (like in avirtual machine,) you may want to choose the prefork MPM to save memory atthe cost of more process forks. However, if you have more than one CPU on thatsame machine, you may also want to consider using the threaded worker MPMand tweak its
MaxClientsandThreadsPerChildsettings from the defaultconfiguration.On a typical
apache2installation on a Debian system, the worker MPMconfiguration looks like this:MaxClients 150 MinSpareThreads 25 MaxSpareThreads 75 ThreadsPerChild 25 MaxRequestsPerChild 0 Using these default settings on a resource-constrained system (say a serverwith 128MB of RAM but with no swap) would be overkill, and the web serverprocesses will definitely eat up all of that memory, leaving little or no roomfor even simple CGI scripts.
In my setup, I experimented with tweaking the values above to get apache2 toserve without eating up too much precious memory. I found that the importantvalues to consider here are
MaxClients, which dictate how many clients canconnect simultaneously to my server, andThreadsPerChild, which specifies howmany threads of execution can run in a child/worker process. My resultingconfig becomes:MaxClients 15 MinSpareThreads 3 MaxSpareThreads 7 ThreadsPerChild 3 MaxRequestsPerChild 200 With this setup, I free up a significant amount of RAM from apache2's hold whlemaximizing my thread usage in each worker process; at the same time, I avoidkeeping each child process for too long by setting a maximum number of requestseach worker can serve, preventing the workers to bloat too much when handlingCGI.
I also tweaked the
KeepAliveTimeoutsetting to just 2 seconds (instead of thedefault 15) so that each worker process can go to the next request quickly andpreventing them from being tied up to a connection for too long. I also settheTimeoutto 30 seconds.Shared by: