Read Complete Post From Source: BLog.CripperZ.SG
apache best mpm for php
Good Apache MPM Settings for Low End VPS / Servers – 1GB Memory / 1GB Swap
Apache uses a set of values called the Prefork MPM to determine how many servers it will utilize and how many threads each server can process. Out of the box all Apache installations use the same values regardless of whether your server has 512Mb of RAM or 8Gb of RAM. It is important that as the server administrator you configure these values to work with your server load.
The Apache Prefork MPM can be found in the Apache configuration file; usually /etc/httpd/conf/httpd.conf. The default values are…
<IfModule prefork.c>
StartServers 2
MinSpareServers 3
MaxSpareServers 3
ServerLimit 75
MaxClients 75
MaxRequestsPerChild 1000
</IfModule>
Each Directive taken from “http://httpd.apache.org/docs/trunk/mod/mpm_common.html” is detailed below.
- – – – – – – – – – – -
The StartServers directive sets the number of child server processes created on startup. As the number of processes is dynamically controlled depending on the load there is usually little reason to adjust this parameter.
- – – – – – – – – – – -
The MinSpareServers directive sets the desired minimum number of idle child server processes. An idle process is one which is not handling a request. If there are fewer than MinSpareServers idle then the parent process creates new children until satisfies the MinSpareServers setting.
- – – – – – – – – – – -
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.
- – – – – – – – – – – -
The ServerLimit directive is only used if you need to set MaxClients higher than 256 (default). Do not set the value of this directive any higher than what you might want to set MaxClients to.
- – – – – – – – – – – -
The MaxClients directive sets the limit on the number of simultaneous requests that will be served. Any connection attempts over the MaxClients limit will normally be queued, up to a number based on the ListenBacklog directive. Once a child process is freed at the end of a different request, the connection will then be serviced.
For non-threaded servers (i.e., prefork), MaxClients translates into the maximum number of child processes that will be launched to serve requests. The default value is 256; to increase it, you must also raise ServerLimit.
- – – – – – – – – – – -
The MaxConnectionsPerChild directive sets the limit on the number of connections that an individual child server process will handle. After MaxConnectionsPerChild connections, the child process will die. If MaxConnectionsPerChild is 0, then the process will never expire.
Setting MaxConnectionsPerChild to a non-zero value limits the amount of memory that process can consume by (accidental) memory leakage.
- – – – – – – – – – – -
The single most important directive is MaxClients as this determines the amount of Apache child processes that will be launched to server requests. A simple calculation for MaxClients would be:
(Total Memory – Critical Services Memory) / Size Per Apache process
I define Critical Services as services such as mySQL, Plesk, Cpanel; any service that is required for proper operation of your server.
I’ve used the following commands via shell to determine values for Total Memory, OS Memory, MySQL Memory, and Apache Process Size
TOTAL MEMORY
[root@vps httpd]# free -m
total used free shared buffers cached
Mem: 1002 599 402 0 28 337
-/+ buffers/cache: 233 769
Swap: 2047 124 1922
MYSQL MEMORY
[root@vps httpd]# ps aux | grep ‘mysql’ | awk ‘print $6’
408
21440
704
APACHE PROCESS SIZE
[root@vps httpd]# ps aux | grep ‘httpd’ | awk ‘print $6’
22468
11552
41492
40868
41120
41696
39488
41704
15552
16076
16084
728
In this case the server has 1002Mb of memory allocated, xx used by the OS itself, 21Mb used by mySQL, and each Apache thread averages about 30Mb.
MaxClients = (1002 – 21) / 30 therefore MaxClients = 32.7
The next important aspect is MaxConnectionsPerChild as this is the amount of threads that will be processed before the child is recycled.
A good calculation for MaxConnectionsPerChild would be:
(total amount of daily requests / total number of daily processes)
Determining these values is a bit more complex as it requires some type of statistics package or thorough knowledge of interpreting Apache access logs.
As this does not adversely effect memory usage, only cpu time to cycle the process if you are unable to determine this information the standard 1000 should be used.
Thus a good configuration for this server would be
<IfModule prefork.c>
StartServers 2
MinSpareServers 3
MaxSpareServers 3
ServerLimit 30
MaxClients 30
MaxRequestsPerChild 1000
</IfModule>
Be sure once you’ve saved the file to perform a configuration test before restarting Apache.
[root@vps httpd]# service httpd configtest
Syntax OK
[root@vps httpd]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd:
On another note, on my Xen VPS running Directadmin / Ubuntu 10.04 64bit LTS with 1GB allocated memory, 2GB swap, i can comfortably run this config set on my /etc/httpd/conf/extra/httpd-mpm.conf
# # # Server-Pool Management (MPM specific) # # # PidFile: The file in which the server should record its process # identification number when it starts. # # Note that this is the default PidFile for most MPMs. # <IfModule !mpm_netware_module> PidFile "/var/run/httpd.pid" </IfModule> # # The accept serialization lock file MUST BE STORED ON A LOCAL DISK. # <IfModule !mpm_winnt_module> <IfModule !mpm_netware_module> #LockFile /var/log/httpd/accept.lock </IfModule> </IfModule> # # Only one of the below sections will be relevant on your # installed httpd. Use "apachectl -l" to find out the # active mpm. # # 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 # MaxClients: maximum number of server processes allowed to start # MaxRequestsPerChild: maximum number of requests a server process serves #<IfModule mpm_prefork_module> # StartServers 5 # MinSpareServers 5 # MaxSpareServers 20 # ServerLimit 200 # MaxClients 200 # MaxRequestsPerChild 1000 #</IfModule> <IfModule prefork.c> StartServers 2 MinSpareServers 3 MaxSpareServers 3 ServerLimit 10 MaxClients 10 MaxRequestsPerChild 100 </IfModule> # worker MPM # StartServers: initial number of server processes to start # MaxClients: maximum number of simultaneous client connections # MinSpareThreads: minimum number of worker threads which are kept spare # MaxSpareThreads: maximum number of worker threads which are kept spare # ThreadsPerChild: constant number of worker threads in each server process # MaxRequestsPerChild: maximum number of requests a server process serves <IfModule mpm_worker_module> StartServers 2 ServerLimit 20 MaxClients 20 MinSpareThreads 3 MaxSpareThreads 3 ThreadsPerChild 3 MaxRequestsPerChild 1000 </IfModule> # BeOS MPM # StartThreads: how many threads do we initially spawn? # MaxClients: max number of threads we can have (1 thread == 1 client) # MaxRequestsPerThread: maximum number of requests each thread will process <IfModule mpm_beos_module> StartThreads 1 MaxClients 5 MaxRequestsPerThread 100 </IfModule> # NetWare MPM # ThreadStackSize: Stack size allocated for each worker thread # StartThreads: Number of worker threads launched at server startup # MinSpareThreads: Minimum number of idle threads, to handle request spikes # MaxSpareThreads: Maximum number of idle threads # MaxThreads: Maximum number of worker threads alive at the same time # MaxRequestsPerChild: Maximum number of requests a thread serves. It is # recommended that the default value of 0 be set for this # directive on NetWare. This will allow the thread to # continue to service requests indefinitely. <IfModule mpm_netware_module> ThreadStackSize 65536 StartThreads 3 MinSpareThreads 2 MaxSpareThreads 5 MaxThreads 10 MaxRequestsPerChild 1000 MaxMemFree 100 </IfModule> # OS/2 MPM # StartServers: Number of server processes to maintain # MinSpareThreads: Minimum number of idle threads per process, # to handle request spikes # MaxSpareThreads: Maximum number of idle threads per process # MaxRequestsPerChild: Maximum number of connections per server process # MaxRequestsPerChild: Maximum number of requests a thread serves. It is # recommended that the default value of 0 be set for this # directive on NetWare. This will allow the thread to # continue to service requests indefinitely. <IfModule mpm_netware_module> ThreadStackSize 65536 StartThreads 3 MinSpareThreads 2 MaxSpareThreads 5 MaxThreads 10 MaxRequestsPerChild 1000 MaxMemFree 100 </IfModule> # OS/2 MPM # StartServers: Number of server processes to maintain # MinSpareThreads: Minimum number of idle threads per process, # to handle request spikes # MaxSpareThreads: Maximum number of idle threads per process # MaxRequestsPerChild: Maximum number of connections per server process <IfModule mpm_mpmt_os2_module> StartServers 2 MinSpareThreads 5 MaxSpareThreads 10 MaxRequestsPerChild 1000 </IfModule> |
*** Update 10 October 2013 ***
I have made further tweaks to my Xen virtual server which has 2 cpu cores, 1GB ram allocated / 2GB swap with 40G hard disk space. It appears that the tweaks i made helps to improve the stability of the server running Directadmin hosting my wordpress websites and able to handle more than 100 visitors at any given point of time without freezing like the previous settings i have. Have a look at the Apache and Mysql settings respectively to help improve your settings. See the respective link and configurations below.
Tuning Your Mysql Settings / Conf
Tuning Your Apache Settings / Conf
# # Server-Pool Management (MPM specific) # # # PidFile: The file in which the server should record its process # identification number when it starts. # # Note that this is the default PidFile for most MPMs. # PidFile "/var/run/httpd.pid" # # The accept serialization lock file MUST BE STORED ON A LOCAL DISK. # #LockFile /var/log/httpd/accept.lock # # Only one of the below sections will be relevant on your # installed httpd. Use "apachectl -l" to find out the # active mpm. # # 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 # MaxClients: maximum number of server processes allowed to start # MaxRequestsPerChild: maximum number of requests a server process serves # # StartServers 5 # MinSpareServers 5 # MaxSpareServers 20 # ServerLimit 200 # MaxClients 200 # MaxRequestsPerChild 1000 # StartServers 1 MinSpareServers 3 MaxSpareServers 5 ServerLimit 10 MaxClients 10 MaxRequestsPerChild 0 # worker MPM # StartServers: initial number of server processes to start # MaxClients: maximum number of simultaneous client connections # MinSpareThreads: minimum number of worker threads which are kept spare # MaxSpareThreads: maximum number of worker threads which are kept spare # ThreadsPerChild: constant number of worker threads in each server process # MaxRequestsPerChild: maximum number of requests a server process serves StartServers 2 ServerLimit 20 MaxClients 20 MinSpareThreads 3 MaxSpareThreads 3 ThreadsPerChild 3 MaxRequestsPerChild 1000 # BeOS MPM # StartThreads: how many threads do we initially spawn? # MaxClients: max number of threads we can have (1 thread == 1 client) # MaxRequestsPerThread: maximum number of requests each thread will process StartThreads 1 MaxClients 5 MaxRequestsPerThread 100 # NetWare MPM # ThreadStackSize: Stack size allocated for each worker thread # StartThreads: Number of worker threads launched at server startup # MinSpareThreads: Minimum number of idle threads, to handle request spikes # MaxSpareThreads: Maximum number of idle threads # MaxThreads: Maximum number of worker threads alive at the same time # MaxRequestsPerChild: Maximum number of requests a thread serves. It is # recommended that the default value of 0 be set for this # directive on NetWare. This will allow the thread to # continue to service requests indefinitely. ThreadStackSize 65536 StartThreads 3 MinSpareThreads 2 MaxSpareThreads 5 MaxThreads 10 MaxRequestsPerChild 1000 MaxMemFree 100 # OS/2 MPM # StartServers: Number of server processes to maintain # MinSpareThreads: Minimum number of idle threads per process, # to handle request spikes # MaxSpareThreads: Maximum number of idle threads per process # MaxRequestsPerChild: Maximum number of connections per server process # MaxRequestsPerChild: Maximum number of requests a thread serves. It is # recommended that the default value of 0 be set for this # directive on NetWare. This will allow the thread to # continue to service requests indefinitely. ThreadStackSize 65536 StartThreads 3 MinSpareThreads 2 MaxSpareThreads 5 MaxThreads 10 MaxRequestsPerChild 1000 MaxMemFree 100 # OS/2 MPM # StartServers: Number of server processes to maintain # MinSpareThreads: Minimum number of idle threads per process, # to handle request spikes # MaxSpareThreads: Maximum number of idle threads per process # MaxRequestsPerChild: Maximum number of connections per server process StartServers 2 MinSpareThreads 5 MaxSpareThreads 10 MaxRequestsPerChild 1000 |
Good Apache best mpm For PhpRead Complete Post From Source:
BLog.CripperZ.SG
0 comments:
Post a Comment