From f945808e31e2336d14ad6f6510135d3443c836d6 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Fri, 3 May 2019 07:05:05 +0000 Subject: [PATCH] Fix "last_idle_child" lookup Currently, the "last_idle_child" is determined by looking at the starting time, that is, it is the child that has been around for the longest time. A few lines later, for pm = ondemand the idle time is computed for this last_idle_child to decide if it has been idle too long and should be terminated. To make this calculation correct, we need to find the "last_idle_child" by looking at the time of the last request served, not the startup time. --- sapi/fpm/fpm/fpm_process_ctl.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sapi/fpm/fpm/fpm_process_ctl.c b/sapi/fpm/fpm/fpm_process_ctl.c index f99ec241c74e..42f2bbc7da97 100644 --- a/sapi/fpm/fpm/fpm_process_ctl.c +++ b/sapi/fpm/fpm/fpm_process_ctl.c @@ -313,6 +313,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{ for (wp = fpm_worker_all_pools; wp; wp = wp->next) { struct fpm_child_s *child; struct fpm_child_s *last_idle_child = NULL; + struct timeval last_idle_child_activity, child_activity; int idle = 0; int active = 0; int children_to_fork; @@ -324,9 +325,12 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{ if (fpm_request_is_idle(child)) { if (last_idle_child == NULL) { last_idle_child = child; + fpm_request_last_activity(last_idle_child, &last_idle_child_activity); } else { - if (timercmp(&child->started, &last_idle_child->started, <)) { + fpm_request_last_activity(child, &child_activity); + if (timercmp(&child_activity, &last_idle_child_activity, <)) { last_idle_child = child; + last_idle_child_activity = child_activity; } } idle++; @@ -356,15 +360,14 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{ /* this is specific to PM_STYLE_ONDEMAND */ if (wp->config->pm == PM_STYLE_ONDEMAND) { - struct timeval last, now; + struct timeval now; zlog(ZLOG_DEBUG, "[pool %s] currently %d active children, %d spare children", wp->config->name, active, idle); if (!last_idle_child) continue; - fpm_request_last_activity(last_idle_child, &last); fpm_clock_get(&now); - if (last.tv_sec < now.tv_sec - wp->config->pm_process_idle_timeout) { + if (last_idle_child_activity.tv_sec < now.tv_sec - wp->config->pm_process_idle_timeout) { last_idle_child->idle_kill = 1; fpm_pctl_kill(last_idle_child->pid, FPM_PCTL_QUIT); }