From 4d62c8c5014b4ad72cfcd535dcfd1ab164fe8034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Loyet?= Date: Tue, 31 Aug 2010 14:49:16 +0000 Subject: [PATCH] - add 'max children reached' to the FPM status page. It shows how many times a pool has reached the max_children parameter. --- sapi/fpm/fpm/fpm_conf.c | 1 + sapi/fpm/fpm/fpm_process_ctl.c | 2 ++ sapi/fpm/fpm/fpm_status.c | 57 ++++++++++++++++++++++++++++------ sapi/fpm/fpm/fpm_status.h | 3 ++ sapi/fpm/php-fpm.conf.in | 28 ++++++++++------- 5 files changed, 69 insertions(+), 22 deletions(-) diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c index 4c7e6d618cf..7d25a044fae 100644 --- a/sapi/fpm/fpm/fpm_conf.c +++ b/sapi/fpm/fpm/fpm_conf.c @@ -574,6 +574,7 @@ static int fpm_conf_process_all_pools() /* {{{ */ } fpm_status_update_accepted_conn(wp->shm_status, 0); fpm_status_update_activity(wp->shm_status, -1, -1, -1, 1); + fpm_status_update_max_children_reached(wp->shm_status, 0); fpm_status_set_pm(wp->shm_status, wp->config->pm); /* memset(&fpm_status.last_update, 0, sizeof(fpm_status.last_update)); */ } diff --git a/sapi/fpm/fpm/fpm_process_ctl.c b/sapi/fpm/fpm/fpm_process_ctl.c index 573a596a355..d4639b08636 100644 --- a/sapi/fpm/fpm/fpm_process_ctl.c +++ b/sapi/fpm/fpm/fpm_process_ctl.c @@ -366,6 +366,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now, struct if (idle < wp->config->pm_min_spare_servers) { if (wp->running_children >= wp->config->pm_max_children) { if (!wp->warn_max_children) { + fpm_status_increment_max_children_reached(wp->shm_status); zlog(ZLOG_STUFF, ZLOG_WARNING, "[pool %s] server reached max_children setting (%d), consider raising it", wp->config->name, wp->config->pm_max_children); wp->warn_max_children = 1; } @@ -384,6 +385,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now, struct children_to_fork = MIN(children_to_fork, wp->config->pm_max_children - wp->running_children); if (children_to_fork <= 0) { if (!wp->warn_max_children) { + fpm_status_increment_max_children_reached(wp->shm_status); zlog(ZLOG_STUFF, ZLOG_WARNING, "[pool %s] server reached max_children setting (%d), consider raising it", wp->config->name, wp->config->pm_max_children); wp->warn_max_children = 1; } diff --git a/sapi/fpm/fpm/fpm_status.c b/sapi/fpm/fpm/fpm_status.c index 50efaf8df12..19285b193da 100644 --- a/sapi/fpm/fpm/fpm_status.c +++ b/sapi/fpm/fpm/fpm_status.c @@ -99,6 +99,40 @@ void fpm_status_update_accepted_conn(struct fpm_shm_s *shm, unsigned long int ac } /* }}} */ +void fpm_status_increment_max_children_reached(struct fpm_shm_s *shm) /* {{{ */ +{ + struct fpm_status_s status; + + if (!shm) shm = fpm_status_shm; + if (!shm || !shm->mem) return; + + /* one shot operation */ + status = *(struct fpm_status_s *)shm->mem; + + status.max_children_reached++; + + /* one shot operation */ + *(struct fpm_status_s *)shm->mem = status; +} +/* }}} */ + +void fpm_status_update_max_children_reached(struct fpm_shm_s *shm, unsigned int max_children_reached) /* {{{ */ +{ + struct fpm_status_s status; + + if (!shm) shm = fpm_status_shm; + if (!shm || !shm->mem) return; + + /* one shot operation */ + status = *(struct fpm_status_s *)shm->mem; + + status.max_children_reached = max_children_reached; + + /* one shot operation */ + *(struct fpm_status_s *)shm->mem = status; +} +/* }}} */ + void fpm_status_update_activity(struct fpm_shm_s *shm, int idle, int active, int total, int clear_last_update) /* {{{ */ { struct fpm_status_s status; @@ -130,13 +164,14 @@ static void fpm_status_handle_status_txt(struct fpm_status_s *status, char **out } spprintf(output, 0, - "accepted conn: %lu\n" - "pool: %s\n" - "process manager: %s\n" - "idle processes: %d\n" - "active processes: %d\n" - "total processes: %d\n", - status->accepted_conn, fpm_status_pool, status->pm == PM_STYLE_STATIC ? "static" : "dynamic", status->idle, status->active, status->total); + "accepted conn: %lu\n" + "pool: %s\n" + "process manager: %s\n" + "idle processes: %d\n" + "active processes: %d\n" + "total processes: %d\n" + "max children reached: %u\n", + status->accepted_conn, fpm_status_pool, status->pm == PM_STYLE_STATIC ? "static" : "dynamic", status->idle, status->active, status->total, status->max_children_reached); spprintf(content_type, 0, "Content-Type: text/plain"); } @@ -156,8 +191,9 @@ static void fpm_status_handle_status_html(struct fpm_status_s *status, char **ou "idle processes%d\n" "active processes%d\n" "total processes%d\n" + "max children reached%u\n" "", - status->accepted_conn, fpm_status_pool, status->pm == PM_STYLE_STATIC ? "static" : "dynamic", status->idle, status->active, status->total); + status->accepted_conn, fpm_status_pool, status->pm == PM_STYLE_STATIC ? "static" : "dynamic", status->idle, status->active, status->total, status->max_children_reached); spprintf(content_type, 0, "Content-Type: text/html"); } @@ -176,9 +212,10 @@ static void fpm_status_handle_status_json(struct fpm_status_s *status, char **ou "\"process manager\":\"%s\"," "\"idle processes\":%d," "\"active processes\":%d," - "\"total processes\":%d" + "\"total processes\":%d," + "\"max children reached\":%u" "}", - status->accepted_conn, fpm_status_pool, status->pm == PM_STYLE_STATIC ? "static" : "dynamic", status->idle, status->active, status->total); + status->accepted_conn, fpm_status_pool, status->pm == PM_STYLE_STATIC ? "static" : "dynamic", status->idle, status->active, status->total, status->max_children_reached); spprintf(content_type, 0, "Content-Type: application/json"); } diff --git a/sapi/fpm/fpm/fpm_status.h b/sapi/fpm/fpm/fpm_status.h index 368fc2cb517..e081f5eeb03 100644 --- a/sapi/fpm/fpm/fpm_status.h +++ b/sapi/fpm/fpm/fpm_status.h @@ -15,6 +15,7 @@ struct fpm_status_s { int active; int total; unsigned long int accepted_conn; + unsigned int max_children_reached; struct timeval last_update; }; @@ -23,6 +24,8 @@ void fpm_status_update_activity(struct fpm_shm_s *shm, int idle, int active, int void fpm_status_update_accepted_conn(struct fpm_shm_s *shm, unsigned long int accepted_conn); void fpm_status_increment_accepted_conn(struct fpm_shm_s *shm); void fpm_status_set_pm(struct fpm_shm_s *shm, int pm); +void fpm_status_update_max_children_reached(struct fpm_shm_s *shm, unsigned int max_children_reached); +void fpm_status_increment_max_children_reached(struct fpm_shm_s *shm); int fpm_status_handle_status(char *uri, char *query_string, char **output, char **content_type); char* fpm_status_handle_ping(char *uri); diff --git a/sapi/fpm/php-fpm.conf.in b/sapi/fpm/php-fpm.conf.in index d3bc7eacd75..ccf864a5e80 100644 --- a/sapi/fpm/php-fpm.conf.in +++ b/sapi/fpm/php-fpm.conf.in @@ -154,21 +154,25 @@ pm.max_children = 50 ; The URI to view the FPM status page. If this value is not set, no URI will be ; recognized as a status page. By default, the status page shows the following ; information: -; accepted conn - the number of request accepted by the pool; -; pool - the name of the pool; -; process manager - static or dynamic; -; idle processes - the number of idle processes; -; active processes - the number of active processes; -; total processes - the number of idle + active processes. +; accepted conn - the number of request accepted by the pool; +; pool - the name of the pool; +; process manager - static or dynamic; +; idle processes - the number of idle processes; +; active processes - the number of active processes; +; total processes - the number of idle + active processes. +; max children reached - number of times, the process limit has been reached, +; when pm tries to start more children (works only for +; pm 'dynamic') ; The values of 'idle processes', 'active processes' and 'total processes' are ; updated each second. The value of 'accepted conn' is updated in real time. ; Example output: -; accepted conn: 12073 -; pool: www -; process manager: static -; idle processes: 35 -; active processes: 65 -; total processes: 100 +; accepted conn: 12073 +; pool: www +; process manager: static +; idle processes: 35 +; active processes: 65 +; total processes: 100 +; max children reached: 1 ; By default the status page output is formatted as text/plain. Passing either ; 'html' or 'json' as a query string will return the corresponding output ; syntax. Example: