There was a problem loading the comments.

User Guide - Apache Web Server Performance Tuning

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

Applicable Plans - All eApps General VPS Plans

User Guide - Apache Web Server Performance Tuning

Overview

The Apache web server's default configuration is fine for the majority of sites. Most users will have no need to access or modify any of the configurations for their web server.

However, for those users who need to optimize performance, there are modifications that can be made to tune the web server to improve performance.

This User Guide is a quick overview for tuning the Apache web server. For more information on managing the Apache web server and your sites, see the following User Guides:

Note This User Guide is for performance tuning the Apache web server, not an application server like Tomcat, JBoss, Ruby on Rails, or GlassFish. For information on troubleshooting sites using those application servers, see their specific User Guides - http://support.eapps.com/kb


This is only a small subset of what can be done to tune an Apache web server. There are literally thousands of web pages on Apache performance tuning, along with several books on the subject. Due to this fact, eApps Support is only able to offer minimal support at best for any web server performance optimizations.

If your site requires extensive web server optimization and tuning, it is assumed that you are an expert in making these modifications, or have someone available to you that can make and support these modifications on a 24/7/365 basis. Any request for assistance with these modifications from eApps Support will be considered billable at our standard rate of $15 per 10 minute increment.

WARNING Any web server optimization and tuning will be wasted if your VPS does not have enough resources to serve your sites

From the official Apache documentation: "The single biggest hardware issue affecting web server performance is RAM. A web server should never ever have to swap, as swapping increases the latency of each request beyond a point that users consider "fast enough". This causes users to hit stop and reload, further increasing the load. You can, and should, control the MaxClients setting so that your server does not spawn so many children it starts swapping. This procedure for doing this is simple: determine the size of your average Apache process, by looking at your process list via a tool such as top, and divide this into your total available memory, leaving some room for other processes."

If your site receives a lot of traffic, or requires a lot of server resources to work, then you need to pay close attention to the plan you are on and the resources available when the site is under load.

Generally, only very small or hobby sites do well with the Standard and Standard Plus plans. For sites doing any type of e-commerce or serving web applications with Java or Ruby, the Standard Max plan should be your entry point, with the knowledge that moving to an Advanced or Premier plan as your business ramps up may be necessary.

eApps Supported Performance Modifications

Modifying php.ini
Finding the best value for MaxClients

eApps Support Guidelines
Links to other information


eApps Supported Performance Modifications

The only Apache Performance tuning options that are supported by eApps are the ones available in the Control Panel. However to fully optimize these values, there is one value called ServerLimit that can only be accessed by changing the httpd.conf file directly. (ServerLimit is one of the few modifications to httpd.conf that can be done safely)

The supported modifications can be done either through the Control Panel, or from the command line.

Using the Control Panel

To make changes to the Apache Web Server via the Control Panel, log in to your Control Panel, and click on the System Tab. If necessary, click on the Select Another System (Subscription) link on the left and choose the correct Virtuozzo Container.

Then, go to Server Management, Web Server. Click on Edit to change these values.

Web server values

WARNING Changing some of these values to a higher number without a corresponding increase in server resources will actually cause your web server to perform worse, not better. Many of these values will cause your web server to consume more memory, and if you do not have enough memory available, changing these values can significantly decrease the performance of your sites.

  • Port - by default, this is set to port 80. Generally, there should never be a reason to change this port number. eApps offers no support or assistance for any issues you may encounter with Apache if you change this value.
  • Start Servers - the StartServers directive sets the number of child server processes created on startup. There is generally no need to adjust this setting. By default this is set to 1, increase to 5 if your site handles a large number of requests.
  • Minimum spare server processes number - The MinSpareServers directive sets the desired minimum number of idle child server processes. An idle process is one which is not handling a request. By default, this is set to 1, be careful about about setting this to a large number, as the web server will create a new server process if needed at a rate of 1 per second, so having this number too high can easily over load the web server.
  • Maximum spare server processes number - The MaxSpareServers directive sets the desired maximum number of idle child server processes. An idle process is one which is not handling a request. If there are more than MaxSpareServers idle, then the parent process will kill off the excess processes. By default, this is set to 5. As with MinSpareServers, setting this value too high can over load the web server.
  • Max. number of clients - The MaxClients directive sets the limit on the number of simultaneous requests that will be served. Any connection attempts over the MaxClients limit will be queued.
