There could be many reasons why your Apache web server is slow. One of them can be that Apache needs tuning. Tuning the Apache performance using the Apache MPM prefork module is one of them.
Tune Apache performance using MPM Prefork module
StartServers: 30% of MaxClients
MinSpareServers: 5% of MaxClients
MaxSpareServers: 10% of MaxClients
MaxRequestWorkers = MaxClients
MaxConnectionsPerChild= 10000 (To avoid problem with memory leaks in WordPress plugin themes and apps)
Edit the file with this command:
sudo nano /etc/apache2/mods-available/mpm_prefork.conf
Try these values if Apache uses 70 MB under heavy load and the server has 1 GB RAM.
<IfModule mpm_prefork_module> StartServers 8 MinSpareServers 8 MaxSpareServers 9 MaxRequestWorkers 9 MaxConnectionsPerChild 100 </IfModule>
Save the changes
Ctrl+X - Y
Restart Apache
sudo service apache2 restart
It might make the server a bit slower, but there will be the most available memory, and you will not hit the roof. Hitting the limit will almost stop the server.
How to calculate the values
The initial Ubuntu OS install uses 350 MB RAM – memory – and the server has 1 GB with memory.
Then there is half a gigabyte to run Apache clients.
You measure that each Apache instance uses 33 MB of memory. Then you would be able to run 18 servers with 650 MB available RAM. 650 MB RAM allows ten customers to download content from your site simultaneously. Often the browser uses several simultaneous instances so one user could use several Apache instances. Upgrade to 4 GB of RAM then you would have 3.5 GB available to serve your customers with Apache. 3,5 GB of available memory would suggest a “MaxClients” settings increased from ten clients to 106.
Tool nr 1 to help you determine a useful configuration
Check Apache Httpd MPM Config Limits
This Perl script compares the size of running Apache HTTP processes. This consist of the configured Prefork, worker and event MPM limits. Measured towards the server’s available memory. You might get an error message if the setting limits exceed the server’s available memory.
Check the website for the newest release.
https://code.google.com/archive/p/check-httpd-limits/downloads
Go to the user home folder
cd ~
Create a folder
mkdir apache-memory-test
Go to the newly created folder
cd apache-memory-test
Download the latest version. This is for version 2.5:
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/check-httpd-limits/check_httpd_limits-2.5.zip
Unzip the file
unzip check_httpd_limits-2.5.zip
Make the script executable:
chmod u+x check_httpd_limits.pl
Run the script as root
sudo ./check_httpd_limits.pl
Open a bunch of web pages while you run the script many times to get an impression of the average memory consumed.
Tool number 2
Please read this tutorial about oApache” performance using optimizing MPM Prefork module
Create a folder and download and unzip the script as you did with “Tool 1”
Make the script executable
chmod u+x ap.sh
Run the script
./ap.sh