You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ko...@apache.org on 2017/07/11 16:41:51 UTC

svn commit: r1801635 - /httpd/httpd/trunk/server/mpm/winnt/child.c

Author: kotkov
Date: Tue Jul 11 16:41:51 2017
New Revision: 1801635

URL: http://svn.apache.org/viewvc?rev=1801635&view=rev
Log:
mpm_winnt: Make the shutdown faster by avoiding unnecessary Sleep()'s
when shutting down the worker threads.

Previously, the shutdown code was posting an amount of I/O completion
packets equal to the amount of the threads blocked on the I/O completion
port.  Then it would Sleep() until all these threads "acknowledge" the
completion packets by decrementing the global amount of blocked threads.

A better way would be to send the number of IOCP_SHUTDOWN completion
packets equal to the total amount of threads and immediately proceed to
the next step.  There is no need to block until the threads actually receive
the completion, as the shutdown process includes a separate step that waits
until the threads exit, and the new approach avoids an unnecessary delay.

Modified:
    httpd/httpd/trunk/server/mpm/winnt/child.c

Modified: httpd/httpd/trunk/server/mpm/winnt/child.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/winnt/child.c?rev=1801635&r1=1801634&r2=1801635&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/winnt/child.c (original)
+++ httpd/httpd/trunk/server/mpm/winnt/child.c Tue Jul 11 16:41:51 2017
@@ -1173,19 +1173,19 @@ void child_main(apr_pool_t *pconf, DWORD
                      "Child: Failure releasing the start mutex");
     }
 
-    /* Shutdown the worker threads
-     * Post worker threads blocked on the ThreadDispatch IOCompletion port
+    /* Shutdown the worker threads by posting a number of IOCP_SHUTDOWN
+     * completion packets equal to the amount of created threads
      */
-    while (g_blocked_threads > 0) {
+    if (g_blocked_threads > 0) {
         ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, ap_server_conf, APLOGNO(00361)
                      "Child: %d threads blocked on the completion port",
                      g_blocked_threads);
-        for (i=g_blocked_threads; i > 0; i--) {
-            PostQueuedCompletionStatus(ThreadDispatchIOCP, 0,
-                                       IOCP_SHUTDOWN, NULL);
-        }
-        Sleep(1000);
     }
+
+    for (i = 0; i < threads_created; i++) {
+        PostQueuedCompletionStatus(ThreadDispatchIOCP, 0, IOCP_SHUTDOWN, NULL);
+    }
+
     /* Empty the accept queue of completion contexts */
     apr_thread_mutex_lock(qlock);
     while (qhead) {