Apache modules.
Apache is available in 3 MPM modules.
=-=-=-=
Prefork
Worker
Event
=-=-=-=
The module currently apache using can be obtained from the command,
#httpd -l
1. Prefork
The prefork will dedicate a process per request, while worker and event allocate a thread per request. Now, a thread is subset of process. Threads are originated from process. When a thread is used, resource utiliization is less, because it use a shared memory space. Threads can handle more requests than the other method since there is less overhead required. Number of process to be started can be configured using the apache configuration under the section "IfModule prefork.c".
Sample prefork values,
--------------------------
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
-------------------------
#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
#ServerLimit: maximum value for MaxClients for the lifetime of the server
#MaxClients: maximum number of server processes allowed to start
#MaxRequestsPerChild: maximum number of requests a server process serves.
I have seen an useful diagam to illustrate prefork.
/---------\
| Prefork | -------- > Request --- 1% CPU - 10 MB RAM
\________/
/---------\
| Prefork | -------- > Request --- 1% CPU - 10 MB RAM
\________/
/---------\
| Prefork | -------- > Request --- 1% CPU - 10 MB RAM
\________/
/---------\
| Prefork | -------- > Request --- 1% CPU - 10 MB RAM
Here, total usage of resources are 4% of your CPU and 40MB of RAM.
2. Worker
For worker, each of the requests are handled by threads. The most important directives used to control this MPM are ThreadsPerChild, which controls the number of threads deployed by each child process and MaxClients, which controls the maximum total number of threads that may be launched. This can be wasily illustrated by the following diagram.
/-------------\
| Worker MPM | ----------> Request \
| Worker MPM | ----------> Request | All these request use up 2% CPU and 25 MB of ram.
| Worker MPM | ----------> Request |
| Worker MPM | ----------> Request /
\____________/
A single control process (the parent) is responsible for launching child processes. Each child process creates a fixed number of server threads as specified in the ThreadsPerChild directive, as well as a listener thread which listens for connections and passes them to a server thread for processing when they arrive.
Parameters and sample worker configuration.
#worker MPM
#StartServers: initial number of server processes to start
#MaxClients: maximum number of simultaneous client connections
#MinSpareThreads: minimum number of worker threads which are kept spare
#MaxSpareThreads: maximum number of worker threads which are kept spare
#ThreadsPerChild: constant number of worker threads in each server process
#MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule worker.c>
StartServers 4
MaxClients 300
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
3. Event MPM
Event allow more requests to be served simultaneously by passing off some processing work to supporting threads,freeing up the main threads to work on new requests. Here, after a client completes the first request, the client can keep the connection open, and send further requests using the same socket. This can save significant overhead in creating TCP connections.This has been released stable in Apache 2.4. This can be used for having threads waiting for idle connections.With the Event MPM, the connection the thread is only used for requests and frees backup immediately after the request is fulfilled.
Apache is available in 3 MPM modules.
=-=-=-=
Prefork
Worker
Event
=-=-=-=
The module currently apache using can be obtained from the command,
#httpd -l
1. Prefork
The prefork will dedicate a process per request, while worker and event allocate a thread per request. Now, a thread is subset of process. Threads are originated from process. When a thread is used, resource utiliization is less, because it use a shared memory space. Threads can handle more requests than the other method since there is less overhead required. Number of process to be started can be configured using the apache configuration under the section "IfModule prefork.c".
Sample prefork values,
--------------------------
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
-------------------------
#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
#ServerLimit: maximum value for MaxClients for the lifetime of the server
#MaxClients: maximum number of server processes allowed to start
#MaxRequestsPerChild: maximum number of requests a server process serves.
I have seen an useful diagam to illustrate prefork.
/---------\
| Prefork | -------- > Request --- 1% CPU - 10 MB RAM
\________/
/---------\
| Prefork | -------- > Request --- 1% CPU - 10 MB RAM
\________/
/---------\
| Prefork | -------- > Request --- 1% CPU - 10 MB RAM
\________/
/---------\
| Prefork | -------- > Request --- 1% CPU - 10 MB RAM
Here, total usage of resources are 4% of your CPU and 40MB of RAM.
2. Worker
For worker, each of the requests are handled by threads. The most important directives used to control this MPM are ThreadsPerChild, which controls the number of threads deployed by each child process and MaxClients, which controls the maximum total number of threads that may be launched. This can be wasily illustrated by the following diagram.
/-------------\
| Worker MPM | ----------> Request \
| Worker MPM | ----------> Request | All these request use up 2% CPU and 25 MB of ram.
| Worker MPM | ----------> Request |
| Worker MPM | ----------> Request /
\____________/
A single control process (the parent) is responsible for launching child processes. Each child process creates a fixed number of server threads as specified in the ThreadsPerChild directive, as well as a listener thread which listens for connections and passes them to a server thread for processing when they arrive.
Parameters and sample worker configuration.
#worker MPM
#StartServers: initial number of server processes to start
#MaxClients: maximum number of simultaneous client connections
#MinSpareThreads: minimum number of worker threads which are kept spare
#MaxSpareThreads: maximum number of worker threads which are kept spare
#ThreadsPerChild: constant number of worker threads in each server process
#MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule worker.c>
StartServers 4
MaxClients 300
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
3. Event MPM
Event allow more requests to be served simultaneously by passing off some processing work to supporting threads,freeing up the main threads to work on new requests. Here, after a client completes the first request, the client can keep the connection open, and send further requests using the same socket. This can save significant overhead in creating TCP connections.This has been released stable in Apache 2.4. This can be used for having threads waiting for idle connections.With the Event MPM, the connection the thread is only used for requests and frees backup immediately after the request is fulfilled.