Apache Optimization

From Wiki
Jump to: navigation, search

Contents

Apache1 vs Apache2 and MPMs

There are three versions of Apache that are supported by both the Apache project and Cpanel: 1.3, 2.0 and 2.2. For purposes of this discussion, 2.0 and 2.2 will be collectively referred to as Apache2.

Apache 1.3 is fairly simple compared to Apache 2. Directive values that do not require a specific MPM or reference Prefork can be applied to Apache 1.3. While Apache 1.3 is stable, it is old and not as flexible as Apache 2. Unless the customer has a specific reason for running Apache 1.3, please recommend an upgrade to them.

Apache 2 can be compiled with a variety of Multi Process Modules, or MPMs. The MPMs fundamentally change how Apache behaves as a program. While there are multiple MPMS, there are only three that are supported in the Linux version of Apache2, which may be compiled in from source or using cPanel's Easy Apache: Prefork, Worker and Event. You will also see notes of mpm_common or core in documentation, which indicate directives that are common to all MPMs. Apache 2.0 also has two experimental MPMs that are not present in Apache 2.2, leader and perchild. The two most common MPMs are Prefork and Worker, and only one MPM can be compiled into Apache at a given time.

To determine which MPM you're working with:

 httpd -V | grep -i mpm

Prefork

http://httpd.apache.org/docs/2.2/mod/prefork.html

Prefork implements a non-threaded, pre-forking web server that behaves much like Apache 1.3. Prefork is good for libraries that are non-thread-safe, or for instances where each Apache request needs to be isolated. With prefork, each child process is either a request or an idle server.

When using EasyApache, regardless of options selected in EasyApache, Prefork is the default MPM for Apache2. (I rebuilt that sentence completely) If none are selected, prefork will be compiled in. However, if prefork is not selected in EasyApache, the directives will need to be added by hand.

Worker

http://httpd.apache.org/docs/2.2/mod/worker.html

Worker is a multi-process, multi-threaded server. Each Apache process under Worker can serve multiple requests, simultaneously. This allows Worker to serve more requests while using fewer resources than Prefork. Worker is ideal for high traffic servers or servers that are experiencing Apache related memory issues.

Event (Experimental for Apache 2.2, default for Apache 2.4)

http://httpd.apache.org/docs/2.2/mod/event.html

http://httpd.apache.org/docs/2.4/mod/event.html

Event is an experimental MPM that tries to solve the "Keep Alive Problem" in HTTP by using dedicated threads to handle listening sockets and sockets that are being Keep Alive. Since Event is based off of Worker, it is configured just like Worker is. Do not install this on a customer's Apache 2.2 server unless they request it, as it is incompatible with mod_ssl in that version.

KeepAlive should almost ALWAYS be turned on. If you have keepalive off with MPM Event you're doing it wrong.

Make sure you are CHECKING the Apache version. It matters which directives you're using for the version. httpd -V Apache 2.2 MPM Event = MaxClients Apache 2.4 MPM Event = MaxRequestWorkers

ALSO MPM Event MaxRequestsPerChild = MaxConnectionsPerChild They are the same directive. These should always bet set to 0! Which means unlimited. MaxRequestsPerChild 0 MaxConnectionsPerChild 0

Don't define it twice, I am just showing you it should be set to 0 for either one.

Also changing settings for Apache through WHM for MPM Event will make almost 0 difference. You must change these through an include file.

/usr/local/apache/conf/includes/pre_virtualhost_global.conf

That is the preferred configuration file to add Apache MPM Event and Worker directives to.

ALSO do not do a restart after changing MPM Event directives. Do a full stop / start

httpd stop

Check to make sure its stopped

httpd status

httpd start

Threadpool (Apache 2.0 Only) [Experimental]

http://httpd.apache.org/docs/2.0/mod/threadpool.html

Threadpool is an experimental MPM that is based off of Worker. It handles the queue of idle requests differently than Worker does. It is considered to be a developer's playground and doesn't perform as well as Worker in benchmark tests. Do not install this on a customer's server unless they request it.

Leader (Apache 2.0 Only) [Experimental]

http://httpd.apache.org/docs/2.0/mod/leader.html

Leader is an experimental MPM that uses a Leader/Followers design pattern to coordinate work among threads. It is based off of Worker, so it is optimized like Worker. Since it is experimental, do not install it on a customer's server unless they request it.

