From: Stefan Eissing Date: Fri, 11 Dec 2015 17:43:04 +0000 (+0000) Subject: fixed worker number by default, worker pool reuse experiments, allocatory max_free set X-Git-Tag: 2.5.0-alpha~2542 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=edef94e40a50bc5fdfe76d4f39c88d48872d3089;p=apache fixed worker number by default, worker pool reuse experiments, allocatory max_free set git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1719479 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/http2/h2_conn.c b/modules/http2/h2_conn.c index 8d14b09c7c..9216c230e7 100644 --- a/modules/http2/h2_conn.c +++ b/modules/http2/h2_conn.c @@ -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); diff --git a/modules/http2/h2_conn_io.c b/modules/http2/h2_conn_io.c index a67d025fa8..21428da078 100644 --- a/modules/http2/h2_conn_io.c +++ b/modules/http2/h2_conn_io.c @@ -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)) { diff --git a/modules/http2/h2_worker.c b/modules/http2/h2_worker.c index 3119cb081e..a42f246ef9 100644 --- a/modules/http2/h2_worker.c +++ b/modules/http2/h2_worker.c @@ -17,6 +17,7 @@ #include +#include #include #include #include @@ -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) diff --git a/modules/http2/h2_worker.h b/modules/http2/h2_worker.h index 035448e5db..43a7293097 100644 --- a/modules/http2/h2_worker.h +++ b/modules/http2/h2_worker.h @@ -54,6 +54,7 @@ struct h2_worker { void *ctx; int aborted; + int pool_reuses; struct h2_task *task; }; diff --git a/modules/http2/h2_workers.c b/modules/http2/h2_workers.c index 3c08ff35d1..9371eebcf2 100644 --- a/modules/http2/h2_workers.c +++ b/modules/http2/h2_workers.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -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);