• Home
  • WordPress
  • web Hosting
  • linux
  • mysql
  • nginx
  • apache2
  • devops

Raju Ginni

wordpress tutorials seo hosting etc

You are here: Home / apache server tutorial (install,config, performance tuning, security, error handling) / apache performance tuning mpm-worker vs prefork vs event modules

apache performance tuning mpm-worker vs prefork vs event modules

#1 understanding apache architecture

Selecting multiprocessing module based on application and traffic type.

Table of Contents

Toggle
  • #1 apache mpm worker module
  • apache mpm event worker module :
  • apache mpm-prefork module
    • MaxRequestWorkers / MaxClients
    • maxrequestsperchild/maxconnectionsperchild
    • check mpm module apache2 using
  • Disable unnecessary modules
    • Time-outs
    • keep alive
    • Increase Max Open Files
    • disable htaccess
    • Disable extended status in apache2.conf
    • optimize linux system
    • cpu intensive or memory intensive
  • use varnish nginx as reverse proxy and load balancer

#1 apache mpm worker module

: (multi threaded) multiple child processes,  each child with many threads.each thread handles one connection.
ServerLimit, (upper limit child processes)
default 16 child process.
ThreadsPerChild,  default 25
MaxRequestWorkers /serverlimit
sets limit for all threads , apache don’t spawn threads to handle new connections
error message maxclient reached.
serverlimit * threadsperchild = maxrequestworkers.
cpucores= serverlimit
2 cpu cores
2*64=128 worker connections per second.
4*32=128 worker connection/sec
threadsperchild 1 equals to mpm Prefork.
Minsparethreads (idle threads waiting to handle rather than spawning on new connection)
Maxsparethreads (50% of maxrequestworkers)
(Idle threads uses shared memory, make sure to know avg connections for server by monitoring)
thread limit 64 default

apache mpm event worker module :

same as worker, but assigns some connections to other threads to free up main thread active vs inactive connections with keep alive(separately).

apache mpm-prefork module

Prefork: child process, (single threaded)
each child process with one thread, each process handles one,(memory allocates based on process)
<IfModule mpm_prefork_module>
  StartServers              4
MinSpareServers          20
MaxSpareServers          40
MaxRequestWorkers       200
MaxConnectionsPerChild 4500</IfModule>

MaxRequestWorkers / MaxClients

maximum connections handled by (single threaded process)
default 256
(increase based on traffic &server resources)
starts servers (greater than min spare servers)
server means a child process of apache
threadsperchild, minsparethreads
minspareservers (25% of max spare servers)
maximum spare servers (equal to request workers)

maxrequestsperchild/maxconnectionsperchild

before a process respawns or die it should handle the these connections. (respawning frequently causes highload)
default =0(unlimited) already decides by threadsperchild *maxconnectionsperchild
it’s better use to avoid memory leaks.
set minimum of 10000 if necessary.
in php-fpm pool manager with nginx default it is 500;
ServerLimit directive represents the upper limit of MaxRequestWorkers

check mpm module apache2 using

apache2 -v
root@instance-1:/home/ubuntu/.ssh# apache2 -v
Server version: Apache/2.4.29 (Ubuntu)
Server built: 2020-03-13T12:26:16
you see mom module along with apache version.
Mpm-prefork module and php-fpm confirmation uses same methodology.
root@instance-1:/home/ubuntu/.ssh# apache2 -V
[Fri Aug 07 10:55:45.384106 2020] [core:warn] [pid 9663] AH00111: Config variable ${APACHE_RUN_DIR} is not defined
apache2: Syntax error on line 80 of /etc/apache2/apache2.conf: DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot
Server version: Apache/2.4.29 (Ubuntu)
Server built:   2020-03-13T12:26:16
Server's Module Magic Number: 20120211:68
Server loaded:  APR 1.6.3, APR-UTIL 1.6.1
Compiled using: APR 1.6.3, APR-UTIL 1.6.1
Architecture:   64-bit
Server MPM:
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"
root@instance-1:/home/ubuntu/.ssh#

 

/etc/apache2/mods-enabled

 

you can change in apache2.conf or enabling disabling module

 

mpm_prefork_module (shared)

 

nano /etc/apache2/apache2.conf

Disable unnecessary modules

sudo a2dismod modname
to view loaded modules
apache2ctl -M
root@instance-1:~# apache2ctl -M
Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 filter_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 php7_module (shared)
 reqtimeout_module (shared)
 setenvif_module (shared)
 status_module (shared)
root@instance-1:~#

 

Time-outs

default 60 sec or 1 minute
to control dos /ddos or brute force attacks.

keep alive

connections while browser reading a page
directives also govern KeepAlive. MaxKeepAliveRequests and KeepAliveTimeout.
default 100
keep alive timeout 2
task vs process vs child process vs threads

Increase Max Open Files

If you are handling high loads increase the number of allowed open files.  On linux, increase /proc/sys/fs/file-max and run ulimit -H -n 4096.
HostnameLookups off;

disable htaccess

AllowOverride should be directory specific.

enable caching in to separate static content.
CacheQuickHandler on; for static

Disable extended status in apache2.conf

ExtendedStatus off
install MySQL tuner to suggestions based on your sever environment.

optimize linux system

ListenBacklog
soffilelimit

cpu intensive or memory intensive

top command shows
dual core cpu
50% means one core utilized 100%.
avg cpu 75%
memory 75%
disk io & space (SSD must hdd no way hdd vs ssd)

use varnish nginx as reverse proxy and load balancer

nginx caches pages and serves directly without contacting the apache.
while apache busy with dynamic page generation. then nginx caches dynamic pages stores as satic pages seres faster.
nginx as load balancer :
stores cache multiple server based on algorithms.
you must read
use nginx as reverse proxy and load balancer for apache wordpress

apache server tutorial (install,config, performance tuning, security, error handling)

  • what is If-Modified-Since HTTP header how to add to Wordpress website
  • htaccess tutorial tips for wordpress #redirect #leverage browser cache #Gzip #KeepAlive
  • apache modules list (explained, enable disable)
  • connect to server by SSH client Putty SFTP client winscp LAMP, LEMP nginx apache etc linux
  • Lamp stack install on Ubuntu 20.4 LTS apache, mysql, php 7.4(Debian 9 & Ubuntu 18.04 lts)
  • apache performance tuning mpm-worker vs prefork vs event modules
  • enable caching in apache server (mod cache disk cache) vs fastcgi cache
  • how to enable KeepAlive connections in apache nginx wordpress
  • Cache control Header & expires headers How to set Properly
  • apache2 conf sample explained apache configuration file modules etc
  • restart apache in ubuntu (start | stop | reload | config test) centos debian mac linux windows 10 xampp
  • uninstall apache2 ubuntu in 3 steps Debian

hi i am raju ginni, primalry i manage wordpress websites on GCP cloud platform as a cloud engineer, and create content on passionate things.
you can follow me on youtbe

© 2025 - All Rights Reserved Disclaimer & Privacy Policy