Please note that this is NOT the maximum amount of connections that the web server can handle, but the maximum amount of http requests that can be serviced simultaneously. Once a request has been serviced, and the connection to the site established, then the request is considered idle by the web server, and another request can be serviced.

By default this value is either 10 or 32, depending on which Apache web server template was used when your VPS was created. Be aware that each request to the web site consumes memory, so do not change this value to a high number unless your VPS has plenty of free memory under a normal load.

See the section titled Finding the Best Value for MaxClients of this User Guide to see how to determine the optimum value for MaxClients for your VPS and sites.
  • Server Name - this is the name of the VPS that is shown on the System Tab, and also the name of the server that shows in any Apache error document. The Server Name has nothing to do with your site names. You can change this value, but keep in mind that there is only one server name, no matter how many sites you have.
  • Admin E-mail - the e-mail address that will get any status or error messages from the web server. By default, this is 'root@localhost', but you can change it to any e-mail address of your choosing.
Click Cancel to cancel your changes, or Save and Restart to save your changes and restart the web server, or Save to save the changes without restarting the web server.

Generally, the only values that most users will want or need to change are the Max. number of clients and the Admin E-mail. If you need to change any of the other values, please make sure that your VPS has enough resources, especially memory, to accommodate your changes.

ServerLimit and MaxClients

If you change the MaxClients value (Max. number of clients), then a corresponding value called ServerLimit will have to be changed to match the MaxClients value. In the Control Panel, the ServerLimit has to be changed through the File Manager.
  • ServerLimit - the ServerLimit directive sets the maximum configured value for MaxClients for the lifetime of the Apache process. If your MaxClients (Max. number of clients) value is 10, this number cannot be increased past 256. If your MaxClients value is 32, you can increase this number past 256. ServerLimit is bound by MaxClients, so make sure that both ServerLimit and MaxClients match.
To change the value of ServerLimit from the Control Panel, use the File Manager to navigate to the httpd.conf file, located in the etc >httpd >conf directory. Click the check box next to httpd.conf, and then click the Edit link. This will open the httpd.conf file for editing.

The httpd.conf file is over a thousand lines long. You may have to scroll down a few screens to find the section you need to change, which looks like this:

<IfModule prefork.c>
StartServers       1
MinSpareServers    1
MaxSpareServers    5
ServerLimit       10
MaxClients        10
MaxRequestsPerChild  4000
</IfModule>

(note that there is also a section starting with <IfModule worker.c> that has many of the same parameters. Do not change that section, change the parameters in the <IfModule prefork.c> section only)

Change ServerLimit to match MaxClients. See the section titled Finding the Best Value for MaxClients of this User Guide to see how to determine the optimum value for MaxClients for your VPS and sites.

If the ServerLimit value does not exist, you can add it manually.  Be careful of your spelling - ServerLimit has a capital S and a capital L and no spaces. If you misspell it, Apache will not start.

Once you have made your changes, click OK to save and exit the file. For the changes to take effect, you will then need to restart the web server from the System Tab, Web Server, Restart button.

Using the Command Line

Most of the values that can be changed via the Control Panel can also be changed via the command line. Generally speaking, using the command line is much faster than using the Control Panel.

The following must be done from the command line of the VPS while logged in via SSH - http://support.eapps.com/hsp/ssh, as the root user. This also assumes you are able to edit files using the vi editor.

[root@eapps-example ~]# cd /etc/httpd/conf
[root@eapps-example conf]# ll httpd.conf
-rw-r--r-- 1 root root 39329 Aug 11 13:13 httpd.conf
[root@eapps-example conf]# cp httpd.conf{,.back}
[root@eapps-example conf]# vi httpd.conf

