(dv) HOWTO: Basic Apache performance tuning (httpd)
OVERVIEW:
This article will provide some basic apache (httpd) performance tuning. The objective of this article is to perform simple edits that will allow your (dv) server to run with less memory and to ensure higher availability under heavier loads.This is Part 1 of a series of articles on how to tune your (dv) for better performance. Please see (dv) HOWTO: Performance tuning (Optimization) for additional articles in this series.
Symptoms:
- Frequent apache (httpd) crashes
- Slow server response
- "Server unreachable" errors
- kmemsize warnings in your QoS Alerts (Plesk Control Panel under Virtuozzo)
- privvmpages warnings in your QoS Alerts (Plesk Control Panel under Virtuozzo)
LINKS:
http://httpd.apache.org/docs/2.2/ Apache Doumentation sitehttp://httpd.apache.org/docs/2.2/mod/core.html#timeout Documentation on the Timeout setting.
http://httpd.apache.org/docs/2.2/mod/mpm_common.html#maxclients Documentation on MaxClients
DETAILS:
Apache Timeout setting
The timeout setting is the number of seconds before data "sends" or "receives" (to or from the client) time out. Having this set to a high number forces site visitors to "wait in line" which adds extra load to the server.- First backup the file with the following command:
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.bkup.kb-246.1 - The following command opens httpd.conf and searches for the term Timeout:
You should see the following lines:vi +/Timeout /etc/httpd/conf/httpd.conf# Timeout: The number of seconds before receives and sends time out. Timeout 120 - Edit the section that reads:
to a more reasonable value like the following:Timeout 120Timeout 20 - Save this file.
- Restart Apache to apply the changes:
/etc/init.d/httpd restart
Max Client Settings
On (dv) Dedicated-Virtual v2.0 Servers:
- First backup the file with the following command:
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.bkup.kb-246.2 - The following command opens httpd.conf and searches for MaxClients:
You should see the following section marked prefork MPM.vi +/MaxClients /etc/httpd/conf/httpd.conf - Edit the section that reads:
to something more like this:<IfModule prefork.c> StartServers 2 MinSpareServers 1 MaxSpareServers 5 MaxClients 10 MaxRequestsPerChild 1000 </IfModule>- For Base servers:
<IfModule prefork.c> StartServers 1 MinSpareServers 1 MaxSpareServers 3 MaxClients 50 MaxRequestsPerChild 1000 </IfModule> - For Rage servers:
<IfModule prefork.c> StartServers 2 MinSpareServers 2 MaxSpareServers 5 MaxClients 100 MaxRequestsPerChild 1000 </IfModule> - For Extreme servers:
<IfModule prefork.c> StartServers 2 MinSpareServers 2 MaxSpareServers 5 MaxClients 200 MaxRequestsPerChild 1000 </IfModule>
- For Base servers:
- Save this file and restart Apache to apply the changes:
/etc/init.d/httpd restart
On (dv) Dedicated-Virtual v3.x Servers:
- First backup the file with the following command:
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.bkup.kb-246.2 - The following command opens httpd.conf and searches for MaxClients:
You should see the following section marked prefork MPM.vi +/MaxClients /etc/httpd/conf/httpd.conf - Edit the section that reads:
to something more like this:<IfModule prefork.c> StartServers 1 MinSpareServers 1 MaxSpareServers 20 ServerLimit 20 MaxClients 150 MaxRequestsPerChild 4000 </IfModule> - For Base servers:
<IfModule prefork.c> StartServers 1 MinSpareServers 1 MaxSpareServers 3 ServerLimit 50 MaxClients 50 MaxRequestsPerChild 4000 </IfModule> - For Rage servers:
<IfModule prefork.c> StartServers 2 MinSpareServers 2 MaxSpareServers 5 ServerLimit 100 MaxClients 100 MaxRequestsPerChild 4000 </IfModule> - For Extreme servers:
<IfModule prefork.c> StartServers 2 MinSpareServers 2 MaxSpareServers 5 ServerLimit 200 MaxClients 200 MaxRequestsPerChild 4000 </IfModule> - For Nitro servers:
<IfModule prefork.c> StartServers 20 MinSpareServers 20 MaxSpareServers 50 ServerLimit 500 MaxClients 500 MaxRequestsPerChild 4000 </IfModule>
- For Base servers:
- Save this file and restart Apache to apply the changes:
/etc/init.d/httpd restart
NOTE:
If you are running into frequent Apache crashes you can check the error_log for MaxClients-related problems.
To check your error logs to see if you have MaxClient issues you can run the following command as root:
grep -i maxclient /var/log/httpd/error_log* If this command returns any results after making the above changes you may need to fine-tune the MaxClients variables further.
The official documentation on these settings and many others can be found here:
http://httpd.apache.org/docs-2.0/mod/mpm_common.html
Revisions:
07-20-2009: Minor Fixes
Fields marked with an asterisk(*) are required. Comment on this article