Get rid of WORKER_LOCK_TIMEOUT.

Instead let the workers send a message on the msg channel to each
other when they have given up the accept lock and it is now available
to be grabbed.
This commit is contained in:
Joris Vink 2019-03-21 14:03:11 +01:00
parent 8b0279879a
commit 370041656e
2 changed files with 25 additions and 19 deletions

View File

@ -498,6 +498,7 @@ struct kore_timer {
#define KORE_MSG_CERTIFICATE 7 #define KORE_MSG_CERTIFICATE 7
#define KORE_MSG_CERTIFICATE_REQ 8 #define KORE_MSG_CERTIFICATE_REQ 8
#define KORE_MSG_CRL 9 #define KORE_MSG_CRL 9
#define KORE_MSG_ACCEPT_AVAILABLE 10
/* Predefined message targets. */ /* Predefined message targets. */
#define KORE_MSG_PARENT 1000 #define KORE_MSG_PARENT 1000

View File

@ -53,8 +53,6 @@
#define WAIT_ANY (-1) #define WAIT_ANY (-1)
#endif #endif
#define WORKER_LOCK_TIMEOUT 100
#if !defined(KORE_NO_TLS) #if !defined(KORE_NO_TLS)
#define WORKER_SOLO_COUNT 2 #define WORKER_SOLO_COUNT 2
#else #else
@ -74,7 +72,8 @@ static int worker_trylock(void);
static void worker_unlock(void); static void worker_unlock(void);
static inline int worker_acceptlock_obtain(void); static inline int worker_acceptlock_obtain(void);
static inline int worker_acceptlock_release(void); static inline void worker_acceptlock_release(void);
static void worker_accept_avail(struct kore_msg *, const void *);
#if !defined(KORE_NO_TLS) #if !defined(KORE_NO_TLS)
static void worker_entropy_recv(struct kore_msg *, const void *); static void worker_entropy_recv(struct kore_msg *, const void *);
@ -83,7 +82,7 @@ static int worker_keymgr_response_verify(struct kore_msg *, const void *,
struct kore_domain **); struct kore_domain **);
#endif #endif
static u_int64_t next_lock; static int accept_avail;
static struct kore_worker *kore_workers; static struct kore_worker *kore_workers;
static int worker_no_lock; static int worker_no_lock;
static int shm_accept_key; static int shm_accept_key;
@ -353,8 +352,8 @@ kore_worker_entry(struct kore_worker *kw)
quit = 0; quit = 0;
had_lock = 0; had_lock = 0;
next_lock = 0;
next_prune = 0; next_prune = 0;
accept_avail = 1;
worker_active_connections = 0; worker_active_connections = 0;
#if defined(KORE_USE_PGSQL) #if defined(KORE_USE_PGSQL)
@ -376,6 +375,8 @@ kore_worker_entry(struct kore_worker *kw)
} }
#endif #endif
kore_msg_register(KORE_MSG_ACCEPT_AVAILABLE, worker_accept_avail);
if (nlisteners == 0) if (nlisteners == 0)
worker_no_lock = 1; worker_no_lock = 1;
@ -405,14 +406,13 @@ kore_worker_entry(struct kore_worker *kw)
} }
#endif #endif
if (!worker->has_lock && next_lock <= now) { if (!worker->has_lock && accept_avail) {
accept_avail = 0;
if (worker_acceptlock_obtain()) { if (worker_acceptlock_obtain()) {
if (had_lock == 0) { if (had_lock == 0) {
kore_platform_enable_accept(); kore_platform_enable_accept();
had_lock = 1; had_lock = 1;
} }
} else {
next_lock = now + WORKER_LOCK_TIMEOUT / 2;
} }
} }
@ -420,10 +420,8 @@ kore_worker_entry(struct kore_worker *kw)
kore_platform_event_wait(netwait); kore_platform_event_wait(netwait);
now = kore_time_ms(); now = kore_time_ms();
if (worker->has_lock) { if (worker->has_lock)
if (worker_acceptlock_release()) worker_acceptlock_release();
next_lock = now + WORKER_LOCK_TIMEOUT;
}
if (!worker->has_lock) { if (!worker->has_lock) {
if (had_lock == 1) { if (had_lock == 1) {
@ -600,25 +598,26 @@ kore_worker_make_busy(void)
if (worker->has_lock) { if (worker->has_lock) {
worker_unlock(); worker_unlock();
worker->has_lock = 0; worker->has_lock = 0;
next_lock = kore_time_ms() + WORKER_LOCK_TIMEOUT; kore_msg_send(KORE_MSG_WORKER_ALL,
KORE_MSG_ACCEPT_AVAILABLE, NULL, 0);
} }
} }
static inline int static inline void
worker_acceptlock_release(void) worker_acceptlock_release(void)
{ {
if (worker_count == WORKER_SOLO_COUNT || worker_no_lock == 1) if (worker_count == WORKER_SOLO_COUNT || worker_no_lock == 1)
return (0); return;
if (worker->has_lock != 1) if (worker->has_lock != 1)
return (0); return;
if (worker_active_connections < worker_max_connections) { if (worker_active_connections < worker_max_connections) {
#if !defined(KORE_NO_HTTP) #if !defined(KORE_NO_HTTP)
if (http_request_count < http_request_limit) if (http_request_count < http_request_limit)
return (0); return;
#else #else
return (0); return;
#endif #endif
} }
@ -629,7 +628,7 @@ worker_acceptlock_release(void)
worker_unlock(); worker_unlock();
worker->has_lock = 0; worker->has_lock = 0;
return (1); kore_msg_send(KORE_MSG_WORKER_ALL, KORE_MSG_ACCEPT_AVAILABLE, NULL, 0);
} }
static inline int static inline int
@ -684,6 +683,12 @@ worker_unlock(void)
kore_log(LOG_NOTICE, "worker_unlock(): wasnt locked"); kore_log(LOG_NOTICE, "worker_unlock(): wasnt locked");
} }
static void
worker_accept_avail(struct kore_msg *msg, const void *data)
{
accept_avail = 1;
}
#if !defined(KORE_NO_TLS) #if !defined(KORE_NO_TLS)
static void static void
worker_entropy_recv(struct kore_msg *msg, const void *data) worker_entropy_recv(struct kore_msg *msg, const void *data)