Saltar al contenido

MFM

Apache – prefork vs. worker mode, how to check mode and more

  • admin 

Referencia:

https://communities.ca.com/web/ca-identity-and-access-mgmt-distributed-global-user-community/message-board/-/message_boards/view_message/98290538

 

This Tuesday Tip will cover some common questions regarding Apache, specifically prefork vs. worker mode, how to change the default value on RedHat, Solaris and other operating systems as well as verifying what mode apache is currently running in.

A. The default MPM for Unix is the Prefork module.
B. The Worker MPM was introduced in Apache2.

Now Comparing between Worker MPM and Prefork MPM.

Prefork MPM
– prefork MPM uses multiple child processes with one thread each.
– Each process handles one connection at a time and uses more memory.
– Good for non-thread-safe third party modules.

Worker MPM
– worker MPM uses multiple child processes with many threads each.
– Each thread handles one connection at a time.
– Good for high-traffic, smaller memory footprint.

MPM uses a multi-process and multi-threaded structure.
Multi-process –> multi PIDs (use ‘ps -aef’ to find out)
Multi-thread –> more connections per PID. (use ‘lsof’ (on Solaris) to find out. ‘netstat -an’ (You really won’t see everything.)

The worker MPM uses multiple child processes. It’s multi-threaded within each child, and each thread handles a single connection. Worker is fast and highly scalable and the memory footprint is comparatively low. It’s well suited for multiple processors.

Prefork MPM is preferred for better compatibility with older software or for better stability although it uses more memory. It handles requests in a manner similar to Apache 1.3. It is appropriate for sites that need to avoid threading for compatibility with non-thread-safe libraries. It is also the best MPM for isolating each request, so that a problem with a single request will not affect any other. Prefork is well suited for single or double CPU systems, speed is comparable to that of worker, and it’s highly tolerant of faulty modules and crashing children – but the memory usage is high, and more traffic leads to greater memory usage.

Conclusion: For most new websites that are that use thread safe libraries, use multiple processes and high traffic sites, CA SiteMinder recommends MPM worker mode for Apache.

>>>>>>>>>>>

How to tell if I’m running Apache in prefork or worker MPM? (Multi-Processing Module)

Note : You can have one and only one MPM module loaded in apache at any one time.

From the bin directory, you can run ./apachectl -V (Capital V)

./apache2/bin/apachectl -V
Server version: Apache/2.0.50
Server built: Aug 3 2004 16:52:20
Server’s Module Magic Number: 20020903:8
Architecture: 32-bit
Server compiled with….
-D APACHE_MPM_DIR=»server/mpm/prefork» (This is running in prefork mode)

Newer version running in worker mode:

./apachectl -V
Server version: Apache/2.2.21 (Unix)
Server built: Oct 23 2011 17:42:11
Server’s Module Magic Number: 20051115:30
Server loaded: APR 1.4.5, APR-Util 1.3.12
Compiled using: APR 1.4.5, APR-Util 1.3.12
Architecture: 32-bit
Server MPM: Worker <——Worker
threaded: yes (fixed thread count)
forked: yes (variable process count)
Server compiled with….
-D APACHE_MPM_DIR=»server/mpm/worker» <- This same line will still exist.

A second way to check, again from the bin directory:

#./ httpd -l
Compiled in modules:
core.c
prefork.c <—- Prefork
http_core.c
mod_so.c

./httpd -l
Compiled in modules:
core.c
mod_access.c
mod_auth.c
mod_include.c
mod_log_config.c
mod_logio.c
mod_env.c
mod_setenvif.c
worker.c <—–Worker

>>>>>>>>>>>

How do I change the default value on RHEL (Red Hat Enterprise Release)?

Edit the /etc/sysconfig/httpd file.

Change #HTTPD=/usr/sbin/httpd.worker

to

HTTPD=/usr/sbin/httpd.worker

and stop/start the apache service.

>>>>>>>>>>>

Solaris or most unix like operating systems.

When I download the code from apache.org and use certain flags to compile apache, what flag do I use for worker mode?

./configure –with-mpm=worker

For all compile options, please reference www.apache.org