Perchild (Apache 2.0 Only) [Experimental]

http://httpd.apache.org/docs/2.0/mod/perchild.html

Perchild is a thread experimental MPM. While it is selectable in EasyApache, the Offical Apache Documentation has the following note on the Perchild page.

Warning: From the Apache docs: This module is not functional. Development of this module is not complete and is not currently active. Do not use perchild unless you are a programmer willing to help fix it.

I would recommend against installing this MPM

Apache Optimization Directives

Below is the list of Directives that we change in order to optimize Apache. These values maybe tweaked to any value, however values that are too high for a server's available hardware may cause Apache to respond more slowly, a shortage of resources, and/or server instability. Remember that these are only suggestions and that each server is different. If you have any questions regarding a particular server, please consult the admin comment or the monitoring team.

Directives Common to all Apache variants, or Core Directives

These are directives are available to Apache, regardless of version number and MPM. These directives may sometimes be located in different locations from the MPM specific directives.

Timeout

Timeout <integer> (Default 300)

Timeout, in seconds, controls how much time Apache will wait for the follow three conditions:

  1. The total amount of time it takes to receive a GET request
  2. The amount of time between receipt of TCP packets on a POST or PUT request
  3. The amount of time between ACKs on transmissions of TCP packets in responses.

On dedicated hardware we leave this value at 300 and it is set to 100 on VPSes. This value is pretty safe to be left alone in most cases. If a server is getting slammed by traffic, lowering Timeout may help mitigate this by decreasing the amount of time that apache will hold open a process waiting for a slow response. It may need to be increased in the odd case that code doesn't reset the timer when one of these conditions occurs.

Timeout can be set in the Server Config, or in individual vhosts.

KeepAlive

KeepAlive <on|off> (Default on)

KeepAlive controls whether a request is "Kept Alive" or not when it serves a request to a client. With KeepAlive on, Apache requests are kept alive so that one connection is used to serve multiple requests. With KeepAlive off, once a request is served, apache will close the connection and the client will need to open a new request. A KeepAlive connection will count as only one request for MaxRequestsPerChild, regardless of how many requests are actually sent.

KeepAlive is a tricky directive. The default is on, and for the most part, this will serve well for most servers. If a server is experiencing a lot of traffic and Apache is having trouble keeping up, turning KeepAlive off can help. The caveat to this is if the high traffic site is either dynamic content or each page has to load a large number of individual files, such as with a forum, turning KeepAlive off is a bad idea, as it will open a new connection to load each individual file.

KeepAlive can be set in the Server Config and in individual vhosts.

MaxKeepAliveRequest

MaxKeepAliveRequests <integer> (Default 100)

MaxKeepAliveRequests limits the number of requests that are allowed per connection when KeepAlive is on. If this is set to 0, unlimited requests will be allowed. We leave this value to 100 on VPSes, and up it to 150 on dedicated hardware. Once a connection has hit the MaxKeepAliveRequests, it will be closed. If KeepAlive is off, this value will not be read.

If a server can handle it, this value can be safely increased. If the server is having connection issues, dropping it is an option, but it is probably a better idea to just turn KeepAlive off.

MaxKeepAliveRequests can be set in the Server Config or in individual vhosts.

KeepAliveTimeout

KeepAliveTimeout <integer> (Apache Default 5, Cpanel Default 15)

KeepAliveTimeout, in seconds, controls how long Apache will wait for a subsequent request from a specific client before closing the connection to that client. Having this value too high will cause performance problems on high traffic servers. This is because server processes will be occupied waiting on connections with idle clients. We set this value to 5 on both Dedicated hardware and VPSes. If KeepAlive is off, this value will not be read.

This value can be set in the server config and in individual vhosts.

MaxClients

MaxClients <integer> (Apache Prefork Default 256, Apache Worker Default ServerLimit X ThreadsPerChild, Cpanel Default 150)

MaxClients sets the limit on the simultaneous requests that will be served. Connections over this value will be queued, which is controlled by the ListenBacklog variable. Once an open slot is available, Apache will pick up the queued requests. Worker's MaxClients must be equal to no more than ServerLimit X ThreadsPerChild.

