9

I am running a hobby webserver off of an ancient Blue & White G3/300 running Debian PPC Squeeze 2.6.30. The performance is okay for a while after a restart, but it eventually gets more and more bogged down. Right now it's at 76 days uptime, and the main culprit seems to be the memory usage of 10+ apache2 processes.

I think I need to lower the values for StartServers, MinSpareServers, and/or MaxSpareServers, but I'm not sure which one to adjust, and there are three sections for each depending on which mpm module is in use.

How do I tell which of the following sections I need to change, and what are some reasonable values given that the box has 448 MB physical memory (weird upgrade history of one each 64, 128, and 256 sticks)?

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

<IfModule mpm_event_module>
    StartServers          2
    MaxClients          150
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxRequestsPerChild   0
</IfModule>

There aren't any other instances of StartServers in my apache2.conf, but none of those mpm modules appear in mods-available or mods-enabled. Ideas?

Thanks!

1
  • I've gone on the assumption that your box is running low on memory (and your lousy performance is coming from swapping heavily). If you're not swapping I'll bug you for more details :-)
    – voretaq7
    Feb 12, 2010 at 18:34

2 Answers 2

7

400MB isn't much for a web server these days -- you may want to consider replacing the box :)

That said, if your memory usage is ballooning you probably have a memory leak somewhere -- for a quick test look at the size of the httpd processes now, then stop/start Apache & see if they're a lot smaller. If they are watch them for a few days and see if they grow.

If it is a memory leak the real solution for that is to find and fix the memory leak, but since that's usually a pain in the ass you can also adjust MaxRequestsPerChild to something other than 0 (unlimited). This will kill off the Apache workers when they've serviced a fixed number of requests (forcing them to give up their leaked memory in the process.

Start with larger values (in the thousands or so) and work your way down into the hundreds. If you get below 100 requests per child your memory leak is big enough to warrant actually fixing it as the performance hit from constantly killing off and re-spawning apache workers will be significant.


Re: which mpm to adjust, the answer is almost certainly prefork.
You can run httpd -V and look for the Server MPM: line which will tell you for sure.

4
  • 1
    -V gave me the prefork info I needed (although it's apache2 -V in my case). Thanks!
    – UltraNurd
    Feb 12, 2010 at 19:28
  • Seems to have done the trick. I think the problem was that I was running out of physical memory and swapping because too many child servers were up (each grabbing about 80 MB). And yes, I know, the server is old. But it's barely handling any requests :oD.
    – UltraNurd
    Feb 12, 2010 at 19:48
  • 1
    If you're not handling a lot of requests you can also trim the Start & Spare server counts as you mentioned in your original post (on development systems I set them all to something between 2 & 5 to reduce RAM usage)
    – voretaq7
    Feb 12, 2010 at 20:04
  • I ended up dropping the min and max spares to 3 and 6 from 5 and 10, and that seems to leave enough RAM leftover to keep things from swapping. Thanks!
    – UltraNurd
    Feb 17, 2010 at 15:53
2

To nail down the memory use of the apache process you will want to adjust the MaxClients.

The common rule of thumb is: (Max desired Memory) / (Memory Usage of 1 Apache Process) = # Max Clients

In the end you also need to adjust your to be MaxSpareServers <= Max Clients.

The memory usage of one process is strongly depended on the modules you have loaded (php and so on) so you may want to set the Max Clients a little lower.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .