kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 79aea48757f2268fda67c35f82d4b334ccebc36f
parent 6f311a06cf64ab61689e2d5c0fd04d84b8551bf9
Author: Joris Vink <joris@coders.se>
Date:   Wed, 27 Nov 2013 23:02:15 +0100

Don't stop passing the accept lock even when workers are very busy.

If a worker reached worker_max_connections and it was its turn to
grab the accept lock it would've gotten stuck and no new connections
would be handled even if other workers would be less busy.

Instead, we now skip the lock if we're too busy and pass it along
in the hopes other workers are less busy.

Diffstat:
includes/kore.h | 1+
src/worker.c | 20++++++++++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/includes/kore.h b/includes/kore.h @@ -186,6 +186,7 @@ struct kore_worker { u_int16_t load; pid_t pid; u_int8_t has_lock; + u_int8_t busy_warn; u_int16_t accepted; u_int16_t accept_treshold; struct kore_module_handle *active_hdlr; diff --git a/src/worker.c b/src/worker.c @@ -115,6 +115,7 @@ kore_worker_spawn(u_int16_t id, u_int16_t cpu) kw->load = 0; kw->accepted = 0; kw->has_lock = 0; + kw->busy_warn = 0; kw->active_hdlr = NULL; kw->pid = fork(); @@ -232,8 +233,7 @@ kore_worker_entry(struct kore_worker *kw) sig_recv = 0; } - if (!worker->has_lock && - (worker_active_connections < worker_max_connections)) + if (!worker->has_lock) kore_worker_acceptlock_obtain(); kore_platform_event_wait(); @@ -411,8 +411,20 @@ kore_worker_acceptlock_obtain(void) } if (worker_trylock()) { - worker->has_lock = 1; - kore_platform_enable_accept(); + if (worker_active_connections >= worker_max_connections) { + worker->accepted = 0; + worker_unlock(); + + if (worker->busy_warn == 0) { + kore_log(LOG_NOTICE, + "skipping accept lock, too busy"); + worker->busy_warn = 1; + } + } else { + worker->has_lock = 1; + worker->busy_warn = 0; + kore_platform_enable_accept(); + } } }