]> granicus.if.org Git - apache/commitdiff
fixed worker number by default, worker pool reuse experiments, allocatory max_free set
authorStefan Eissing <icing@apache.org>
Fri, 11 Dec 2015 17:43:04 +0000 (17:43 +0000)
committerStefan Eissing <icing@apache.org>
Fri, 11 Dec 2015 17:43:04 +0000 (17:43 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1719479 13f79535-47bb-0310-9956-ffa450edef68

modules/http2/h2_conn.c
modules/http2/h2_conn_io.c
modules/http2/h2_worker.c
modules/http2/h2_worker.h
modules/http2/h2_workers.c

index 8d14b09c7cf00627615ecc67630c8f9bfb6827be..9216c230e76fc1fa460eae37c924a52b19a0c874 100644 (file)
@@ -75,14 +75,12 @@ apr_status_t h2_conn_child_init(apr_pool_t *pool, server_rec *s)
     int maxw = h2_config_geti(config, H2_CONF_MAX_WORKERS);
     
     int max_threads_per_child = 0;
-    int threads_limit = 0;
     int idle_secs = 0;
     int i;
 
     h2_config_init(pool);
     
     ap_mpm_query(AP_MPMQ_MAX_THREADS, &max_threads_per_child);
-    ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &threads_limit);
     
     for (i = 0; ap_loaded_modules[i]; ++i) {
         module *m = ap_loaded_modules[i];
@@ -104,15 +102,12 @@ apr_status_t h2_conn_child_init(apr_pool_t *pool, server_rec *s)
         minw = max_threads_per_child;
     }
     if (maxw <= 0) {
-        maxw = threads_limit;
-        if (maxw < minw) {
-            maxw = minw;
-        }
+        maxw = minw;
     }
     
     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
-                 "h2_workers: min=%d max=%d, mthrpchild=%d, thr_limit=%d", 
-                 minw, maxw, max_threads_per_child, threads_limit);
+                 "h2_workers: min=%d max=%d, mthrpchild=%d", 
+                 minw, maxw, max_threads_per_child);
     
     workers = h2_workers_create(s, pool, minw, maxw);
     idle_secs = h2_config_geti(config, H2_CONF_MAX_WORKER_IDLE_SECS);
index a67d025fa883c299f3afd8ee08e583ff01de5847..21428da078cf67dd5e1be64a7c2a439df8d3b4af 100644 (file)
@@ -102,8 +102,7 @@ static apr_status_t h2_conn_io_bucket_read(h2_conn_io *io,
     apr_size_t readlen = 0;
     *pdone = 0;
     
-    while (status == APR_SUCCESS && !*pdone
-           && !APR_BRIGADE_EMPTY(io->input)) {
+    while (status == APR_SUCCESS && !*pdone && !APR_BRIGADE_EMPTY(io->input)) {
         
         apr_bucket* bucket = APR_BRIGADE_FIRST(io->input);
         if (APR_BUCKET_IS_METADATA(bucket)) {
index 3119cb081eed0b279a255f93d2b1814c2b402948..a42f246ef913bbf634136a76d9fa97bcefed19bd 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <apr_thread_cond.h>
 
+#include <mpm_common.h>
 #include <httpd.h>
 #include <http_core.h>
 #include <http_log.h>
@@ -61,8 +62,11 @@ static void* APR_THREAD_FUNC execute(apr_thread_t *thread, void *wctx)
         }
     }
 
-    status = worker->get_next(worker, &m, NULL, worker->ctx);
-    m = NULL;
+    if (m) {
+        /* Hand "m" back to other workers */
+        status = worker->get_next(worker, &m, NULL, worker->ctx);
+        m = NULL;
+    }
     
     if (worker->socket) {
         apr_socket_close(worker->socket);
@@ -98,15 +102,9 @@ h2_worker *h2_worker_create(int id,
     h2_worker *w;
     apr_status_t status;
     
-    status = apr_allocator_create(&allocator);
-    if (status != APR_SUCCESS) {
-        return NULL;
-    }
-    
-    status = apr_pool_create_ex(&pool, parent_pool, NULL, allocator);
-    if (status != APR_SUCCESS) {
-        return NULL;
-    }
+    apr_allocator_create(&allocator);
+    apr_allocator_max_free_set(allocator, ap_max_mem_free);
+    apr_pool_create_ex(&pool, parent_pool, NULL, allocator);
     apr_allocator_owner_set(allocator, pool);
 
     w = apr_pcalloc(pool, sizeof(h2_worker));
@@ -169,6 +167,7 @@ h2_task *h2_worker_create_task(h2_worker *worker, h2_mplx *m,
      */
     if (!worker->task_pool) {
         apr_pool_create(&worker->task_pool, worker->pool);
+        worker->pool_reuses = 100;
     }
     task = h2_task_create(m->id, req, worker->task_pool, m, eos);
     
@@ -193,7 +192,13 @@ void h2_worker_release_task(h2_worker *worker, struct h2_task *task)
 {
     task->io = NULL;
     task->pool = NULL;
-    apr_pool_clear(worker->task_pool);
+    if (worker->pool_reuses-- <= 0) {
+        apr_pool_destroy(worker->task_pool);
+        worker->task_pool = NULL;
+    }
+    else {
+        apr_pool_clear(worker->task_pool);
+    }
 }
 
 apr_socket_t *h2_worker_get_socket(h2_worker *worker)
index 035448e5dbbcf24c35d4c6ce505ac8233d507d35..43a729309773139472242bfcb37a00e81cb2ffe0 100644 (file)
@@ -54,6 +54,7 @@ struct h2_worker {
     void *ctx;
     
     int aborted;
+    int pool_reuses;
     struct h2_task *task;
 };
 
index 3c08ff35d1cf34b5c5efc2bb053235ef2d775776..9371eebcf2c8775f61e208850bada61d4cf22efa 100644 (file)
@@ -18,6 +18,7 @@
 #include <apr_thread_mutex.h>
 #include <apr_thread_cond.h>
 
+#include <mpm_common.h>
 #include <httpd.h>
 #include <http_core.h>
 #include <http_log.h>
@@ -271,6 +272,14 @@ h2_workers *h2_workers_create(server_rec *s, apr_pool_t *server_pool,
         apr_atomic_set32(&workers->max_idle_secs, 10);
         
         apr_threadattr_create(&workers->thread_attr, workers->pool);
+        apr_threadattr_detach_set(workers->thread_attr, 0);
+        if (ap_thread_stacksize != 0) {
+            apr_threadattr_stacksize_set(workers->thread_attr,
+                                         ap_thread_stacksize);
+            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
+                         "h2_workers: using stacksize=%ld", 
+                         (long)ap_thread_stacksize);
+        }
         
         APR_RING_INIT(&workers->workers, h2_worker, link);
         APR_RING_INIT(&workers->zombies, h2_worker, link);