From f26b9bb2c87a1179efdc8849fb140c2a2e917966 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sat, 11 Oct 2014 00:01:09 +0300 Subject: [PATCH] auth: Userdb iteration optimization. Don't keep re-creating the timeout after iterating each user. --- src/auth/auth-worker-server.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/auth/auth-worker-server.c b/src/auth/auth-worker-server.c index c7900e4ecc..c7512bf086 100644 --- a/src/auth/auth-worker-server.c +++ b/src/auth/auth-worker-server.c @@ -46,6 +46,7 @@ struct auth_worker_connection { unsigned int received_error:1; unsigned int restart:1; unsigned int shutdown:1; + unsigned int timeout_pending_resume:1; }; static ARRAY(struct auth_worker_connection *) connections = ARRAY_INIT; @@ -278,6 +279,7 @@ static bool auth_worker_request_handle(struct auth_worker_connection *conn, timeout_reset(conn->to); } else { conn->request = NULL; + conn->timeout_pending_resume = FALSE; timeout_remove(&conn->to); conn->to = timeout_add(AUTH_WORKER_MAX_IDLE_SECS * 1000, auth_worker_idle_timeout, conn); @@ -285,6 +287,7 @@ static bool auth_worker_request_handle(struct auth_worker_connection *conn, } if (!request->callback(line, request->context) && conn->io != NULL) { + conn->timeout_pending_resume = FALSE; timeout_remove(&conn->to); io_remove(&conn->io); return FALSE; @@ -411,6 +414,7 @@ static void worker_input(struct auth_worker_connection *conn) static void worker_input_resume(struct auth_worker_connection *conn) { + conn->timeout_pending_resume = FALSE; timeout_remove(&conn->to); conn->to = timeout_add(AUTH_WORKER_LOOKUP_TIMEOUT_SECS * 1000, auth_worker_call_timeout, conn); @@ -456,9 +460,12 @@ void auth_worker_server_resume_input(struct auth_worker_connection *conn) { if (conn->io == NULL) conn->io = io_add(conn->fd, IO_READ, worker_input, conn); - if (conn->to != NULL) - timeout_remove(&conn->to); - conn->to = timeout_add_short(0, worker_input_resume, conn); + if (!conn->timeout_pending_resume) { + conn->timeout_pending_resume = TRUE; + if (conn->to != NULL) + timeout_remove(&conn->to); + conn->to = timeout_add_short(0, worker_input_resume, conn); + } } void auth_worker_server_init(void) -- 2.47.3