The section of httpd.conf that contains the values to change is the prefork MPM section. Note that there is also a worker MPM section - changes made there will have no effect on the Apache web server.

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule prefork.c>
StartServers       1
MinSpareServers    1
MaxSpareServers    5
ServerLimit       10
MaxClients        10
MaxRequestsPerChild  4000
</IfModule>

Once you have made your changes, save and exit the file. and then restart the web server. If you are changing MaxClients and ServerLimit, see the section of this User Guide titled Finding the Best Value for MaxClients  to see how to determine the optimum value for MaxClients for your VPS and sites.

[root@eapps-example conf]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@eapps-example conf]#


Modifying php.ini

If your site is PHP based, or you are using an application that is written in PHP, then there are two modifications to the php.ini file that may help increase the performance of your site.

Note The same warnings apply for modifying php.ini as for modifying httpd.conf - if your VPS does not have the resources available to properly serve your sites, then any type of performance tuning will be wasted, and in fact may make your site perform worse, not better.


The documentation for the application you are using may also have recommendations for optimum values in php.ini, so please check that before making changes to the file.

To modify php.ini you will need to connect to the VPS via SSH - http://support.eapps.com/hsp/ssh, and be able to work as the root user, and edit files with the vi editor.

[root@eapps-example ~]# cd /etc
[root@eapps-example etc]# cp php.ini{,.bak}
[root@eapps-example etc]# vim php.ini

The two values that are normally changed are the memory limit and the max upload file size.

memory_limit = 32M   ; Maximum amount of memory a script may consume (16MB)

; Maximum allowed size for uploaded files.
upload_max_filesize = 2M

Here are the descriptions of both values, from the PHP.net site - http://php.net/manual/en/ini.core.php
  • memory_limit: This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1.
  • upload_max_filesize: The maximum size of an uploaded file.

For more information of the directives in the php.ini file, read the official PHP documentation - http://www.php.net/docs.php. eApps offers no actual support for php.ini modifications outside of the two described here.

Once you have made your modifications to php.ini, you will need to restart the web server for the changes to take effect.

For more information on PHP, see the PHP User Guide - http://support.eapps.com/hsp/php


Finding the best value for MaxClients

The MaxClients value, if set too low, may cause you to have times where your site appears to be unavailable, even though the web server is running and the site is up.In the /var/log/httpd/error_log file, you may see entries similar to these:

[Wed Aug 05 14:13:59 2009][error] server reached MaxClients setting, consider raising the MaxClients setting
[Fri Aug 07 11:50:32 2009][error] server reached MaxClients setting, consider raising the MaxClients setting
[Mon Jul 20 15:52:50 2009][error] server reached MaxClients setting, consider raising the MaxClients setting
[Sat Jul 18 09:31:56 2009][error] server reached MaxClients setting, consider raising the MaxClients setting


Another way to see if the web server is hitting the MaxClients is to see if the number of httpd connections exceeds your MaxClients value in httpd.conf.

[root@eapps-example ~]# ps -ef | grep -c httpd
13
[root@eapps-example ~]#

If the number returned by the ps -ef command is greater than MaxClients, then the MaxClients limit is being exceeded. You will need to increase MaxClients and restart the web server.

If you are consistently hitting MaxClients, even after increasing the value, then you need to consider upgrading to a larger plan that has more memory so that you can increase the MaxClients value even further.

Remember that MaxClients is NOT the maximum amount of connections that the web server can handle, but the maximum amount of http requests that can be serviced simultaneously.

To find the best value for MaxClients (and by extension ServerLimit) do the following. Note that all of this has to be done from the command line of the VPS, as the root user. See the SSH User Guide - http://support.eapps.com/hsp/ssh for more information if necessary.

