mpm_winnt: Use a LIFO stack instead of a FIFO queue to hold unused
completion contexts, as that may significantly reduce the memory usage. This simple change can have a noticeable impact on the amount of memory consumed by the child process in various cases. Every completion context in the queue has an associated allocator, and every allocator has it's ap_max_mem_free memory limit which is not given back to the operating system. Once the queue grows, it cannot shrink back, and every allocator in each of the queued completion contexts keeps up to its max_free amount of memory. The queue can only grow when a server has to serve multiple concurrent connections at once. With that in mind, consider a case with a server that doesn't encounter many concurrent connections most of the time, but has occasional spikes when it has to serve multiple concurrent connections. During such spikes, the size of the completion context queue grows. The actual difference between using LIFO and FIFO orders shows up after such spikes, when the server is back to light load and doesn't see a lot of concurrency. With FIFO order, every completion context in the queue will be used in a round-robin manner, thus using *every* available allocator one by one and ultimately claiming up to (N * ap_max_mem_free memory) from the OS. With LIFO order, only the completion contexts that are close to the top of the stack will be used and reused for subsequent connections. Hence, only a small part of the allocators will be used, and this can prevent all other allocators from unnecessarily acquiring memory from the OS (and keeping it), and this reduces the overall memory footprint. Please note that this change doesn't affect the worst case behavior, as it's still (N * ap_max_mem_free memory), but tends to behave better in practice, for the reasons described above. Another thing worth considering is the new behavior when the OS decides to swap out pages of the child process, for example, in a close-to-OOM condition. Handling every new connection after the swap requires the OS to load the memory pages for the allocator from the completion context that is used for this connection. With FIFO order, the completion contexts are used one by one, and this would cause page loads for every new connection. With LIFO order, there will be almost no swapping, since the same completion context is going to be reused for subsequent new connections. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1801655 13f79535-47bb-0310-9956-ffa450edef68
Please register or sign in to comment