]> granicus.if.org Git - php/commitdiff
Merging PR 121 to add support for slow request counting on the PHP-FPM status page
authorLars Strojny <lstrojny@php.net>
Sun, 26 Aug 2012 15:02:39 +0000 (17:02 +0200)
committerLars Strojny <lstrojny@php.net>
Sun, 26 Aug 2012 15:02:39 +0000 (17:02 +0200)
NEWS
sapi/fpm/fpm/fpm_php_trace.c
sapi/fpm/fpm/fpm_process_ctl.c
sapi/fpm/fpm/fpm_request.c
sapi/fpm/fpm/fpm_scoreboard.c
sapi/fpm/fpm/fpm_scoreboard.h
sapi/fpm/fpm/fpm_sockets.c
sapi/fpm/fpm/fpm_status.c

diff --git a/NEWS b/NEWS
index b7753d68dd224e16ef4971ab13f6632c69d850c9..f5b5fe05f6b724892cd7c6f5ca0d4ddebff6dde6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -57,6 +57,9 @@ PHP                                                                        NEWS
   . Fixed bug #62836 (Seg fault or broken object references on unserialize()).
     (Laruence)
 
+- FPM:
+  . Merged PR 121 by minitux to add support for slow request counting on PHP
+    FPM status page. (Lars)
 
 16 Aug 2012, PHP 5.4.6
 
index cd97aebb3347aa03e429967975665ec9c96fd3ec..d95d66a754c3eecc3115805366318519e48af072 100644 (file)
@@ -26,6 +26,7 @@
 #include "fpm_children.h"
 #include "fpm_worker_pool.h"
 #include "fpm_process_ctl.h"
+#include "fpm_scoreboard.h"
 
 #include "zlog.h"
 
@@ -137,6 +138,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog TSRMLS_DC
 void fpm_php_trace(struct fpm_child_s *child) /* {{{ */
 {
        TSRMLS_FETCH();
+       fpm_scoreboard_update(0, 0, 0, 0, 0, 0, 1, FPM_SCOREBOARD_ACTION_SET, child->wp->scoreboard);
        FILE *slowlog;
 
        zlog(ZLOG_NOTICE, "about to trace %d", (int) child->pid);
index 7840d17f8b9c58b68f4610012b29033d37d576ae..76ea4d358e67d7e6ed22af5c4bade6c3d2a7c5da 100644 (file)
@@ -353,7 +353,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{
 #endif
                        }
                }