First, find out how much memory, on average, each httpd process is using. To get an accurate reading, let your VPS and site run for a few hours to allow the memory usage to reflect normal conditions.  The memory usage that shows just after restarting httpd is often lower than what would usually be the case.

[root@eapps-example ~]# top -b -c -n 1 | grep httpd | awk '{print $6}'
18m
18m
18m
18m
21m
18m
19m
18m
18m
[root@eapps-example ~]#

In this example, the average memory usage is of each httpd process is 18 MB.

Next, stop Apache, and determine the amount of free memory available without the web server running using the free -m command.

[root@eapps-example ~]# service httpd stop
Stopping httpd:                                            [  OK  ]
[root@eapps-example ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           432         26        405          0          0          0
-/+ buffers/cache:         26        405
Swap:            0          0          0
[root@eapps-example ~]#

In this example, with the web server stopped, there is 405 MB of free memory.

It would be good to have at least 20 MB of free memory if Apache was running at its maximum, so subtract 20 from 405 to arrive at 385 MB of memory. Divide 385 by 18 (the average memory usage of each httpd process) to arrive at 21. Round this down to 20, and that should be the setting for both MaxClients and ServerLimit.

Keep in mind that this is simply an example, and your situation will be different. You may need to increase or decrease from the determined best value depending on your site, the traffic it gets, and the configuration of your applications.


eApps Support Guidelines

eApps Web Hosting is responsible for the Apache Web Server as installed in your VPS. It is our responsibility to ensure that Apache is installed correctly, and that the default Welcome Page shows correctly in a browser. We use a standard install of the latest version of the Apache server that was available to us from Parallels when the VPS was created. If you are using PHP for your sites, it is our responsibility to ensure that PHP is installed correctly and functioning.

eApps Web Hosting is not responsible for your sites, or the content of your sites, or the functionality of your sites. If the Apache Web Server is running, and the default Welcome Page shows for a new or default site, then that is technically the extent of our responsibilities.

If your sites have mission or business critical data or configurations, it is your responsibility to make sure that the content for the sites is safely backed up. Do not rely on eApps to have current copies of your data or files.

Any server modifications, such as htaccess files or mod_rewrite directives, are outside of our support boundaries. It is assumed that if you are making these types of modifications to your web site that you are familiar with the setup, configuration, and troubleshooting for these types of modifications, or that you know where to search to find the answers. Any assistance with server customizations such as htaccess files or mod_rewrite, or any assistance troubleshooting your site content or functionality could be considered billable support, at our standard rate of $15 per 10 minute increment.

If you make manual changes to httpd.conf, or add modules or make any other configurations changes to the web server, be aware that any support needed to correct problems caused by these modifications will be billable, at our standard rate of $15 per 10 minutes.

If you have made manual, unsupported changes to httpd.conf or to any other part of the web server and are requesting eApps Support assistance, please let us know, as this could save valuable time troubleshooting the problem.

The general assumption, if you are making unsupported changes to httpd.conf or to the web server, is that you are an expert in Apache web server configuration, and will not require any support assistance from eApps if you encounter any problems.

All changes to the virtual host blocks in httpd.conf must be done from the Control Panel. If you manually edit the virtual hosts in httpd.conf, the Control Panel will overwrite your changes, and your sites may stop functioning. This is a feature, not a bug, and this behavior cannot be changed.

As always, eApps support will go the extra mile to assist you with any problems you may have with your websites, but with the understanding that the content and functionality of your sites is ultimately your responsibility.


Links to other information

Apache Performance Tuning Official Guide - http://httpd.apache.org/docs/2.0/misc/perf-tuning.html
Apache Common Directives - http://httpd.apache.org/docs-2.0/mod/mpm_common.html

Apache MaxClients Official Documentation - http://httpd.apache.org/docs/2.2/mod/mpm_common.html#maxclients
PHP Official Documentation - http://www.php.net/docs.php

Share via
Did you find this article useful?  

Related Articles


On-Premise Help Desk Software by SupportPal

Categories

© Cloudscale365