What is the best way to configure the number of workers in Apache?

My site receives a lot of traffic for 2 hours during the day (2000 hits per minute). The rest of the day receives less traffic(500e hits per minute). I have been experimenting with the MaxClients and MaxSpareServers values but I still get some downtime during peek hours.

How can I calculate the best values for my configuration based on the amount of ram that I have ?

Each process is like 36-40 M of Memory

             total       used       free     shared    buffers     cached
Mem:          3096        793       2302          0          0          0
-/+ buffers/cache:        793       2302
Swap:  

      0          0          0

Values that I am using now

<IfModule prefork.c>
StartServers 10
MinSpareServers 22
MaxSpareServers 60
ServerLimit 90
MaxClients 90
MaxRequestsPerChild  400

UPDATE: I found this from my hosting provider.

http://kb.mediatemple.net/questions/246/(dv)+HOWTO:+Basic+Apache+performance+tuning+(httpd)

I have the extreme package and I used 190 in MaxClients instead of 200 I tried it for half a night and I got some malloc error command line messages but using the free command and got like 800 M in the free column.


Solution 1:

If your server suffers from peaks it may be as well because apache handle the process & threads creation very slowly (in mpm_prefork mode it's 1 new subprocess per second). If you know your 'high traffic' needs (let's say it's 200 process) then tell apache to get always thes 200 proces ready, even if they do nothing 90% of tim. You'll be ready when people comes in.

Check this handy presentation (old but cool) http://www.techpresentations.org/Hacking_Apache_HTTP_Server_at_Yahoo!

No need for StartServers, MaxSpareServers, MinSpareServers - just MaxClients (constant pool size)