Support / KnowledgeBase

 
Search the KnowledgeBase Search

(dv) HOWTO: Basic Apache performance tuning (httpd)

  • Applies to: (dpv) Nitro, All (dv)

  • Difficulty: Medium

  • Time needed: 5 minutes

  • Tools needed: Root SSH vi

 

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 site
http://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.
  1. First backup the file with the following command:
     
    cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.bkup.kb-246.1
  2. The following command opens httpd.conf and searches for the term Timeout:

    vi +/Timeout /etc/httpd/conf/httpd.conf 
    You should see the following lines:

    # Timeout: The number of seconds before receives and sends time out.
    Timeout 120
  3. Edit the section that reads:

    Timeout 120
    to a more reasonable value like the following:

    Timeout 20
  4. Save this file by pressing the escape key followed by :wq! which will save the file and exit vi.
  5. Restart Apache to apply the changes:

    /etc/init.d/httpd restart

Max Client Settings

On (dv) Dedicated-Virtual v2.0 Servers:

  1. First backup the file with the following command:

    cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.bkup.kb-246.2
  2. The following command opens httpd.conf and searches for MaxClients:

    vi +/MaxClients /etc/httpd/conf/httpd.conf
    You should see the following section marked prefork MPM.
  3. Edit the section that reads:

    <IfModule prefork.c>
    StartServers       2
    MinSpareServers    1
    MaxSpareServers    5
    MaxClients         10
    MaxRequestsPerChild  1000
    </IfModule>
    
    
    to something more like this:
    • 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>
      
  4. Save this file and restart Apache to apply the changes:

    /etc/init.d/httpd restart

On (dv) Dedicated-Virtual v3.x Servers:

  1. First backup the file with the following command:


    cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.bkup.kb-246.2
  2. The following command opens httpd.conf and searches for MaxClients:


    vi +/MaxClients /etc/httpd/conf/httpd.conf
    You should see the following section marked prefork MPM.
  3. Edit the section that reads:

    <IfModule prefork.c>
    StartServers       1
    MinSpareServers    1
    MaxSpareServers    20
    ServerLimit        20
    MaxClients         150
    MaxRequestsPerChild  4000
    </IfModule>
    
    to something more like this:
    • 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>
      
  4. 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

User Comments

No visitor comments posted. Post a comment

Fields marked with an asterisk(*) are required. Comment on this article

Fill out the form below if you would like to comment on this article.
 
 
 

(code is not case-sensitive)
 
Submit
 
 

Continue