Httpd worker MPM Concepts

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

Internal

Relevance

  • httpd 2.2.26.

Overview

When configured in worker MPM mode, the httpd web server functions as a hybrid multi-process/multi-threaded web server. The server uses multiple O/S processes, each of them running multiple threads, to serve requests, unlike in the prefork mode, where there are multiple processes, but each process can only serve one request at a time.

Worker MPM support has be be explicitly compiled into the binary, it is not available by default. See the Compilation section to learn how to configure httpd with worker support and how to check whether worker support has been correctly installed.

A single control process (the parent) is responsible for launching child processes. The number of child processes is controlled with the ServerLimit and StartServers directives. 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. The configuration elements described below are represented on the mod_jk Concepts Diagram.

httpd always tries to maintain a pool of spare or idle server threads, which stand ready to serve incoming requests. In this way, clients do not need to wait for a new threads or processes to be created before their requests can be served. The number of processes that will initially launched is set by the StartServers directive. During operation, httpd assesses the total number of idle threads in all processes, and forks or kills processes to keep this number within the boundaries specified by MinSpareThreads and MaxSpareThreads. Since this process is very self-regulating, it is rarely necessary to modify these directives from their default values.

What happens if all processes have at least an active threads, at any time? Does Apache has a mechanism that marks a process for shut down and let it bleed of active requests?

MaxClients. The maximum number of clients that may be served simultaneously (i.e., the maximum total number of threads in all processes) is determined by the MaxClients (MaxRequestWorkers) directive. Situations in which the number of connections to the back end server (by counting the number of connections from the back end server side) exceed MaxClients have been reported, but those were related to edge case and error conditions, so it is probably safe to assume that MaxClient is the upper limit of the clients that can be served concurrently, for practical purposes.

The maximum number of active child processes is determined by the MaxClients directive divided by the ThreadsPerChild directive.

Two directives set hard limits on the number of active child processes and the number of server threads in a child process, and can only be changed by fully stopping the server and then starting it again. ServerLimit is a hard limit on the number of active child processes, and must be greater than or equal to the MaxClients directive divided by the ThreadsPerChild directive. ThreadLimit is a hard limit of the number of server threads per child process, and must be greater than or equal to the ThreadsPerChild directive. If non-default values are specified for these directives, they should appear before other worker directives.

Connection pooling in worker MPM mode is explained here:

mod_proxy Concepts - Connection Pooling