On dedicated hardware running prefork, we initially set MaxClients to 250. On VPSs and dedicated hardware running Worker, we set MaxClients to 150. MaxClients can be increased if a server is having trouble keeping up with legitimate traffic, and can vary greatly, depending on the type of content being served, the kind of server it is, and the amount of memory the server has. Increasing this value should be done cautiously, because if it is set too high you will see an increase in server instability, as each additional MaxClient causes apache to use more resources.

If you set prefork's MaxClient above 256, the ServerLimit may also be also need to be set. The MaxClient value can only be set in the server config.

ServerLimit

ServerLimit <integer> (Apache Prefork Default 256, Apache Worker Default 16)

With prefork, ServerLimit sets the MaxClients for the lifetime of the Apache process. With worker, ServerLimit combined with ThreadLimit determines the server's MaxClients. Please note that the ServerLimit cannot be changed via a restart. It requires that you stop and start apache.

This Value does not need to be set, unless it is required to increase MaxClients above the server's hard limit. Please note that there is a hard coded limit on ServerLimit, 20,000 for worker and 200,000 for prefork. This is intended to avoid nastyness caused by typos.

This value is set in the server config.

MaxRequestsPerChild

MaxRequestsPerChild <integer> (Apache Default 10000, Cpanel Default 0)

MaxRequestsPerChild sets a limit on the number of requests each individual Apache process will handle. Once this value is reached, the child process is stopped. A value of 0 will prevent processes from expiring. We usually set this value to 10 times the number of MaxClients (up to 1000, e.g. if MaxClients=1000, MaxRequestsPerChild should not exceed 1000), to prevent accidental memory leaks. If the content being served by Apache is stable (even if not static) this directive can be set quite high, to allow processes to serve more content.

This value is set in the server config.

StartServers

StartServers <integer> (prefork default 5, worker default 3)

StartServers controls how many child processes are spawned at startup. Please note that after start, this directive isn't used. What value this should be set to is dependent on the type and size of CPU, as well as the amount of memory the server has. Due to the way Apache works, setting this value lower than MinSpareServers or more than MaxSpareServers is counterproductive as it generally only puts extra load on the server itself.

This value is set in the server config.

RLimitCPU

RLimitCPU <min> | <max> [set in seconds] (Not set by default)

RLimitCPU determines the CPU limit for all child processes. The first value is a soft limit and the second value is a hard limit. Either value can be set to a number or the word "max". This applies only to processes forked off from Apache child processes, such as PHP or CGI processes, not the Apache children themselves. This value is expressed in seconds per process.

RLimitCPU can be set in the server config, an individual domain's vhost, a directory block, or an .htaccess file in the domain's docroot.

Do not set this value on a VPS.

RLimitMEM

RLimitMEM <min> | <max> [set in bytes] (Not set by default)

RLimitMEM determines the memory limit for all child processes. The first value is a soft limit and the second value is a hard limit. Either value can be set to a number or the word "max". This applies to processes forked off from Apache child processes, such as PHP or CGI processes, not the Apache children themselves. This value is expressed in bytes per process.

RLimitMEM can be set in the server config, an individual domain's vhost, a directory block, or an .htaccess file in the domain's docroot.

Do not set this value on a VPS.

Directives common to Apache 1.3 and Prefork

Below are values that are common both Apache 1.3 and Prefork builds of Apache2. Having these values outside of a prefork include in the httpd.conf with worker installed will cause Apache to error on a restart and prevent Apache from starting.

MinSpareServers

MinSpareServers <Integer> (Default 5)

MinSpareServers dictates what the minimal number of idle child server processes will be running at any given time. If the number of idle servers is less than this number, Apache will start them at a rate of 1 per second. This value should always be tweaked with available server resources in mind. If a server is experiencing memory shortages, this value can be safely dropped. A good rule of thumb is that this setting and StartServer should be the same.

This value is set in the server config.

MaxSpareServers

MaxSpareServers <Integer> (Default 10)

MaxSpareServers dictates what the maximum number of idle child server processes will be running at any given time. If the number of idle servers is more than MaxSpareServers, Apache will just kill the processes off. If this value is less MinSpareServer, Apache will automagically set MaxSpareServer to MinSpareServer +1. Like with MinSpareServer, this value should always be tweaked with available server resources in mind. For lower values of MinSpareServer, doubling that to get MaxSpareServer is generally a good rule of thumb.

