WINNT Apache MPM “ThreadsPerChild” configuration on Windows Server 2008 R2

amazon ec2Apache2mpm-preforkwindows-server-2008-r2

I am getting error and unable to start Apache when I set my ThreadPerChild to 200 , although I still have 60% free RAM. Server is Windows Server 2008 R2 With 4GB RAM. How to utilize more RAM to apache in this case?

My Apache MPM Configuration:

# WinNT MPM
# ThreadsPerChild: constant number of worker threads in the server process
# MaxRequestsPerChild: maximum  number of requests a server process serves
# Win32DisableAcceptEx: Use accept() rather than AcceptEx() to accept network connections
<IfModule mpm_winnt_module>
   ThreadStackSize 8388608
    ThreadsPerChild      170
    MaxRequestsPerChild    0
    #Win32DisableAcceptEx
</IfModule>

What I get in apache's error_log:

[Thu Dec 01 18:23:04.459113 2016] [mpm_winnt:notice] [pid 3396:tid
288] AH00354: Child: Starting 200 worker threads.

[Thu Dec 01 18:23:04.459113 2016] [mpm_winnt:crit] [pid 3396:tid 288] (OS 8)Not
enough storage is available to process this command. : AH00355:
Child: CreateThread failed. Unable to create all worker threads.
Created 190 of the 200 threads requested with the ThreadsPerChild
configuration directive.

[Thu Dec 01 18:23:04.474714 2016]
[mpm_winnt:notice] [pid 3644:tid 380] AH00422: Parent: Received
shutdown signal —

EDIT: 9 Dec 2016:

Followed this page https://support.microsoft.com/en-us/kb/106167 to change the IRPStackSize in Registry to 20 and 25. Still failed to start Apache server.

Thanks.

Best Answer

The thread configuration of the multi-processing module (mpm) on any system is bound to certain restrictions, system limitations, and compiled fail-safe settings as described in the article Apache MPM Common Directives

ThreadsPerChild Directive

This directive sets the number of threads created by each child process. The child creates these threads at startup and never creates more. If using an MPM like mpm_winnt, where there is only one child process, this number should be high enough to handle the entire load of the server. If using an MPM like worker, where there are multiple child processes, the total number of threads should be high enough to handle the common load on the server.

ThreadLimit Directive

Special care must be taken when using this directive. If ThreadLimit is set to a value much higher than ThreadsPerChild, extra unused shared memory will be allocated. If both ThreadLimit and ThreadsPerChild are set to values higher than the system can handle, Apache httpd may not start or the system may become unstable. Do not set the value of this directive any higher than your greatest predicted setting of ThreadsPerChild for the current run of Apache httpd.

And they also point out that...

The default value for ThreadLimit is 1920 when used with mpm_winnt and 64 when used with the others.

There is also a hard-coded compiled limit which you can circumvent by recompiling the code as explained here:

There is a hard limit of ThreadLimit 20000 (or ThreadLimit 100000 with event, ThreadLimit 15000 with mpm_winnt) compiled into the server. This is intended to avoid nasty effects caused by typos. To increase it even further past this limit, you will need to modify the value of MAX_THREAD_LIMIT in the mpm source file and rebuild the server.

ThreadStackSize Directive

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:

Which are...

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.

Solution

If you are going to increase the ThreadsPerChild directive, then you will have to align the ThreadLimit directive to the same value or only slightly higher, while additionally reducing the ThreadStackSize directive to a lower value than default, while still maintaining a stable system.

A possible solution would be:

<IfModule mpm_winnt_module>
    ThreadStackSize  6291456
    ThreadsPerChild      200
    ThreadLimit          200
    MaxRequestsPerChild    0
    #Win32DisableAcceptEx
</IfModule>

You will have to play around a bit with these values to determine the setting that will allow you to run a stable system with the max possible ThreadsPerChild setting.