Skip to content

Commit 8e7081f

Browse files
committed
Merging PR 121 to add support for slow request counting on the PHP-FPM status page
1 parent e24194d commit 8e7081f

8 files changed

+27
-13
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ PHP NEWS
5757
. Fixed bug #62836 (Seg fault or broken object references on unserialize()).
5858
(Laruence)
5959

60+
- FPM:
61+
. Merged PR 121 by minitux to add support for slow request counting on PHP
62+
FPM status page. (Lars)
6063

6164
16 Aug 2012, PHP 5.4.6
6265

sapi/fpm/fpm/fpm_php_trace.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "fpm_children.h"
2727
#include "fpm_worker_pool.h"
2828
#include "fpm_process_ctl.h"
29+
#include "fpm_scoreboard.h"
2930

3031
#include "zlog.h"
3132

@@ -137,6 +138,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog TSRMLS_DC
137138
void fpm_php_trace(struct fpm_child_s *child) /* {{{ */
138139
{
139140
TSRMLS_FETCH();
141+
fpm_scoreboard_update(0, 0, 0, 0, 0, 0, 1, FPM_SCOREBOARD_ACTION_SET, child->wp->scoreboard);
140142
FILE *slowlog;
141143

142144
zlog(ZLOG_NOTICE, "about to trace %d", (int) child->pid);

sapi/fpm/fpm/fpm_process_ctl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{
353353
#endif
354354
}
355355
}
356-
fpm_scoreboard_update(idle, active, cur_lq, -1, -1, -1, FPM_SCOREBOARD_ACTION_SET, wp->scoreboard);
356+
fpm_scoreboard_update(idle, active, cur_lq, -1, -1, -1, 0, FPM_SCOREBOARD_ACTION_SET, wp->scoreboard);
357357