This value is set in the server config.

Directives common to Worker, Event and Leader

The following directives are common to the Worker MPM and it's derivatives, Event and Leader. Having these directives active in the server config outside of an IfModule statement with prefork compiled, will cause Apache to error out and refuse to start. Even though Worker, Event and Leader all use the same directives, they will not read directives inside another's statement. For example: Event will not read directives in a Worker IfModule include.

ThreadsPerChild

ThreadsPerChild <Integer> (Default 25)

ThreadsPerChild dictates how many threads each child process will create when the process is spawned. This value should be high enough to handle the server's load. The value of this, along with the value of ServerLimit determine what maximum MaxClients is. Generally this value doesn't need to be changed.

This value is set in the server config.

ThreadLimit

ThreadLimit <integer> (Default 64)

ThreadLimit determines what the maximum value ThreadPerChild can be. A restart will not re-read this directive, you will have to stop and start Apache. Please take care when changing this directive. If ThreadLimit is too high compared to ThreadsPerChild, extra unused shared memory will be allocated to Apache. If ThreadLimit and ThreadsPerChild are set too high, it could make Apache and the server unstable. This value should be left at its default unless ThreadsPerChild is raised. There is a hard limit of 20,000 on this.

This value is set in the server config.

MinSpareThreads

MinSpareThreads <integer> (default 75)

MinSpareThreads determines how many idle threads are present on the server at a given moment. If the number of idle threads is less than MinSpareThreads, Apache will create child processes until enough idle threads are present. This value should be set depending on traffic to the server and the type and size of CPU, as well as the amount of memory the server has. We generally set this value to 25.

This value is set in the server config.

MaxSpareThreads

MaxSpareThreads <integer> (default 250)

MaxSpareThreads sets the upper limit on how many idle workers may be present at a given time. If current idle is higher than MaxSpareThreads, Apache will kill off child processes until the number of idle servers is less than this number. Apache will automatically increase MaxSpareThreads if it is not equal to or greater than the sum of MinSpareThreads and ThreadsPerChild. Like with MinSpareThreads, this value should be set depending on traffic to the server and the type and size of CPU, as well as the amount of memory the server has.. We generally set this value to 75.

This value is set in the server config.

Optimizing Apache

Browser Caching

The best way to make Apache faster is to give it less work to handle. By enabling browser caching in .htaccess you are telling client browsers to hang on to static files for future requests. What this means for Apache is that the next time someone re-visits the site, they will not need to request as many files as they previously requested. Less files means less work for Apache. This makes websites load much faster after the first visit.

To enable this, please visit this wiki link: https://wiki.int.example.com/articles/Htaccess#Enable_Browser_Caching_and_Compression

Worker vs Prefork

The Worker vs Prefork debate is one of the many debates that can come about when working with Apache. Which is right for you, and which should be used when. Prefork is the default MPM for Apache, and it works well for most of our customers. If the customer has an Apache module installed that does not work with threading, they will have to use Prefork.

Prefork does have its limitations, however. It uses more resources than worker, and as such it does not scale well. Servers running with mpm_prefork that have high traffic or servers that are having repeat Apache related memory problems should consider mpm_worker. Alternatively, mpm_worker shouldn't be installed if the customer has a compelling reason for each Apache request to be isolated. Since worker is threaded, each child process handles multiple requests and may not be appropriate to what the customer needs.

Worker should also not be used if the customer needs to use software that is not thread-safe. The DSO handler for PHP is not threadsafe, and cannot be used with Worker. If they want to use Worker with PHP, they'll need to use either SuPHP or one of the CGI handlers.

As a rule, the other experiment MPMs should be avoided. Since changing MPMs requires a recompile, always clear the recompile with the customer beforehand.

Apache is running out of connections

Template:Warning

Apache does have limits to how much traffic it can handle, but fortunately there are things we can tweak in the httpd.conf to allow Apache to handle more requests. If a server is getting legitimate traffic, ie. not getting DOS'd, these tips could help Apache keep up with the amount of traffic the server is receiving. Try one suggestion at a time and observe how the server reacts over a 5 to 10 minute span before trying something else.

