Optimizing Apache for Better Performance and Reduce RAM Usage

Server performance and website speed is almost everything now, the recent revealed Google Panda ranking signals sheet also indicates that website speed is considered as the first preference in the rankings. Apache has great features and strong development and support base, but the problem with Apache is consuming of memory, it will suck the entire server RAM like anything, this will be really frustrating for any webmaster because upgrading the RAM on a VPS or dedicated server isn’t so cheap. I faced the similar problem with VPS account, I have 2GB of RAM, but Apache sucks almost 90% of my RAM memory.

So I decided to look in this and fix the issue once in for all, as some of you may aware that I am a RHCE and I am quite comfortable with Linux-based servers. I started digging in to deep of the issue by primarily exploring the cause of the issue, and as usual the problem is that Apache is simply reserving the RAM memory, which obviously resulting in to my VPS node going down, even dedicated servers can also get performance level issues. So it is better to fix this memory consuming issue ASAP to avoid future circumstances.

There are two possible solutions, one by tweaking Apache and reducing RAM usage. Second simply switch to Nginx, which consumes really a very low memory and the performance level is really astonishing compared to Apache. I did a lot of load testing etc and finally agree that Nginx is way better in terms of performance and handling multiple concurrent connections at a time. I will write a complete comparison report and review on Apache and Nginx in my next article.

Optimization Apache and Reduce RAM Usage

Optimizing Apache and Reducing RAM usage:

Apache has a special feature called Multi-Processing Module (MPMs), which helps it in handling the multiprocessing of threads, which obviously increase your server load by running spare servers unnecessarily, this will easily suck up all your RAM in no-time. I try many ways to reduce the RAM usage by disabling unused PHP modules, uninstalling the useless packages etc. But it barely reduced the usage, so I started to taking this issue a little serious (because my hosting provider keeps on sending me warnings about crossing the RAM usage limits).

So obviously as a primary step I start digging in to the HTTPD configuration and I find out about MPM, so I tweaked a few settings which dramatically reduced my RAM usage, also I didn’t see any performance issues with website as well. Let me explain you about what exactly I have did…

Note: Please apply these settings at your own risk, I do not hold any responsibility if something goes wrong, also don’t try this on a production server directly.

Steps to Optimize Apache:

1) Open your Apache configuration file which is normally located at..


2) Go to the below location where you can find this code..

<IfModule prefork.c>
StartServers       8
MinSpareServers    1
MaxSpareServers    10
ServerLimit        50
MaxClients        50
MaxRequestsPerChild  4000

For your understand here is what every term means..

# 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

3) Just reduce the number of server start to lower number, in my case I set it as “1”. Also set the minimum spare server value to “1”. Set Max Spare server value to 4 or 5, server limit to 50 or 60 (test with different values).

4) Just below to the prefork settings, you can see worker settings as well, worker can better your website performance if you optimize it correctly. It will look like this..

<IfModule worker.c>
StartServers       8
MaxClients        50
MinSpareThreads    5
MaxSpareThreads    4
ThreadsPerChild     25
MaxRequestsPerChild  0

You can actually change the values according to your convenient, also check out what those terms mean by…

# 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

5) This will almost do the job, but as I said work a little on your enabled modules which unnecessarily lying in your configuration and wasting the server resources. Please do check before you disable any module and what is its functionality first, then you can go ahead with the disabling.

6) Remove unnecessary packages lying in your servers which runs in background and sucks all your memory without your knowledge. Disable unnecessary background running processes as well.

7) Another simple way to optimize your website performance is by installing the mod_pagespeed module, this can also help in optimizing your website performance dramatically.

Please try experimenting with different values in prefork and worker configurations, just see which can improve your website performance and reduce the RAM usage as well.

I hope you enjoyed this article, you have any questions, suggestions and comments, please ask in the below section, also if you have any specific questions to ask, please ask us at our SEO Forum.

About Arafath Hashmi

Arafath Hashmi is a Blogger from 2007 and he wrote 700 and above articles for solvater.com, He is a Senior SEO Analyst.

Speak Your Mind