Skip to content

Instantly share code, notes, and snippets.

@ZweiSteinSoft
Created August 16, 2012 06:32
Show Gist options
  • Save ZweiSteinSoft/3367379 to your computer and use it in GitHub Desktop.
Save ZweiSteinSoft/3367379 to your computer and use it in GitHub Desktop.
1. SSH into your server as root.
2. Run top.
3. Press shift + m.
4. Note the highest RES memory used by httpd.
5. Hit Q to exit top.
6. Execute: service httpd stop
7. Once httpd is stopped, execute: free -m
8. Note the memory listed under "used".
9. Find the guaranteed memory for your VPS plan. Support can tell you how much you have guaranteed if you cannot find it.
10. Subtract the memory USED from the memory that your plan is GUARANTEED. This will give you your base FREE MEMORY POOL.
11. Multiply the value of your FREE MEMORY POOL by 0.8 to find your average AVAILABLE APACHE POOL (this will allow you a 20% memory reserve for burst periods).
12. Divide your AVAILABLE APACHE POOL by the highest RES memory used by httpd. This will give you the MaxClients value that should be set for your system.
13. Open httpd.conf in your favorite text editor (don't use Windows text editors as they may break httpd.conf).
14. Set the MaxClients value you've calculated.
15. Set Keepalive Off if you don't need it (your server will handle more requests per second with keepalive on, but will require more memory for apache--don't turn on keepalive if you're not leaving a 20% memory reserve).
16. If you are leaving keepalive on, set keepalivetimeout to the lowest value you can to prevent connections from hanging. If you experience high latency to your server, set keepalivetimeout to 2-5 seconds.
17. Set your Timeout to a reasonable value. Pick a time that won't cut off the transfer of your pages to your customers, but keep it low enough that you don't have dead connections that remain open for a large period of time (10-30 seconds should be a good timeout if most of your users are on highspeed, and 30-120 should be ok for dialup).
18. MaxKeepAliveRequests should be set equal to the largest number of objects you have in 1 page. If you don't know, 70-200 should be good.
19. Set your MinSpareServers equal to 10-25% of MaxClients.
20. Set your MaxSpareServers equal to 25-50% of MaxClients.
21. Set your StartServers equal to either MinSpareServers or MaxSpareServers. When apache is restarted, this is the number of servers that will start and be ready for connections immediately. High-traffic sites should set this value to MaxSpareServers and lower volume sites should use MinSpareServrs.
22. MaxRequestsPerChild should be set somewhere between 500 (if you see rapid apache child process memory use growth) to 10000 (if you have no leaks in your applications). Setting this value to 0 will result in child processes never being killed, and eventually all shared memory used by apache will become "dirty" and unshared, possibly resulting in higher overall memory use.
23. Once you've set all values, save the file, exit, and issue: service httpd restart.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment