]> granicus.if.org Git - apache/commitdiff
Threaded MPMs for Unix and Win32: Add WorkerStackSize directive
authorJeff Trawick <trawick@apache.org>
Thu, 11 Mar 2004 03:57:50 +0000 (03:57 +0000)
committerJeff Trawick <trawick@apache.org>
Thu, 11 Mar 2004 03:57:50 +0000 (03:57 +0000)
to override default thread stack size for threads which handle
client connections.  Required for some third-party modules on
platforms with small default thread stack size.

This is also useful for trimming back the stack size on
platforms with relatively large default stack size in order to
conserve address space for supporting more threads per child.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@102931 13f79535-47bb-0310-9956-ffa450edef68

14 files changed:
CHANGES
include/mpm_common.h
server/core.c
server/mpm/experimental/leader/leader.c
server/mpm/experimental/leader/mpm.h
server/mpm/experimental/perchild/mpm.h
server/mpm/experimental/perchild/perchild.c
server/mpm/experimental/threadpool/mpm.h
server/mpm/experimental/threadpool/threadpool.c
server/mpm/winnt/child.c
server/mpm/winnt/mpm.h
server/mpm/worker/mpm.h
server/mpm/worker/worker.c
server/mpm_common.c

diff --git a/CHANGES b/CHANGES
index 78b03708203102aaebf6a4ee3251e3f720099c4c..f598c8dde6fce6629f74e6e83ebdea1634760d24 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,12 @@
 Changes with Apache 2.1.0-dev
 
   [Remove entries to the current 2.0 section below, when backported]
+
+  *) Threaded MPMs for Unix and Win32: Add WorkerStackSize directive
+     to override default thread stack size for threads which handle
+     client connections.  Required for some third-party modules on
+     platforms with small default thread stack size.  [Jeff Trawick]
+
   *) Win32: Tweak worker thread accounting routines to eliminate
      server hang when number of Listen directives in httpd.conf
      is greater than or equal to the setting of ThreadsPerChild.
index 8afb154ed6580785f938ba2814da7f25c866f233..f751cc64a05e89f654a3725b1e60ab7882246303 100644 (file)
@@ -248,6 +248,12 @@ extern const char *ap_mpm_set_max_mem_free(cmd_parms *cmd, void *dummy,
                                            const char *arg);
 #endif
 
+#ifdef AP_MPM_WANT_SET_STACKSIZE
+extern apr_size_t ap_worker_stacksize;
+extern const char *ap_mpm_set_worker_stacksize(cmd_parms *cmd, void *dummy,
+                                               const char *arg);
+#endif
+
 #ifdef AP_MPM_WANT_FATAL_SIGNAL_HANDLER
 extern apr_status_t ap_fatal_signal_setup(server_rec *s, apr_pool_t *pconf);
 extern apr_status_t ap_fatal_signal_child_setup(server_rec *s);
index c6d243a3a7579ec0941699517c8b64808222e25e..b62586265c47bcbe5ec6a2115decc5bc9882223e 100644 (file)
@@ -3225,6 +3225,10 @@ AP_INIT_TAKE1("AcceptMutex", ap_mpm_set_accept_lock_mech, NULL, RSRC_CONF,
 AP_INIT_TAKE1("MaxMemFree", ap_mpm_set_max_mem_free, NULL, RSRC_CONF,
               "Maximum number of 1k blocks a particular childs allocator may hold."),
 #endif
+#ifdef AP_MPM_WANT_SET_STACKSIZE
+AP_INIT_TAKE1("WorkerStackSize", ap_mpm_set_worker_stacksize, NULL, RSRC_CONF,
+              "Size in bytes of stack used by threads handling client connections"),
+#endif
 #if AP_ENABLE_EXCEPTION_HOOK
 AP_INIT_TAKE1("EnableExceptionHook", ap_mpm_set_exception_hook, NULL, RSRC_CONF,
               "Controls whether exception hook may be called after a crash"),
index ccb0c39f34b9b267965b0a608548c9e9f158c030..c9b275ed72f8f1acf057d4bc6b9090c2671a1557 100644 (file)
@@ -1074,6 +1074,9 @@ static void child_main(int child_num_arg)
     apr_threadattr_create(&thread_attr, pchild);
     /* 0 means PTHREAD_CREATE_JOINABLE */
     apr_threadattr_detach_set(thread_attr, 0);
+    if (ap_worker_stacksize != 0) {
+        apr_threadattr_stacksize_set(thread_attr, ap_worker_stacksize);
+    }
 
     ts->threads = threads;
     ts->child_num_arg = child_num_arg;
index e9e51438dce447157e962c9dba8ba0337282b064..9ad7da214fe3520cddc97d49f6944dfe7665dc46 100644 (file)
@@ -34,6 +34,7 @@
 #define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
 #define AP_MPM_WANT_SIGNAL_SERVER
 #define AP_MPM_WANT_SET_MAX_MEM_FREE
+#define AP_MPM_WANT_SET_STACKSIZE
 #define AP_MPM_WANT_FATAL_SIGNAL_HANDLER
 #define AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK
 
index 95f3eb35f3e66c36d6e678ed60b1b8be44f32cd3..cb17ba9bc52fe0b85e6f8af68d7c8317bf34b0cf 100644 (file)
@@ -34,6 +34,7 @@
 #define AP_MPM_WANT_SET_COREDUMPDIR
 #define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
 #define AP_MPM_WANT_SIGNAL_SERVER
+#define AP_MPM_WANT_SET_STACKSIZE
 #define AP_MPM_WANT_FATAL_SIGNAL_HANDLER
 #define AP_MPM_USES_POD
 
index f73c0f1b430620b8a07eb67d83fc89877aa7ce48..484f630378b7a0e2ddfb3d57ea15b364ebbcbc87 100644 (file)
@@ -982,7 +982,9 @@ static void child_main(int child_num_arg)
                     APR_THREAD_MUTEX_DEFAULT, pchild);
 
     apr_threadattr_create(&worker_thread_attr, pchild);
