How To Optimize Apache For Better Performance/Load Management

Posted on November 20th, 2012

Posted By Rishabh Jain | Comments

Optimization of Apache Server is essential, if you want maximum from your website and want to grow your business rapidly. Well in this huge online market you are not alone with your products, there are thousands of other similar online business are standing beside you and can throw you out of competition if you are not taking the important steps which must be taken for a challenging competition in this competitive online world of business.

 

Everyone of us is familiar with Apache Server and its use and importance. So most important thing we are going to discuss in this article is How can you optimize your Apache server to enhance your website performance and can boost your traffic.

 

So there are some essential steps which must be followed in order to optimize your Apache Server for better performance and load management. so below i am going to explain all those steps which may help you to enhance your online experience.

 

Step 1 :- Disable Unnecessary Functions :

The first step you should be focused on is to disabling to functions that are no longer in use for you so just find such functions and disable them. This will bring the server load down and as a result your website will be optimized.

 

Step 2 :- Choose The Right Number Of Processes :

 

Each Apache process will consume a similar amount of memory on your server, depending on the Apache modules which are loaded and the tasks you’ll execute. So you have to choose a number of processes which matches your available memory. If there is 1GB of memory available – not at all but for Apache, your OS will use memory too and one of your Apache processes uses 20MB of memory, you can launch 50 processes equally. If you choose more, Apache will run in swap which results in huge memory issues. So there is need that you decide the right number of processes.

You can find out memory usage from the below command:

#ps -FA|grep apache2

To set the maximum number of processes launched open your Apache config (usually /etc/apache2/apache2.conf) and set MaxClients to the correct number.

 

Step 3 :- Disable Apache Modules :

 

Apache modules will use memory for each process that is launched and this is very expensive. The default Apache setup comes with more than 20 enabled modules which we did not need. You should disable everything that is not necessary for your site to run:

#a2dismod ruby 


#a2dismod include 

#a2dismod dav 

#a2dismod dav_fs 

Etc. You may disable other modules too which are no longer in use for you.

This will save you memory and allows you to launch more  processes without causing any problem.

 

 

Step 4 :- Reducing The KeepAliveTimeout :

 

If a client connects to your web server it will keep the connection open for a specific number of seconds for further requests. During this time, the whole Apache process is locked for other requests. You can specify the number of keep-alive seconds in your Apache config using the directive KeepAliveTimeout. You should enable KeepAlive but reduce KeepAlive to a value of 2-3 seconds. Default is 30 and you will notice that you can serve three times more visitors with the same server setup!

 

 

Step 5:- Optimize The MaxClients And MaxSpareThreads :

In case you have lots of  visitors on your website and you often face the resources full problem then you must apply this trick to optimize and increase the capacity in your apache configuration files.for example, today i will show you the commands you need to do to increase the MaxClients and MaxSpareThreads.

 

you have to made few changes to your httpd.conf file to optimize the MaxClients and MaxSpareThreads. before changing anything first create the backup of your file with the following command :-

 

cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak

 

once you have made a backup file, lets edit the httpd.conf file with this command:

 

nano /etc/httpd/conf/httpd.conf

 

once you are in nano, look for the word MaxClients
so search in nano, just hit Control+w enter the keyword and then hi enter then change to the following settings like below:

 

##
## Server-Pool Size Regulation (MPM specific)
##
# 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 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 300
MaxClients 300
MaxRequestsPerChild 4000
# 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 worker.c>
StartServers 2
MaxClients 300
MinSpareThreads 25
MaxSpareThreads 300
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
 

So you may change the above fields according to you also. After making the necessary changes just save this file and once you save this you will need to restart the Apache Server to make it work.

 
 

/etc/init.d/httpd restart

 

Step 6 :-  Enable Specific Modules :-

 

Enable the mod_status module (#a2enmod status) and enable ExtendedStatus directive (“ExtendedStatus On”) in /etc/apache2/mods-enabled/status.conf! Then have a look at /server-status which will tell you how many Apache processes are running and in which state (e.g. to find out if Keep-Alive is killing your setup) and which files are requested. Maybe you can find out which files to move to S3 storage using this technique.

 

So with these steps you would be able to optimize the Apache Server for better performance.



About Rishabh Jain - Hello, I am rishabh Jain CEO Of Eden Web inc.