358358
/* this is specific to PM_STYLE_ONDEMAND */
359359
if (wp->config->pm == PM_STYLE_ONDEMAND) {
@@ -388,7 +388,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{
388388
if (idle < wp->config->pm_min_spare_servers) {
389389
if (wp->running_children >= wp->config->pm_max_children) {
390390
if (!wp->warn_max_children) {
391-
fpm_scoreboard_update(0, 0, 0, 0, 0, 1, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
391+
fpm_scoreboard_update(0, 0, 0, 0, 0, 1, 0, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
392392
zlog(ZLOG_WARNING, "[pool %s] server reached pm.max_children setting (%d), consider raising it", wp->config->name, wp->config->pm_max_children);
393393
wp->warn_max_children = 1;
394394
}
@@ -407,7 +407,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{
407407
children_to_fork = MIN(children_to_fork, wp->config->pm_max_children - wp->running_children);
408408
if (children_to_fork <= 0) {
409409
if (!wp->warn_max_children) {
410-
fpm_scoreboard_update(0, 0, 0, 0, 0, 1, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
410+
fpm_scoreboard_update(0, 0, 0, 0, 0, 1, 0, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
411411
zlog(ZLOG_WARNING, "[pool %s] server reached pm.max_children setting (%d), consider raising it", wp->config->name, wp->config->pm_max_children);
412412
wp->warn_max_children = 1;
413413
}
@@ -511,7 +511,7 @@ void fpm_pctl_on_socket_accept(struct fpm_event_s *ev, short which, void *arg) /
511511

512512
if (wp->running_children >= wp->config->pm_max_children) {
513513
if (!wp->warn_max_children) {
514-
fpm_scoreboard_update(0, 0, 0, 0, 0, 1, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
514+
fpm_scoreboard_update(0, 0, 0, 0, 0, 1, 0, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
515515
zlog(ZLOG_WARNING, "[pool %s] server reached max_children setting (%d), consider raising it", wp->config->name, wp->config->pm_max_children);
516516
wp->warn_max_children = 1;
517517
}

sapi/fpm/fpm/fpm_request.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void fpm_request_accepting() /* {{{ */
5454
fpm_scoreboard_proc_release(proc);
5555

5656
/* idle++, active-- */
57-
fpm_scoreboard_update(1, -1, 0, 0, 0, 0, FPM_SCOREBOARD_ACTION_INC, NULL);
57+
fpm_scoreboard_update(1, -1, 0, 0, 0, 0, 0, FPM_SCOREBOARD_ACTION_INC, NULL);
5858
}
5959
/* }}} */
6060

@@ -98,7 +98,7 @@ void fpm_request_reading_headers() /* {{{ */
9898
fpm_scoreboard_proc_release(proc);
9999

100100
/* idle--, active++, request++ */
101-
fpm_scoreboard_update(-1, 1, 0, 0, 1, 0, FPM_SCOREBOARD_ACTION_INC, NULL);
101+
fpm_scoreboard_update(-1, 1, 0, 0, 1, 0, 0, FPM_SCOREBOARD_ACTION_INC, NULL);
102102
}
103103
/* }}} */
104104

sapi/fpm/fpm/fpm_scoreboard.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int fpm_scoreboard_init_main() /* {{{ */
7373
}
7474
/* }}} */
7575

76-
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) /* {{{ */
76+
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) /* {{{ */
7777
{
7878
if (!scoreboard) {
7979
scoreboard = fpm_scoreboard;
@@ -110,6 +110,9 @@ void fpm_scoreboard_update(int idle, int active, int lq, int lq_len, int request
110110
if (max_children_reached >= 0) {
111111
scoreboard->max_children_reached = max_children_reached;
112112
}
113+
if (slow_rq > 0) {
114+
scoreboard->slow_rq += slow_rq;
115+
}
113116
} else {
114117
if (scoreboard->idle + idle > 0) {
115118
scoreboard->idle += idle;

sapi/fpm/fpm/fpm_scoreboard.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ struct fpm_scoreboard_s {
6464
unsigned int lq_len;
6565
unsigned int nprocs;
6666
int free_proc;
67+
unsigned long int slow_rq;
6768
struct fpm_scoreboard_proc_s *procs[];
6869
};
6970

7071
int fpm_scoreboard_init_main();
7172
int fpm_scoreboard_init_child(struct fpm_worker_pool_s *wp);
7273

73-
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);
74+
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);
7475
struct fpm_scoreboard_s *fpm_scoreboard_get();
7576
struct fpm_scoreboard_proc_s *fpm_scoreboard_proc_get(struct fpm_scoreboard_s *scoreboard, int child_index);
7677

sapi/fpm/fpm/fpm_sockets.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ int fpm_sockets_init_main() /* {{{ */
356356
}
357357

358358
if (wp->listen_address_domain == FPM_AF_INET && fpm_socket_get_listening_queue(wp->listening_socket, NULL, &lq_len) >= 0) {
359-
fpm_scoreboard_update(-1, -1, -1, (int)lq_len, -1, -1, FPM_SCOREBOARD_ACTION_SET, wp->scoreboard);
359+
fpm_scoreboard_update(-1, -1, -1, (int)lq_len, -1, -1, 0, FPM_SCOREBOARD_ACTION_SET, wp->scoreboard);
360360
}
361361
}
362362

sapi/fpm/fpm/fpm_status.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */
158158
"<tr><th>total processes</th><td>%d</td></tr>\n"
159159
"<tr><th>max active processes</th><td>%d</td></tr>\n"
160160
"<tr><th>max children reached</th><td>%u</td></tr>\n"
161+
"<tr><th>slow requests</th><td>%lu</td></tr>\n"
161162
"</table>\n";
162163

163164
if (!full) {
@@ -228,7 +229,8 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */
228229
"<active-processes>%d</active-processes>\n"
229230
"<total-processes>%d</total-processes>\n"
230231
"<max-active-processes>%d</max-active-processes>\n"
231-
"<max-children-reached>%u</max-children-reached>\n";
232+
"<max-children-reached>%u</max-children-reached>\n"
233+
"<slow-requests>%lu</slow-requests>\n";
232234

233235
if (!full) {
234236
short_post = "</status>";
@@ -277,7 +279,8 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */
277279
"\"active processes\":%d,"
278280
"\"total processes\":%d,"
279281
"\"max active processes\":%d,"
280-
"\"max children reached\":%u";
282+
"\"max children reached\":%u,"
283+
"\"slow requests\":%lu";
281284

282285
if (!full) {
283286
short_post = "}";
@@ -326,7 +329,8 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */
326329
"active processes: %d\n"
327330
"total processes: %d\n"
328331
"max active processes: %d\n"
329-
"max children reached: %u\n";
332+
"max children reached: %u\n"
333+
"slow requests: %lu\n";
330334

331335
if (full) {
332336
full_syntax =
@@ -367,7 +371,8 @@ int fpm_status_handle_request(TSRMLS_D) /* {{{ */
367371
scoreboard.active,
368372
scoreboard.idle + scoreboard.active,
369373
scoreboard.active_max,
370-
scoreboard.max_children_reached);
374+
scoreboard.max_children_reached,
375+
scoreboard.slow_rq);
371376

372377
PUTS(buffer);
373378
efree(buffer);

0 commit comments

Comments
 (0)