Warning: Be aware of how much RAM a server has while tweaking these settings. Changing these values too high can cause other issues, such as putting the server into a potential OOM (Out Of Memory) state.
  • Raising the MaxClients - If the Apache error_log specifically mentions that Apache is hitting its Max Connections, raising MaxClients is always an option. Check and double check the bandwidth graphs to ensure there hasn't been a sudden inbound traffic spike. Raise this in increments of 50, being aware that increasing this value too high could cause other problems. The specific warning in the Apache error_log will be as follows:
WARNING: MaxClients of 500 exceeds ServerLimit value of 256 servers, lowering MaxClients to 256. To increase, please see the ServerLimit directive.


Note: raising MaxClients may require a raise in ServerLimit and ThreadLimit in worker. Apache will give an error on restart if this is the case.The ServerLimit and ThreadLimit directives will need to be above the MaxClients directive.

  • Turning KeepAlive off - If the server has fairly static content, such as a cached WordPress site, turning KeepAlive off will often help. Servers with dynamic content such as forums do not benefit from KeepAlive off. If one site is having trouble, try turning KeepAlive off for the one domain in that domain's vhost.
  • Dropping the KeepAliveTimeout - If the server didn't respond to turning KeepAlive off, dropping the KeepAliveTimeout will help Apache refresh its connections faster. If one site on the server is getting more traffic than others, try setting this value in the domain's vhost.

Apache is having memory issues

