Optimizing Apache Memory Usage using mpm prefork

in #apache3 years ago (edited)

Apache mpm prefork Overview

This guide goes over optimizing apache memory usage by configuring mpm prefork module to the best values for your server. Afterword, you should notice substantial increases in performance especially if you are using free micro instances from Google Cloud or AWS.

Commands used:

  • Check Apache Memory usage
    • ps -ylC apache2 --sort:rss | awk '{sum+=$8; ++n} END {print "Tot="sum"("n")";print "Avg="sum"/"n"="sum/n/1024"MB"}' Note: My result was between 68-71 MB with stock modules loaded, however, your results will vary.
  • Launch Memory manager/resource viewer
    • 'htop' OR you can use 'top' for fewer options and visuals

Values to calculate:

Total System Memory Free - Buffer / Apache2 MB usage = MaxRequestWorkers, ServerLimit, and MaxClients

My Settings: Server Instance (Standard) 1 dedicated vCPU with 3.5 GB of Memory

Please note that the below settings is done from a stock apache configuration. With all things considered these values are very conservative and therefore can be used if you are hosting with these specs or greater. In future articles I'll go through disabling un-needed modules to reduce apache's footprint, thus allowing you to increase these numbers.

# 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

MaxRequestWorkers: maximum number of server processes allowed to start

MaxConnectionsPerChild: maximum number of requests a server process serves

StartServers 3
MinSpareServers 5
MaxSpareServers 10
ServerLimit 45
MaxClients 45
MaxRequestWorkers 45
MaxConnectionsPerChild 2000

45 processes x 68 MB per = 3060 MB Free Memory needed for the above configuration
Comparatively, a microserver with 600-700 MB of ram and shared CPU you will be looking at 1-3 Start/Min/Max Start and Spare servers, and no more than 10 for ServerLimit/MaxClients/MaxRequestWorkers. There are other modifications you need to make in culling down apache modules, therefore you can increase these values further.

Video Walkthrough

Leave any Questions and Comments below and I will get back to you. I regularly publish on YouTube, Steemit, and christitus.com so if you’d like to see more videos and articles click the subscribe button.

Posted from my blog with SteemPress : https://www.christitus.com/2018/09/26/apache-mpm-prefork/

Coin Marketplace

STEEM 0.62
TRX 0.10
JST 0.075
BTC 56868.17
ETH 4584.42
BNB 621.05
SBD 7.13