Digital Marketing has never been on the rise as much as during lockdown. All...
Let’s harness the power of precious CPU with Apache!
We are going to discuss PHP MPM Worker which gives a big performance boost to the user requests while doing the scaling. It is gold when it comes to supporting huge web traffic. We will dig into Apache MPM performance side !
Apache MPM prefork and Apache MPM worker
Apache has two types of MPM
How to know whether it is Apache MPM prefork or Apache MPM Worker
Use Following command (It will show Server MPM type)
Server version: Apache/2.4.43 (cPanel) Server built: May 5 2020 18:56:17 Server's Module Magic Number: 20120211:92 Server loaded: APR 1.7.0, APR-UTIL 1.6.1 Compiled using: APR 1.7.0, APR-UTIL 1.6.1 Architecture: 64-bit Server MPM: worker threaded: yes (fixed thread count) forked: yes (variable process count)
or dump the loaded module
httpd -t -D DUMP_MODULES | grep mpm mpm_worker_module (shared) //if loaded module shows worker then it is MPM worker type
Prefork VS Worker
We will do a quick summary of apache MPM prefork, it implements non threaded and preforking web server. Apache maintains a directive named MaxRequestWorkers in its configuration which defines the Maximum number of connections that will be processed simultaneously. We suggest to choose this value based on RAM size.
Apache httpd always tries to maintain several spare or idle server processes, which stand ready to serve incoming requests. In this way, clients do not need to wait for a new child processes to be forked before their requests can be served.
Let’s discuss how exactly Apache MPM prefork uses few directives to process the requests. Following directives are used to control the request. These are configurable, I am keeping some default values to explain.
StartServers: 5 //Apache starts 5 child processes at the moment it gets started MinSpareServers: 5 //Apache keeps minimum of 5 idle child processes MaxSpareServers: 10 //Apache keeps maximum of 10 idle child processes
MaxRequestWorkers: 256 //Maximum number of connections that will be processed simultaneously.
//It sets the upper limit on configurable number of processes. With the prefork MPM, use this directive only if you need to set MaxRequestWorkers higher than 256 (default).
Do not Miss the Gold : Why I Suggest to Use Apache MPM Worker !
There is difference in meaning of few directives when Apache MPM worker is in use.
//Only use if MaxRequestWorkers and ThreadsPerChild needs more than 16(default) server processes. Do not set the value of this directive any higher than the number of server processes required by what you may want for MaxRequestWorkers and ThreadsPerChild.
//restricts the total number of threads that will be available to serve clients.
MaxRequestWorkers an integer multiple of ThreadsPerChild (default 25) and ServerLimit (16).
ThreadsPerChild : 25 //no of threads per child
You can compare serverlimit with no of cores, so lets say your CPU has 4 cores then Ideally you should set serverlimit as 4.
You may try to set serverlimit as 8 if 4 core supports hyper threading(Meaning CPU is 4 core/8 threads)
Try above combinations and share your experience in comment section. Apache MPM Worker makes use of precious CPU better than prefork.
Author: Rajnish K
About Author :
Rajnishk is R&D Expert ,passionate for Web Stack & an Entrepreneur . He can be reached at email@example.com