]> granicus.if.org Git - apache/commitdiff
mod_proxy: follow up to r1822849.
authorYann Ylavic <ylavic@apache.org>
Thu, 1 Feb 2018 14:42:07 +0000 (14:42 +0000)
committerYann Ylavic <ylavic@apache.org>
Thu, 1 Feb 2018 14:42:07 +0000 (14:42 +0000)
Get the help(er) of mod_http2 to determine how much connections should
be handled in the reslist by default (i.e. max_threads).

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

modules/http2/h2_config.c
modules/http2/h2_config.h
modules/http2/h2_conn.c
modules/http2/mod_http2.c
modules/http2/mod_http2.h
modules/proxy/config.m4
modules/proxy/proxy_util.c

index 0f495c75002698634e7e0546618345ff2440a459..876635509c556de3a784670fbaf1ef02a503f611 100644 (file)
@@ -604,6 +604,30 @@ static const char *h2_conf_set_early_hints(cmd_parms *parms,
     return "value must be On or Off";
 }
 
+void h2_get_num_workers(server_rec *s, int *minw, int *maxw)
+{
+    int threads_per_child = 0;
+    const h2_config *config = h2_config_sget(s);
+
+    *minw = h2_config_geti(config, H2_CONF_MIN_WORKERS);
+    *maxw = h2_config_geti(config, H2_CONF_MAX_WORKERS);    
+    ap_mpm_query(AP_MPMQ_MAX_THREADS, &threads_per_child);
+
+    if (*minw <= 0) {
+        *minw = threads_per_child;
+    }
+    if (*maxw <= 0) {
+        /* As a default, this seems to work quite well under mpm_event. 
+         * For people enabling http2 under mpm_prefork, start 4 threads unless 
+         * configured otherwise. People get unhappy if their http2 requests are 
+         * blocking each other. */
+        *maxw = 3 * (*minw) / 2;
+        if (*maxw < 4) {
+            *maxw = 4;
+        }
+    }
+}
+
 #define AP_END_CMD     AP_INIT_TAKE1(NULL, NULL, NULL, RSRC_CONF, NULL)
 
 const command_rec h2_cmds[] = {
index 54f74dd40ad08fa226db65c5ef6cb9af7bbb9f7c..17d75d6035a135c5989d527c4f705c9949bdae76 100644 (file)
@@ -95,6 +95,8 @@ const h2_config *h2_config_rget(request_rec *r);
 int h2_config_geti(const h2_config *conf, h2_config_var_t var);
 apr_int64_t h2_config_geti64(const h2_config *conf, h2_config_var_t var);
 
+void h2_get_num_workers(server_rec *s, int *minw, int *maxw);
+
 void h2_config_init(apr_pool_t *pool);
 
 const struct h2_priority *h2_config_get_priority(const h2_config *conf, 
index ed07c7d2bc0ac28ac42fd90ffb22473491673f12..11f54da2582d07a7a139d4d6c039864a84a80233 100644 (file)
@@ -127,18 +127,7 @@ apr_status_t h2_conn_child_init(apr_pool_t *pool, server_rec *s)
 
     h2_config_init(pool);
     
-    minw = h2_config_geti(config, H2_CONF_MIN_WORKERS);
-    maxw = h2_config_geti(config, H2_CONF_MAX_WORKERS);    
-    if (minw <= 0) {
-        minw = max_threads_per_child;
-    }
-    if (maxw <= 0) {
-        /* As a default, this seems to work quite well under mpm_event. 
-         * For people enabling http2 under mpm_prefork, start 4 threads unless 
-         * configured otherwise. People get unhappy if their http2 requests are 
-         * blocking each other. */
-        maxw = H2MAX(3 * minw / 2, 4);
-    }
+    h2_get_num_workers(s, &minw, &maxw);
     
     idle_secs = h2_config_geti(config, H2_CONF_MAX_WORKER_IDLE_SECS);
     ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, s,
index 19b565ef0df1b9dc762d1bd5ee5503a2079700ae..86e9308f537455f0a4d5b0a206b3226fcffd2dd5 100644 (file)
@@ -193,6 +193,11 @@ static void http2_req_engine_done(h2_req_engine *ngn, conn_rec *r_conn,
     h2_mplx_req_engine_done(ngn, r_conn, status);
 }
 
+static void http2_get_num_workers(server_rec *s, int *minw, int *maxw)
+{
+    h2_get_num_workers(s, minw, maxw);
+}
+
 /* Runs once per created child process. Perform any process 
  * related initionalization here.
  */
@@ -218,6 +223,7 @@ static void h2_hooks(apr_pool_t *pool)
     APR_REGISTER_OPTIONAL_FN(http2_req_engine_push);
     APR_REGISTER_OPTIONAL_FN(http2_req_engine_pull);
     APR_REGISTER_OPTIONAL_FN(http2_req_engine_done);
+    APR_REGISTER_OPTIONAL_FN(http2_get_num_workers);
 
     ap_log_perror(APLOG_MARK, APLOG_TRACE1, 0, pool, "installing hooks");
     
index 35e141d8a98e282f851289f3a05b90c05d37f547..7a1b49a4553e0ba517ab4fa595c4dc743fafa0ac 100644 (file)
@@ -93,4 +93,9 @@ APR_DECLARE_OPTIONAL_FN(void,
                         http2_req_engine_done, (h2_req_engine *engine, 
                                                 conn_rec *rconn,
                                                 apr_status_t status));
+
+APR_DECLARE_OPTIONAL_FN(void,
+                        http2_get_num_workers, (server_rec *s,
+                                                int *minw, int *max));
+
 #endif
index ac7f34943339067f73e23e55edc8c3544967b177..d9bfd7a1cec07c43e56efb8702ddcd40a51db6a5 100644 (file)
@@ -65,7 +65,7 @@ APACHE_MODULE(serf, [Reverse proxy module using Serf], , , no, [
 APACHE_MODULE(proxy_express, mass reverse-proxy module. Requires --enable-proxy., , , most, , proxy)
 APACHE_MODULE(proxy_hcheck, [reverse-proxy health-check module. Requires --enable-proxy and --enable-watchdog.], , , most, , [proxy,watchdog])
 
-APR_ADDTO(INCLUDES, [-I\$(top_srcdir)/$modpath_current])
+APR_ADDTO(INCLUDES, [-I\$(top_srcdir)/$modpath_current -I\$(top_srcdir)/modules/http2])
 
 APACHE_MODPATH_FINISH
 
index 9260771d0f94a7de8d4fa7bd7ea0514c212c6929..0684eb24bd2b4a776adc440f749c98edbb5f85ee 100644 (file)
@@ -24,6 +24,8 @@
 #include "ajp.h"
 #include "scgi.h"
 
+#include "mod_http2.h" /* for http2_get_num_workers() */
+
 #if APR_HAVE_UNISTD_H
 #include <unistd.h>         /* for getpid() */
 #endif
@@ -1814,8 +1816,16 @@ PROXY_DECLARE(apr_status_t) ap_proxy_share_worker(proxy_worker *worker, proxy_wo
 
 PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, server_rec *s, apr_pool_t *p)
 {
+    static int have_get_h2_num_workers = 0;
+    static APR_OPTIONAL_FN_TYPE(http2_get_num_workers)
+              *get_h2_num_workers = NULL;
     apr_status_t rv = APR_SUCCESS;
-    int mpm_threads;
+    int max_threads, minw, maxw;
+
+    if (get_h2_num_workers == NULL) {
+        get_h2_num_workers = APR_RETRIEVE_OPTIONAL_FN(http2_get_num_workers);
+        have_get_h2_num_workers = (get_h2_num_workers != NULL);
+    }
 
     if (worker->s->status & PROXY_WORKER_INITIALIZED) {
         /* The worker is already initialized */
@@ -1839,15 +1849,23 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, ser
             worker->s->is_address_reusable = 1;
         }
 
-        ap_mpm_query(AP_MPMQ_MAX_THREADS, &mpm_threads);
-        if (mpm_threads > 1) {
-            /*
-             * Do not limit hmax to mpm_threads any longer as we might have
-             * more processing threads around when mod_http2 is loaded which
-             * has it's own pool of processing threads on top of this.
+        /*
+         * When mod_http2 is loaded we might have more processing threads
+         * since it has it's own pool of processing threads.
+         */
+        ap_mpm_query(AP_MPMQ_MAX_THREADS, &max_threads);
+        if (have_get_h2_num_workers) {
+            get_h2_num_workers(s, &minw, &maxw);
+            if (max_threads < maxw) {
+                max_threads = maxw;
+            }
+        }
+        if (max_threads > 1) {
+            /* Default hmax is max_threads to scale with the load and never
+             * wait for an idle connection to proceed.
              */
             if (worker->s->hmax == 0) {
-                worker->s->hmax = mpm_threads;
+                worker->s->hmax = max_threads;
             }
             if (worker->s->smax == -1 || worker->s->smax > worker->s->hmax) {
                 worker->s->smax = worker->s->hmax;