-    apr_threadattr_detach_set(worker_thread_attr, 1);                                     
+    apr_threadattr_detach_set(worker_thread_attr, 1);                               if (ap_worker_stacksize != 0) {
+        apr_threadattr_stacksize_set(thread_attr, ap_worker_stacksize);
+    }
 
     /* We are creating worker threads right now */
     for (i=0; i < threads_to_start; i++) {
index afdcce52100dd72197de7077612e2d7ede4a68c0..ff631b067f205007d52cb9fbb0dfc10b329a8b77 100644 (file)
@@ -34,6 +34,7 @@
 #define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
 #define AP_MPM_WANT_SIGNAL_SERVER
 #define AP_MPM_WANT_SET_MAX_MEM_FREE
+#define AP_MPM_WANT_SET_STACKSIZE
 #define AP_MPM_WANT_FATAL_SIGNAL_HANDLER
 #define AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK
 
index 7277915a73576c8170581d6fc2c51643babb1858..fab5d993459f18a17ac13c15e97b0166b3ab064c 100644 (file)
@@ -1289,6 +1289,9 @@ static void child_main(int child_num_arg)
     apr_threadattr_create(&thread_attr, pchild);
     /* 0 means PTHREAD_CREATE_JOINABLE */
     apr_threadattr_detach_set(thread_attr, 0);
+    if (ap_worker_stacksize != 0) {
+        apr_threadattr_stacksize_set(thread_attr, ap_worker_stacksize);
+    }
 
     ts->threads = threads;
     ts->listener = NULL;
index 76ab5b45c44160c33c9f758b7a19566d182a223f..c74f41c22dcecfe12e96981f28062e31cf4b7c39 100644 (file)
@@ -928,7 +928,8 @@ void child_main(apr_pool_t *pconf)
                 continue;
             }
             ap_update_child_status_from_indexes(0, i, SERVER_STARTING, NULL);
-            child_handles[i] = (HANDLE) _beginthreadex(NULL, 0, (LPTHREAD_START_ROUTINE) worker_main,
+            child_handles[i] = (HANDLE) _beginthreadex(NULL, (unsigned)ap_worker_stacksize,
+                                                       (LPTHREAD_START_ROUTINE) worker_main,
                                                        (void *) i, 0, &tid);
             if (child_handles[i] == 0) {
                 ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf,
index 354d581b78087750f70cd8a4afaaa0170a62b33f..9d4ed5a9a85887038f454872232e50d616883c99 100644 (file)
@@ -30,6 +30,7 @@
 #define AP_MPM_WANT_SET_COREDUMPDIR
 #define AP_MPM_WANT_SET_SCOREBOARD
 #define AP_MPM_WANT_SET_MAX_MEM_FREE
+#define AP_MPM_WANT_SET_STACKSIZE
 
 extern int ap_threads_per_child;
 extern int ap_thread_limit;
index b152569dd2cb1664e9baff84b66355a91a5cc8e1..f84cbcf6616910c3a354ba61b0ac9ab73fc228f4 100644 (file)
@@ -34,6 +34,7 @@
 #define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
 #define AP_MPM_WANT_SIGNAL_SERVER
 #define AP_MPM_WANT_SET_MAX_MEM_FREE
+#define AP_MPM_WANT_SET_STACKSIZE
 #define AP_MPM_WANT_FATAL_SIGNAL_HANDLER
 #define AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK
 
index 90ca74119cb0a987b08fb1bc649ac23cb9c5a1a7..5080f7b523348e6816e25b27dbb0a4eddee57712 100644 (file)
@@ -1164,6 +1164,10 @@ static void child_main(int child_num_arg)
     /* 0 means PTHREAD_CREATE_JOINABLE */
     apr_threadattr_detach_set(thread_attr, 0);
 
+    if (ap_worker_stacksize != 0) {
+        apr_threadattr_stacksize_set(thread_attr, ap_worker_stacksize);
+    }
+    
     ts->threads = threads;
     ts->listener = NULL;
     ts->child_num_arg = child_num_arg;
index afb663f29625933e7712a9cb74727194cc65f880..968b4cd0304453a97933a48edc4d51b47f26b547 100644 (file)
@@ -870,6 +870,30 @@ const char *ap_mpm_set_max_mem_free(cmd_parms *cmd, void *dummy,
 
 #endif /* AP_MPM_WANT_SET_MAX_MEM_FREE */
 
+#ifdef AP_MPM_WANT_SET_STACKSIZE
+apr_size_t ap_worker_stacksize = 0; /* use system default */
+
+const char *ap_mpm_set_worker_stacksize(cmd_parms *cmd, void *dummy,
+                                        const char *arg)
+{
+    long value;
+    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+    if (err != NULL) {
+        return err;
+    }
+    
+    value = strtol(arg, NULL, 0);
+    if (value < 0 || errno == ERANGE)
+        return apr_pstrcat(cmd->pool, "Invalid WorkerStackSize value: ", 
+                           arg, NULL);
+
+    ap_worker_stacksize = (apr_size_t)value;
+
+    return NULL;
+}
+
+#endif /* AP_MPM_WANT_SET_STACKSIZE */
+
 #ifdef AP_MPM_WANT_FATAL_SIGNAL_HANDLER
 
 static pid_t parent_pid, my_pid;