Skip to main content

Apache_Http_Server MPM: GracefulShutdownTimeout Example


Description: A collection of directives that are implemented by more than one multi-processing module (MPM)
Status: MPM

CoreDumpDirectory Directive

Description: Directory where Apache HTTP Server attempts to switch before dumping core
Syntax:
CoreDumpDirectory directory
Default:
See usage for the default setting
Context: server config
Status: MPM
Module: event, worker, prefork

This controls the directory to which Apache httpd attempts to switch before dumping core. If your operating system is configured to create core files in the working directory of the crashing process, CoreDumpDirectory is necessary to change working directory from the default ServerRoot directory, which should not be writable by the user the server runs as.

If you want a core dump for debugging, you can use this directive to place it in a different location. This directive has no effect if your operating system is not configured to write core files to the working directory of the crashing processes.

Core Dumps on Linux

If Apache httpd starts as root and switches to another user, the Linux kernel disables core dumps even if the directory is writable for the process. Apache httpd (2.0.46 and later) reenables core dumps on Linux 2.4 and beyond, but only if you explicitly configure a CoreDumpDirectory.

Core Dumps on BSD

To enable core-dumping of suid-executables on BSD-systems (such as FreeBSD), set kern.sugid_coredump to 1.

Specific signals

CoreDumpDirectory processing only occurs for a select set of fatal signals: SIGFPE, SIGILL, SIGABORT, SIGSEGV, and SIGBUS.

On some operating systems, SIGQUIT also results in a core dump but does not go through CoreDumpDirectory or EnableExceptionHook processing, so the core location is dictated entirely by the operating system.

GracefulShutdownTimeout Directive

Description: Specify a timeout after which a gracefully shutdown server will exit.
Syntax:
GracefulShutdownTimeout seconds
Default:
GracefulShutdownTimeout 0
Context: server config
Status: MPM
Module: event, worker, prefork
Compatibility: Available in version 2.2 and later

The GracefulShutdownTimeout specifies how many seconds after receiving a "graceful-stop" signal, a server should continue to run, handling the existing connections.

Setting this value to zero means that the server will wait indefinitely until all remaining requests have been fully served.

Listen Directive

Description: IP addresses and ports that the server listens to
Syntax:
Listen [IP-address:]portnumber [protocol]
Context: server config
Status: MPM
Module: event, worker, prefork, mpm_winnt, mpm_netware, mpmt_os2
Compatibility: The protocol argument was added in 2.1.5

The Listen directive instructs Apache httpd to listen to only specific IP addresses or ports; by default it responds to requests on all IP interfaces. Listen is now a required directive. If it is not in the config file, the server will fail to start. This is a change from previous versions of Apache httpd.

The Listen directive tells the server to accept incoming requests on the specified port or address-and-port combination. If only a port number is specified, the server listens to the given port on all interfaces. If an IP address is given as well as a port, the server will listen on the given port and interface.

Multiple Listen directives may be used to specify a number of addresses and ports to listen to. The server will respond to requests from any of the listed addresses and ports.

For example, to make the server accept connections on both port 80 and port 8000, use:

Listen 80 Listen 8000

To make the server accept connections on two specified interfaces and port numbers, use

Listen 192.170.2.1:80 Listen 192.170.2.5:8000

IPv6 addresses must be surrounded in square brackets, as in the following example:

Listen [2001:db8::a00:20ff:fea7:ccea]:80

The optional protocol argument is not required for most configurations. If not specified, https is the default for port 443 and http the default for all other ports. The protocol is used to determine which module should handle a request, and to apply protocol specific optimizations with the AcceptFilter directive.

You only need to set the protocol if you are running on non-standard ports. For example, running an https site on port 8443:

Listen 192.170.2.1:8443 https

Error condition

Multiple Listen directives for the same ip address and port will result in an Address already in use error message.

See also

ListenCoresBucketsRatio Directive

Description: Ratio between the number of CPU cores (online) and the number of listeners' buckets
Syntax:
ListenCoresBucketsRatio ratio
Default:
ListenCoresBucketsRatio 0 (disabled)
Context: server config
Status: MPM
Module: event, worker, prefork
Compatibility: Available in Apache HTTP Server 2.4.17, with a kernel supporting the socket option SO_REUSEPORT and distributing new connections evenly across listening processes' (or threads') sockets using it (eg. Linux 3.9 and later, but not the current implementations of SO_REUSEPORT in *BSDs.

A ratio between the number of (online) CPU cores and the number of listeners' buckets can be used to make Apache HTTP Server create num_cpu_cores / ratio listening buckets, each containing its own Listen-ing socket(s) on the same port(s), and then make each child handle a single bucket (with round-robin distribution of the buckets at children creation time).

ListenCoresBucketsRatio can improve the scalability when accepting new connections is/becomes the bottleneck. On systems with a large number of CPU cores, enabling this feature has been tested to show significant performances improvement and shorter responses time.

There must be at least twice the number of CPU cores than the configured ratio for this to be active. The recommended ratio is 8, hence at least 16 cores should be available at runtime when this value is used. The right ratio to obtain maximum performance needs to be calculated for each target system, testing multiple values and observing the variations in your key performance metrics.

This directive influences the calculation of the MinSpareThreads and MaxSpareThreads lower bound values. The number of children processes needs to be a multiple of the number of buckets to optimally accept connections.

Multiple Listeners or Apache HTTP servers on the same IP address and port

Setting the SO_REUSEPORT option on the listening socket(s) consequently allows multiple processes (sharing the same EUID, e.g. root) to bind to the the same IP address and port, without the binding error raised by the system in the usual case.

This also means that multiple instances of Apache httpd configured on a same IP:port and with a positive ListenCoresBucketsRatio would start without an error too, and then run with incoming connections evenly distributed accross both instances (this is NOT a recommendation or a sensible usage in any case, but just a notice that it would prevent such possible issues to be detected).

Within the same instance, Apache httpd will check and fail to start if multiple Listen directives on the exact same IP (or hostname) and port are configured, thus avoiding the creation of some duplicated buckets which would be useless and kill performances. However it can't (and won't try harder to) catch all the possible overlapping cases (like a hostname resolving to an IP used elsewhere).

