0

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.

OS

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

MPM_PREFORK.CONF

StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 256
MaxConnectionsPerChild 200

Mods_Enabled

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

Modified MPM_PREFORK.CONF

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)

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

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

ISSUES WHICH ARE STILL FACED BY ME

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.

imvikasmunjal
  • 695
  • 7
  • 14

1 Answers1

0

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

aseques
  • 688
  • 4
  • 12
  • 26