Next to MySQL, Apache is generally the most resource heavy service a server will run. If Apache is causing the server to go OOM, and PHP has sane memory usage directives (set in the server's php.ini), below are some tricks that can be tried. Please note that if the server is having heavy traffic and memory issues, upgrading is generally the best (and sometimes only) option and anything here would be considered a band-aid. Also, if the server in question is a VPS, they will probably have to upgrade.

  • Drop MaxRequestsPerChild and KeepAliveMaxRequests - The more requests an Apache process serves, the more memory that process will use. Dropping both MaxRequestsPerChild and KeepAliveMaxRequests (if KeepAlive is on) will force Apache to kill off old processes and spawn new processes faster. MaxRequestsPerChild is specifically designed to combat memory leaks. Do not set either of these values to 0, as this will have the direct opposite result, allowing each process to server an unlimited number of requests.
  • Drop MinSpareServers and MaxSpareServers - While the amount of resources the idle servers use is generally negilible, if these values are high, dropping these values could have a profound effect. Note: this will only help if the server is running Prefork.
  • Drop MinSpareThreads and MaxSpareThreads - Like the above, but on a server with Worker installed
  • If ServerLimit is set, make sure it is not drastically higher than MaxClients - If ServerLimit is higher MaxClients, Apache will be allocated extra shared memory that will go unused. Dropping ServerLimit to be in line with MaxClients (or MaxClients divided by ThreadsPerChild in Worker's case) will help prevent a memory leak.
  • If ThreadLimit is set, make sure it is not drastically higher than ThreadsPerChild - Just like with ServerLimit, if ThreadLimit is higher than ThreadsPerChild, Apache will be allocated extra shared memory that will go unused. Making sure that ThreadLimit and ThreadsPerChild are in line will help eliminate a potential memory leak.
  • Comment out RLimitMEM and RLimitCPU - A Cpanel script adds these to the httpd.conf, and it usually does a poor job of determining values for these directives (commonly setting them to the exact amount of RAM and CPU in the server). Commenting these values out may help with the situation.
  • Recompiling Apache with Worker - Since worker generally uses less RAM than prefork, compiling Worker into Apache could have a positive effect, especially on servers with lots of traffic.

Starting Points

IF YOU MAKE ANY CHANGES TO THE .CONF FILE YOU MUST DISTILL & rebuild:

/usr/local/cpanel/bin/apache_conf_distiller --update
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart 

Edit /usr/local/apache/conf/httpd.conf and you will see these as the default settings on any CPanel fresh install of either Apache 1.3 or Apache2 with Prefork.

Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
MinSpareServers 5
MaxSpareServers 10
StartServers 5
MaxClients 150
MaxRequestsPerChild 0

Template:Warning

These are general guidelines. For any server with 1GB RAM or less, you may want to start with the VPS specs above, and then increase slowly (a day or 2 later) if its handling it. Increase values and turn KeepAlive On/Off as necessary.

Also, to ensure that you are optimizing correctly, please run the following command to determine what MPM is currently installed.

/usr/local/apache/bin/httpd -V | grep -i mpm

On Core-Managed and Plesk boxes, the command is as follows:

/usr/sbin/httpd -V | grep -i mpm

Output of the command will look like this

root@plastic [~]# /usr/local/apache/bin/httpd -V | grep -i mpm
Server MPM:     event

Apache 1.3 will not return any value for this command.

Note: On CPanel servers: When modifying optimizations for Apache directly from the httpd.conf file, you will also want to modify the ops in the /var/cpanel/conf/apache/local file. Ops will have to be set at least once through WHM before that file will be there.

IF YOU MAKE ANY CHANGES TO THE .CONF FILE YOU MUST DISTILL and Rebuild:

/usr/local/cpanel/bin/apache_conf_distiller --update
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart

cPanel overwriting MPM Worker/Event optimizations

When setting optimizations within WHM, keep in mind that Prefork is the only MPM that WHM sets configurations for properly. WHM sets Serverlimit == MaxClients. In order to get Event and Worker optimizations in place, you should put them within pre_virtualhost_global.conf. I'd recommend running an "httpd status" to get Apache's scoreboard BEFORE setting them, and then again after a STOP and a START of Apache (Apache doesn't update ServerLimit or MaxClients with a graceful restart) After a stop and start, confirm that Apache's scoreboard is looking better. If it had Prefork opts before, it's height was likely quite large.. after properly setting opts, it should be quite a bit smaller unless it's a beefy server.

 /usr/local/apache/conf/includes/pre_virtualhost_global.conf

For VPS, Vservers, and very old hardware

KeepAlive On
MaxKeepAliveRequests 50
KeepAliveTimeout 5
<IfModule prefork.c>
    MinSpareServers 3
    MaxSpareServers 6
    StartServers 3
    MaxClients 30
    MaxRequestsPerChild 300
</IfModule>
<IfModule worker.c>
    ServerLimit 2
    StartServers 1
    MinSpareThreads 25
    MaxSpareThreads 75
    ThreadsPerChild 25
    MaxClients 50
    MaxRequestsPerChild 400
</IfModule>
Timeout 30

For Storm and Dedicated Servers with 1G of RAM

Timeout 50
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

<IfModule mod_fcgid.c>
    FcgidMaxRequestLen 1073741824
    FcgidMinProcessesPerClass 0
    FcgidMaxProcesses 20
    FcgidIOTimeout 60
    FcgidIdleTimeout 3
    FcgidProcessLifeTime 30
    FcgidIdleScanInterval 10
    FcgidErrorScanInterval 10
    FcgidZombieScanInterval 10
    FcgidSpawnScoreUpLimit 7000
    FcgidSpawnScore 1
    FcgidTerminationScore -1
    FcgidTimeScore 3
</IfModule>

<IfModule prefork.c>
    StartServers 5
    ServerLimit 50
    MinSpareServers 5
    MaxSpareServers 10
    MaxClients 50
    MaxRequestsPerChild 400
</IfModule>

<IfModule worker.c>
    ServerLimit 2
    StartServers 1
    MinSpareThreads 25
    MaxSpareThreads 50
    ThreadsPerChild 25
    MaxClients 50
    MaxRequestsPerChild 400
</IfModule>

<IfModule event.c>
    ServerLimit 2
    StartServers 1
    MinSpareThreads 25
    MaxSpareThreads 50
    ThreadsPerChild 25
    MaxRequestWorkers 25
    MaxRequestsPerChild 0
    GracefulShutdownTimeout 5
</IfModule>

For Storm and Dedicated Servers with 2G of RAM

KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
<IfModule prefork.c>
    StartServers 5
    ServerLimit 75
    MinSpareServers 5
    MaxSpareServers 10
    MaxClients 75
    MaxRequestsPerChild 600
</IfModule>
<IfModule worker.c>
    ServerLimit 3
    StartServers 2
    MinSpareThreads 25
    MaxSpareThreads 75
    ThreadsPerChild 25
    MaxClients 75
    MaxRequestsPerChild 600
</IfModule>
<IfModule event.c>
    ServerLimit 2
    StartServers 1
    MinSpareThreads 25
    MaxSpareThreads 75
    ThreadsPerChild 25
    MaxRequestWorkers 50
    MaxRequestsPerChild 0
    GracefulShutdownTimeout 5
</IfModule>
Timeout 50

For Storm and Dedicated Servers with 3G of RAM

KeepAlive On
MaxKeepAliveRequests 150
KeepAliveTimeout 5
<IfModule prefork.c>
    StartServers 10
    ServerLimit 75
    MinSpareServers 10
    MaxSpareServers 20
    MaxClients 75
    MaxRequestsPerChild 600
</IfModule>
<IfModule worker.c>
    ServerLimit 3
    StartServers 2
    MinSpareThreads 25
    MaxSpareThreads 75
    ThreadsPerChild 25
    MaxClients 75
    MaxRequestsPerChild 600
</IfModule>
<IfModule event.c>
    ServerLimit 3
    StartServers 2
    MinSpareThreads 25
    MaxSpareThreads 75
    ThreadsPerChild 25
    MaxRequestWorkers 75
    MaxRequestsPerChild 0
    GracefulShutdownTimeout 5
</IfModule>
Timeout 50

For Storm and Dedicated Servers with between 4G and 6G of RAM

KeepAlive Off
MaxKeepAliveRequests 150
KeepAliveTimeout 5
<IfModule prefork.c>
    StartServers 10
    ServerLimit 100
    MinSpareServers 10
    MaxSpareServers 20
    MaxClients 100
    MaxRequestsPerChild 800
</IfModule>
<IfModule worker.c>
    ServerLimit 4
    StartServers 2
    MinSpareThreads 25
    MaxSpareThreads 75
    ThreadsPerChild 25
    MaxClients 100
    MaxRequestsPerChild 800
</IfModule>
<IfModule event.c>
    ServerLimit 4
    StartServers 2
    MinSpareThreads 25
    MaxSpareThreads 100
    ThreadsPerChild 25
    MaxRequestWorkers 100
    MaxRequestsPerChild 0
    GracefulShutdownTimeout 5
</IfModule>
Timeout 50

For Storm and Dedicated Servers with between 7G and 9G of RAM

KeepAlive Off
MaxKeepAliveRequests 200
KeepAliveTimeout 5
<IfModule prefork.c>
    StartServers 20
    ServerLimit 125
    MinSpareServers 20
    MaxSpareServers 40
    MaxClients 125
    MaxRequestsPerChild 1000
</IfModule>
<IfModule worker.c>
    ServerLimit 5
    StartServers 3
    MinSpareThreads 25
    MaxSpareThreads 125
    ThreadsPerChild 25
    MaxClients 125
    MaxRequestsPerChild 1000
</IfModule>
<IfModule event.c>
    ServerLimit 5
    StartServers 2
    MinSpareThreads 25
    MaxSpareThreads 125
    ThreadsPerChild 25
    MaxRequestWorkers 125
    MaxRequestsPerChild 0
    GracefulShutdownTimeout 5
</IfModule>
Timeout 60

For Storm and Dedicated Server with between 10G and 16G of RAM

KeepAlive Off
MaxKeepAliveRequests 150
KeepAliveTimeout 5
<IfModule prefork.c>
    StartServers 20
    MinSpareServers 20
    MaxSpareServers 40
    ServerLimit 400
    MaxClients 400
    MaxRequestsPerChild 1000
</IfModule>
<IfModule worker.c>
    ServerLimit 16
    StartServers 5
    MinSpareThreads 25
    MaxSpareThreads 125
    ThreadsPerChild 25
    MaxClients 400
    MaxRequestsPerChild 1000
</IfModule>
<IfModule event.c>
    ServerLimit 16
    StartServers 5
    MinSpareThreads 25
    MaxSpareThreads 225
    ThreadsPerChild 25
    MaxRequestWorkers 250
    MaxRequestsPerChild 0
    GracefulShutdownTimeout 5
</IfModule>
Timeout 300

For Storm and Dedicated Server with between 16G and 32G of RAM

KeepAlive Off
MaxKeepAliveRequests 150
KeepAliveTimeout 5
Timeout 300

<IfModule prefork.c>
    StartServers 20
    MinSpareServers 20
    MaxSpareServers 40
    ServerLimit 450
    MaxClients 450
    MaxRequestsPerChild 1000
</IfModule>

<IfModule worker.c>
    ServerLimit 18
    StartServers 8
    MinSpareThreads 25
    MaxSpareThreads 450
    ThreadsPerChild 25
    MaxClients 450
    MaxRequestsPerChild 1000
</IfModule>

<IfModule event.c>
    ServerLimit 18
    StartServers 8
    MinSpareThreads 25
    MaxSpareThreads 300
    ThreadsPerChild 25
    MaxRequestWorkers 300
    MaxRequestsPerChild 0
    GracefulShutdownTimeout 5
</IfModule>

<IfModule mod_fcgid.c>
FcgidMaxRequestLen                      1073741824
FcgidOutputBufferSize                   1073741824
FcgidMinProcessesPerClass               0
FcgidMaxRequestsPerProcess              0
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS   0
FcgidInitialEnv PHP_FCGI_CHILDREN       0
FcgidMaxProcesses                       320
FcgidMaxProcessesPerClass               160
FcgidFixPathinfo                        1
FcgidIdleTimeout                        3
FcgidBusyTimeout                        300
FcgidProcessLifeTime                    300
FcgidIOTimeout                          300
FcgidIdleScanInterval                   1
FcgidErrorScanInterval                  1
FcgidZombieScanInterval                 1
</IfModule>

For Storm and Dedicated Server with between 32G and 48G of RAM

KeepAlive Off
MaxKeepAliveRequests 150
KeepAliveTimeout 5
<IfModule prefork.c>
    StartServers 20
    MinSpareServers 20
    MaxSpareServers 40
    ServerLimit 550
    MaxClients 550
    MaxRequestsPerChild 1000
</IfModule>
<IfModule worker.c>
    ServerLimit 22
    StartServers 10
    MinSpareThreads 25
    MaxSpareThreads 550
    ThreadsPerChild 25
    MaxClients 550
    MaxRequestsPerChild 1000
</IfModule>
<IfModule event.c>
    ServerLimit 22
    StartServers 10
    MinSpareThreads 25
    MaxSpareThreads 250
    ThreadsPerChild 25
    MaxRequestWorkers 450
    MaxRequestsPerChild 0
    GracefulShutdownTimeout 5
</IfModule>
Timeout 300

For Storm and Dedicated Server with more than 48G of RAM

KeepAlive Off
MaxKeepAliveRequests 150
KeepAliveTimeout 5
<IfModule prefork.c>
    StartServers 20
    MinSpareServers 20
    MaxSpareServers 40
    ServerLimit 750
    MaxClients 750
    MaxRequestsPerChild 1000
</IfModule>
<IfModule worker.c>
    ServerLimit 30
    StartServers 15
    MinSpareThreads 25
    MaxSpareThreads 750
    ThreadsPerChild 25
    MaxClients 750
    MaxRequestsPerChild 1000
</IfModule>
<IfModule event.c>
    ServerLimit 30
    StartServers 15
    MinSpareThreads 25
    MaxSpareThreads 750
    ThreadsPerChild 25
    MaxRequestWorkers 750
    MaxRequestsPerChild 0
    GracefulShutdownTimeout 5
</IfModule>
Timeout 300

For Worker one thing to note: ServerLimit is a hard limit on the number of active child processes, and must be greater than or equal to the MaxClients directive divided by the ThreadsPerChild directive. So, if you put MaxClients 500, and have ThreadsPerChild 25, ServerLimit must be set to 20 or greater. If its less, Apache will take ServerLimit x ThreadsPerChild and that will be what MaxClients is set to at runtime (in this example it would end up being 400). However, its OK to set MaxClients lower than the value of ServerLimit x ThreadsPerChild, similar to below:

ServerLimit = MaxClients / ThreadsPerChild

MaxClients = ServerLimit x ThreadsPerChild

Template:Warning

PHP Opcode Caching

Opcode cachers are great for speeding up PHP based sites. Memory is loaded into bytecode form and shared between threads and processes. It can give a good reduction in load and CPU usage to a site that isn't using one. By their nature, they will only work in an environment running some kind of persistent PHP instance such as DSO (with Prefork recommended) or FCGI (with Worker recommended). None will work effectively with suPHP due to the shared memory limitations of suPHP. Additionally, none directly require an EasyApache in order to be installed.

eAccelerator

https://wiki.int.example.com/articles/EAccelerator

Xcache

https://wiki.int.example.com/articles/XCache

APC (Alternative PHP Cache)

https://wiki.int.example.com/articles/APC