MaxConnectionsPerChild Directive

Description: Limit on the number of connections that an individual child server will handle during its life
Syntax:
MaxConnectionsPerChild number
Default:
MaxConnectionsPerChild 0
Context: server config
Status: MPM
Module: event, worker, prefork, mpm_winnt, mpm_netware, mpmt_os2
Compatibility: Available Apache HTTP Server 2.3.9 and later. The old name MaxRequestsPerChild is still supported.

The MaxConnectionsPerChild directive sets the limit on the number of connections that an individual child server process will handle. After MaxConnectionsPerChild connections, the child process will die. If MaxConnectionsPerChild is 0, then the process will never expire.

Setting MaxConnectionsPerChild to a non-zero value limits the amount of memory that process can consume by (accidental) memory leakage.

MaxMemFree Directive

Description: Maximum amount of memory that the main allocator is allowed to hold without calling free()
Syntax:
MaxMemFree KBytes
Default:
MaxMemFree 2048
Context: server config
Status: MPM
Module: event, worker, prefork, mpm_winnt, mpm_netware

The MaxMemFree directive sets the maximum number of free Kbytes that every allocator is allowed to hold without calling free(). In threaded MPMs, every thread has its own allocator. When set to zero, the threshold will be set to unlimited.

ReceiveBufferSize Directive

Description: TCP receive buffer size
Syntax:
ReceiveBufferSize bytes
Default:
ReceiveBufferSize 0
Context: server config
Status: MPM
Module: event, worker, prefork, mpm_winnt, mpm_netware, mpmt_os2

The server will set the TCP receive buffer size to the number of bytes specified.

If set to the value of 0, the server will use the OS default.

ServerLimit Directive

Description: Upper limit on configurable number of processes
Syntax:
ServerLimit number
Default:
See usage for details
Context: server config
Status: MPM
Module: event, worker, prefork

For the prefork MPM, this directive sets the maximum configured value for MaxRequestWorkers for the lifetime of the Apache httpd process. For the worker and event MPMs, this directive in combination with ThreadLimit sets the maximum configured value for MaxRequestWorkers for the lifetime of the Apache httpd process. For the event MPM, this directive also defines how many old server processes may keep running and finish processing open connections. Any attempts to change this directive during a restart will be ignored, but MaxRequestWorkers can be modified during a restart.

Special care must be taken when using this directive. If ServerLimit is set to a value much higher than necessary, extra, unused shared memory will be allocated. If both ServerLimit and MaxRequestWorkers are set to values higher than the system can handle, Apache httpd may not start or the system may become unstable.

With the prefork MPM, use this directive only if you need to set MaxRequestWorkers higher than 256 (default). Do not set the value of this directive any higher than what you might want to set MaxRequestWorkers to.

With worker, use this directive only if your MaxRequestWorkers and ThreadsPerChild settings require more than 16 server processes (default). 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.

With event, increase this directive if the process number defined by your MaxRequestWorkers and ThreadsPerChild settings, plus the number of gracefully shutting down processes, is more than 16 server processes (default).

See also

ThreadStackSize Directive

Description: The size in bytes of the stack used by threads handling client connections
Syntax:
ThreadStackSize size
Default:
65536 on NetWare; varies on other operating systems
Context: server config
Status: MPM
Module: event, worker, mpm_winnt, mpm_netware, mpmt_os2
Compatibility: Available in Apache HTTP Server 2.1 and later

The ThreadStackSize directive sets the size of the stack (for autodata) of threads which handle client connections and call modules to help process those connections. In most cases the operating system default for stack size is reasonable, but there are some conditions where it may need to be adjusted:

  • On platforms with a relatively small default thread stack size (e.g., HP-UX), Apache httpd may crash when using some third-party modules which use a relatively large amount of autodata storage. Those same modules may have worked fine on other platforms where the default thread stack size is larger. This type of crash is resolved by setting ThreadStackSize to a value higher than the operating system default. This type of adjustment is necessary only if the provider of the third-party module specifies that it is required, or if diagnosis of an Apache httpd crash indicates that the thread stack size was too small.
  • On platforms where the default thread stack size is significantly larger than necessary for the web server configuration, a higher number of threads per child process will be achievable if ThreadStackSize is set to a value lower than the operating system default. This type of adjustment should only be made in a test environment which allows the full set of web server processing can be exercised, as there may be infrequent requests which require more stack to process. The minimum required stack size strongly depends on the modules used, but any change in the web server configuration can invalidate the current ThreadStackSize setting.
  • On Linux, this directive can only be used to increase the default stack size, as the underlying system call uses the value as a minimum stack size. The (often large) soft limit for ulimit -s (8MB if unlimited) is used as the default stack size.
It is recommended to not reduce ThreadStackSize unless a high number of threads per child process is needed. On some platforms (including Linux), a setting of 128000 is already too low and causes crashes with some common modules.

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?