-               fpm_scoreboard_update(idle, active, cur_lq, -1, -1, -1, FPM_SCOREBOARD_ACTION_SET, wp->scoreboard);
+               fpm_scoreboard_update(idle, active, cur_lq, -1, -1, -1, 0, FPM_SCOREBOARD_ACTION_SET, wp->scoreboard);
 
                /* this is specific to PM_STYLE_ONDEMAND */
                if (wp->config->pm == PM_STYLE_ONDEMAND) {
@@ -388,7 +388,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{
                if (idle < wp->config->pm_min_spare_servers) {
                        if (wp->running_children >= wp->config->pm_max_children) {
                                if (!wp->warn_max_children) {
-                                       fpm_scoreboard_update(0, 0, 0, 0, 0, 1, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
+                                       fpm_scoreboard_update(0, 0, 0, 0, 0, 1, 0, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
                                        zlog(ZLOG_WARNING, "[pool %s] server reached pm.max_children setting (%d), consider raising it", wp->config->name, wp->config->pm_max_children);
                                        wp->warn_max_children = 1;
                                }
@@ -407,7 +407,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{
                        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_scoreboard_update(0, 0, 0, 0, 0, 1, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
+                                       fpm_scoreboard_update(0, 0, 0, 0, 0, 1, 0, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
                                        zlog(ZLOG_WARNING, "[pool %s] server reached pm.max_children setting (%d), consider raising it", wp->config->name, wp->config->pm_max_children);
                                        wp->warn_max_children = 1;
                                }
@@ -511,7 +511,7 @@ void fpm_pctl_on_socket_accept(struct fpm_event_s *ev, short which, void *arg) /
 
        if (wp->running_children >= wp->config->pm_max_children) {
                if (!wp->warn_max_children) {
-                       fpm_scoreboard_update(0, 0, 0, 0, 0, 1, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
+                       fpm_scoreboard_update(0, 0, 0, 0, 0, 1, 0, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
                        zlog(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;
                }
index 28332d0a92621e524428662df3850baaa06ac76e..bf431a08d0366ef204b681bcb93ced888025760a 100644 (file)
@@ -54,7 +54,7 @@ void fpm_request_accepting() /* {{{ */
        fpm_scoreboard_proc_release(proc);
 
        /* idle++, active-- */
-       fpm_scoreboard_update(1, -1, 0, 0, 0, 0, FPM_SCOREBOARD_ACTION_INC, NULL);
+       fpm_scoreboard_update(1, -1, 0, 0, 0, 0, 0, FPM_SCOREBOARD_ACTION_INC, NULL);
 }
 /* }}} */
 
@@ -98,7 +98,7 @@ void fpm_request_reading_headers() /* {{{ */
        fpm_scoreboard_proc_release(proc);
 
        /* idle--, active++, request++ */
-       fpm_scoreboard_update(-1, 1, 0, 0, 1, 0, FPM_SCOREBOARD_ACTION_INC, NULL);
+       fpm_scoreboard_update(-1, 1, 0, 0, 1, 0, 0, FPM_SCOREBOARD_ACTION_INC, NULL);
 }
 /* }}} */
 
index 4222f6037c765dd83f245e05beb9ba320507b467..24463a90dddfdb739f1fef5d91e65a298e757efa 100644 (file)
@@ -73,7 +73,7 @@ int fpm_scoreboard_init_main() /* {{{ */
 }
 /* }}} */
 
-void fpm_scoreboard_update(int idle, int active, int lq, int lq_len, int requests, int max_children_reached, int action, struct fpm_scoreboard_s *scoreboard) /* {{{ */
+void fpm_scoreboard_update(int idle, int active, int lq, int lq_len, int requests, int max_children_reached, int slow_rq, int action, struct fpm_scoreboard_s *scoreboard) /* {{{ */
 {
        if (!scoreboard) {
                scoreboard = fpm_scoreboard;
@@ -110,6 +110,9 @@ void fpm_scoreboard_update(int idle, int active, int lq, int lq_len, int request
                if (max_children_reached >= 0) {
                        scoreboard->max_children_reached = max_children_reached;
                }
+               if (slow_rq > 0) {
+                       scoreboard->slow_rq += slow_rq;
+               }
        } else {
                if (scoreboard->idle + idle > 0) {
                        scoreboard->idle += idle;
index 136ea481a4a5e0970fcfe15b4a7e01d8c96672f5..f58a28737dff93d8d62c9055c103e665629a6fff 100644 (file)
@@ -64,13 +64,14 @@ struct fpm_scoreboard_s {
        unsigned int lq_len;
        unsigned int nprocs;
        int free_proc;
+       unsigned long int slow_rq;
        struct fpm_scoreboard_proc_s *procs[];
 };
 
 int fpm_scoreboard_init_main();
 int fpm_scoreboard_init_child(struct fpm_worker_pool_s *wp);
 
-void fpm_scoreboard_update(int idle, int active, int lq, int lq_len, int requests, int max_children_reached, int action, struct fpm_scoreboard_s *scoreboard);
+void fpm_scoreboard_update(int idle, int active, int lq, int lq_len, int requests, int max_children_reached, int slow_rq, int action, struct fpm_scoreboard_s *scoreboard);
 struct fpm_scoreboard_s *fpm_scoreboard_get();
 struct fpm_scoreboard_proc_s *fpm_scoreboard_proc_get(struct fpm_scoreboard_s *scoreboard, int child_index);
 
index f56b9cfbd1493c453322acd03f7ccf885ca35443..76759e7f25bf675cef461679303872cf88a8b505 100644 (file)
@@ -356,7 +356,7 @@ int fpm_sockets_init_main() /* {{{ */
                }
 
        if (wp->listen_address_domain == FPM_AF_INET && fpm_socket_get_listening_queue(wp->listening_socket, NULL, &lq_len) >= 0) {
-                       fpm_scoreboard_update(-1, -1, -1, (int)lq_len, -1, -1, FPM_SCOREBOARD_ACTION_SET, wp->scoreboard);
+                       fpm_scoreboard_update(-1, -1, -1, (int)lq_len, -1, -1, 0, FPM_SCOREBOARD_ACTION_SET, wp->scoreboard);
                }
        }
 
index 5f2c852c7d78748f2fc67cd84f562818f46a8786..b9b9a8c0b6f1bfc7a2377c1d481b8458d46cee54 100644 (file)
@@ -158,6 +158,7 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */
                                        "<tr><th>total processes</th><td>%d</td></tr>\n"
                                        "<tr><th>max active processes</th><td>%d</td></tr>\n"
                                        "<tr><th>max children reached</th><td>%u</td></tr>\n"
+                                       "<tr><th>slow requests</th><td>%lu</td></tr>\n"
                                "</table>\n";
 
                        if (!full) {
@@ -228,7 +229,8 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */
                                "<active-processes>%d</active-processes>\n"
                                "<total-processes>%d</total-processes>\n"
                                "<max-active-processes>%d</max-active-processes>\n"
-                               "<max-children-reached>%u</max-children-reached>\n";
+                               "<max-children-reached>%u</max-children-reached>\n"
+                               "<slow-requests>%lu</slow-requests>\n";
 
                                if (!full) {
                                        short_post = "</status>";
@@ -277,7 +279,8 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */
                                "\"active processes\":%d,"
                                "\"total processes\":%d,"
                                "\"max active processes\":%d,"
-                               "\"max children reached\":%u";
+                               "\"max children reached\":%u,"
+                               "\"slow requests\":%lu";
 
                        if (!full) {
                                short_post = "}";
@@ -326,7 +329,8 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */
                                "active processes:     %d\n"
                                "total processes:      %d\n"
                                "max active processes: %d\n"
-                               "max children reached: %u\n";
+                               "max children reached: %u\n"
+                               "slow requests:        %lu\n";
 
                                if (full) {
                                        full_syntax =
@@ -367,7 +371,8 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */
                                scoreboard.active,
                                scoreboard.idle + scoreboard.active,
                                scoreboard.active_max,
-                               scoreboard.max_children_reached);
+                               scoreboard.max_children_reached,
+                               scoreboard.slow_rq);
 
                PUTS(buffer);
                efree(buffer);