I know that question is little long but i choosed to describe each and every aspect which i observed from my end.

I am using a Linux server, OS used is Ubuntu 14.04, all rest configurations are defined below. This Web server is used for serving application built up in PHP, Databse is hosted over RDS. On an average at peak times there are nearly 200 concurrent requests on server, which ends up in 100% memory utilization. Due to this application becomes very slow or sometimes responds back with error. So i followed some steps to get this resolved, which i have listed below, and tried to tune apache and restrict it for odd situations.


NAME="Ubuntu" VERSION="14.04.5 LTS

Server Configuration

CPU: 8 Cores
RAM: 15 GB
Hardware Provider: AWS
Instance Type: c4.2xlarge

Apache.Conf Parameters (2.4)

Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
HostnameLookups Off
LogLevel warn
AllowOverride all (for document root of application)

MPM USED: prefork


StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 256
MaxConnectionsPerChild 200


access_compat.load autoindex.load mime.load setenvif.load alias.conf deflate.conf mpm_prefork.conf socache_shmcb.load alias.load deflate.load mpm_prefork.load ssl.conf authn_core.load dir.conf negotiation.conf ssl.load authn_file.load dir.load negotiation.load status.conf authz_core.load env.load php5.conf status.load authz_host.load filter.load php5.load authz_user.load headers.load rewrite.load autoindex.conf mime.conf setenvif.conf

Average Apache process size

Command used:

sudo ps -ylC apache2 | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Process Size (MB): "x/((y-1)*1024)}' <br/>

Apache Memory Usage (MB): 7227.66
Average Process Size (MB): 314.246

Calculation of MaxRequestWorkers

X = Dedicated RAM which i want to allocate to Apache (13GB): 13312 MB
Y = Average Process size which i am monitoring from last 15 days over server: 314.246
MaxRequestWorkers = X/Y = 40 approx

MPM USED: prefork


StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 40
MaxConnectionsPerChild 8

Now when apache starts, it will start 5 startservers process and each startserver process will start 8 child connections so in total 40 concurrent connections can be made to the server. MaxRequestWorkers are limited to 40, which will not go beyond 40 concurrent requests, Which will prevent in case of DOS, DDOS or protect server from getting halt by occupying maximum ram of 13GB, leaving 2GB RAM free for server.
I am also not clear about MaxConnectionsPerChild parameter, please make me correct if i am using this wrong.

PHP.INI Parametrs (php5)

output_buffering = 4096
max_execution_time = 60
memory_limit = -1
log_errors = On

output_buffering = 4096
max_execution_time = 60
memory_limit = 64M
log_errors = On


After changing the mpm_prefork_conf memory utilization came down but server responds back with 503 error to many clients due to MaxRequestWorkers parameter. I tried to figure out why my each apache process is using 315MB of RAM, i googled around 2 days and was not able to find the right path to further troubleshoot this. So finally i posted this over here. I have two options now.

  1. To optimize the apache average process limit and increase the MaxRequestWorkers limit.

  2. To increase RAM and serve clients with same average process size, which i think would not be a right choice.

Kindly guide me with the right suggestions how can i identify and reduce the average process size of apache with php. Please genuine answers only.

2 Answers 2


I don't think you can get much better than this, I'd take the route to use php-fpm, then the non dynamic content load will be much faster and less memory consuming, I've found this guide (digitalocean.com), that gives good recommendations. A thing you could check out is to change the keepalive times in apache see here

  • I am looking for any ideas to reduce average process size by apache which is 314MB right now? Jan 19, 2017 at 13:29
  • I've no ideas on that, I'm sorry
    – aseques
    Jan 19, 2017 at 14:11
  • The process won't run as per the memory limit given; the limit means that if the process is requesting more RAM, Apache should not allow it. What you should be looking at is why and where is it requesting that much RAM and change the code. e.g. if you are loading too much data to memory (which is most probably the case) stop it. In nearly all scenarios that I've see, programmers code it so that the front-end specify the search criteria and the back-end loads all matching records. Instead, select only the column that are to be displayed, and, use server-side pagination Jul 7 at 12:22

That's quite a lot of memory per apache process. And Ubuntu 14.0.4 was EOL in 2019.

The screaming thing in the config you posted is this:

KeepAliveTimeout 5

Change that to 1. You'll find that at least half your active processes are currently doing nothing waiting for the keepalive timeout.

Start analyzing your traffic - make sure all your static content is cacheable.

Go through your apache config - make sure you're not loading modules you are not using.

Make sure you've set a default timeone for PHP and your scripts aren't disabling error reporting. Check your error logs and clean up the errors. Try tweaking your listenBacklog in Apache.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .