From 91f20fb595be152976f23a8456264d15c8ec6dcd Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 23 Mar 2023 16:36:10 +0200 Subject: [PATCH] master: Add service.process_idling to count number of idling processes --- src/master/service-monitor.c | 4 ++++ src/master/service-process.c | 3 +++ src/master/service.h | 2 ++ 3 files changed, 9 insertions(+) diff --git a/src/master/service-monitor.c b/src/master/service-monitor.c index b0a7a26f3a..05abfee898 100644 --- a/src/master/service-monitor.c +++ b/src/master/service-monitor.c @@ -73,6 +73,9 @@ static void service_status_more(struct service_process *process, &service->idle_processes_tail, process); DLLIST_PREPEND(&service->busy_processes, process); process->idle_start = 0; + + i_assert(service->process_idling > 0); + service->process_idling--; } process->total_count += process->available_count - status->available_count; @@ -106,6 +109,7 @@ static void service_check_idle(struct service_process *process) if (process->idle_start == 0) { /* busy process started idling */ DLLIST_REMOVE(&service->busy_processes, process); + service->process_idling++; } else { /* Idling process updated its status again to be idling. Maybe it was busy for a little bit? Update its idle_start time. */ diff --git a/src/master/service-process.c b/src/master/service-process.c index cf0fd14716..41c60b8e45 100644 --- a/src/master/service-process.c +++ b/src/master/service-process.c @@ -433,6 +433,7 @@ struct service_process *service_process_create(struct service *service) service->process_count_total++; service->process_count++; service->process_avail++; + service->process_idling++; DLLIST2_APPEND(&service->idle_processes_head, &service->idle_processes_tail, process); @@ -467,6 +468,8 @@ void service_process_destroy(struct service_process *process) else { DLLIST2_REMOVE(&service->idle_processes_head, &service->idle_processes_tail, process); + i_assert(service->process_idling > 0); + service->process_idling--; } hash_table_remove(service_pids, POINTER_CAST(process->pid)); diff --git a/src/master/service.h b/src/master/service.h index 87bcf9db3e..2f565a7f44 100644 --- a/src/master/service.h +++ b/src/master/service.h @@ -72,6 +72,8 @@ struct service { unsigned int process_count; /* number of processes currently accepting new clients */ unsigned int process_avail; + /* number of processes currently idling (idle_start != 0) */ + unsigned int process_idling; /* max number of processes allowed */ unsigned int process_limit; /* Total number of processes ever created */ -- 2.47.3