1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Add PHP-FPM memory peak to the scoreboard

Closes #14153
This commit is contained in:
Flavio Heleno
2024-05-06 11:56:48 -03:00
committed by Jakub Zelenka
parent a092bcb4d7
commit 67aac59cfc
11 changed files with 46 additions and 19 deletions

3
NEWS
View File

@@ -25,6 +25,9 @@ PHP NEWS
. Fixed bug GH-15551 (Segmentation fault (access null pointer) in
ext/dom/xml_common.h). (nielsdos)
- FPM:
. Added memory peak to the scoreboard / status page. (Flávio Heleno)
- MySQLnd:
. Fixed bug GH-15432 (Heap corruption when querying a vector). (cmb,
Kamil Tekiela)

View File

@@ -290,6 +290,7 @@ PHP 8.4 UPGRADE NOTES
- FPM:
. Flushing headers without a body will now succeed. See GH-12785.
. Status page has a new field to display a memory peak.
- Hash:
. Added HashContext::__debugInfo().

View File

@@ -189,7 +189,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ *
void fpm_php_trace(struct fpm_child_s *child) /* {{{ */
{
fpm_scoreboard_update(0, 0, 0, 0, 0, 0, 1, FPM_SCOREBOARD_ACTION_INC, child->wp->scoreboard);
fpm_scoreboard_update(0, 0, 0, 0, 0, 0, 1, 0, FPM_SCOREBOARD_ACTION_INC, child->wp->scoreboard);
FILE *slowlog;
zlog(ZLOG_NOTICE, "about to trace %d", (int) child->pid);

View File

@@ -373,7 +373,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{
}
}
fpm_scoreboard_update_commit(idle, active, cur_lq, -1, -1, -1, 0, FPM_SCOREBOARD_ACTION_SET, wp->scoreboard);
fpm_scoreboard_update_commit(idle, active, cur_lq, -1, -1, -1, 0, 0, FPM_SCOREBOARD_ACTION_SET, wp->scoreboard);
/* this is specific to PM_STYLE_ONDEMAND */
if (wp->config->pm == PM_STYLE_ONDEMAND) {
@@ -406,7 +406,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 && !wp->shared) {
fpm_scoreboard_update(0, 0, 0, 0, 0, 1, 0, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
fpm_scoreboard_update(0, 0, 0, 0, 0, 1, 0, 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;
}
@@ -425,7 +425,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 && !wp->shared) {
fpm_scoreboard_update(0, 0, 0, 0, 0, 1, 0, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
fpm_scoreboard_update(0, 0, 0, 0, 0, 1, 0, 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;
}
@@ -529,7 +529,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 && !wp->shared) {
fpm_scoreboard_update(0, 0, 0, 0, 0, 1, 0, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
fpm_scoreboard_update(0, 0, 0, 0, 0, 1, 0, 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;
}

View File

@@ -54,7 +54,7 @@ void fpm_request_accepting(void)
fpm_scoreboard_proc_release(proc);
/* idle++, active-- */
fpm_scoreboard_update_commit(1, -1, 0, 0, 0, 0, 0, FPM_SCOREBOARD_ACTION_INC, NULL);
fpm_scoreboard_update_commit(1, -1, 0, 0, 0, 0, 0, 0, FPM_SCOREBOARD_ACTION_INC, NULL);
}
void fpm_request_reading_headers(void)
@@ -98,7 +98,7 @@ void fpm_request_reading_headers(void)
fpm_scoreboard_proc_release(proc);
/* idle--, active++, request++ */
fpm_scoreboard_update_commit(-1, 1, 0, 0, 1, 0, 0, FPM_SCOREBOARD_ACTION_INC, NULL);
fpm_scoreboard_update_commit(-1, 1, 0, 0, 1, 0, 0, 0, FPM_SCOREBOARD_ACTION_INC, NULL);
}
void fpm_request_info(void)
@@ -199,6 +199,9 @@ void fpm_request_end(void)
#endif
proc->memory = memory;
fpm_scoreboard_proc_release(proc);
/* memory_peak */
fpm_scoreboard_update_commit(0, 0, 0, 0, 0, 0, 0, proc->memory, FPM_SCOREBOARD_ACTION_SET, NULL);
}
void fpm_request_finished(void)

View File

@@ -99,7 +99,7 @@ void fpm_scoreboard_update_begin(struct fpm_scoreboard_s *scoreboard) /* {{{ */
void fpm_scoreboard_update_commit(
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) /* {{{ */
int slow_rq, size_t memory_peak, int action, struct fpm_scoreboard_s *scoreboard) /* {{{ */
{
scoreboard = fpm_scoreboard_get_for_update(scoreboard);
if (!scoreboard) {
@@ -169,6 +169,9 @@ void fpm_scoreboard_update_commit(
if (scoreboard->active > scoreboard->active_max) {
scoreboard->active_max = scoreboard->active;
}
if (scoreboard->memory_peak < memory_peak) {
scoreboard->memory_peak = memory_peak;
}
fpm_unlock(scoreboard->lock);
}
@@ -177,11 +180,11 @@ void fpm_scoreboard_update_commit(
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) /* {{{ */
int slow_rq, size_t memory_peak, int action, struct fpm_scoreboard_s *scoreboard) /* {{{ */
{
fpm_scoreboard_update_begin(scoreboard);
fpm_scoreboard_update_commit(
idle, active, lq, lq_len, requests, max_children_reached, slow_rq, action, scoreboard);
idle, active, lq, lq_len, requests, max_children_reached, slow_rq, memory_peak, action, scoreboard);
}
/* }}} */

View File

@@ -66,6 +66,7 @@ struct fpm_scoreboard_s {
unsigned int nprocs;
int free_proc;
unsigned long int slow_rq;
size_t memory_peak;
struct fpm_scoreboard_s *shared;
struct fpm_scoreboard_proc_s procs[] ZEND_ELEMENT_COUNT(nprocs);
};
@@ -74,8 +75,8 @@ int fpm_scoreboard_init_main(void);
int fpm_scoreboard_init_child(struct fpm_worker_pool_s *wp);
void fpm_scoreboard_update_begin(struct fpm_scoreboard_s *scoreboard);
void fpm_scoreboard_update_commit(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);
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);
void fpm_scoreboard_update_commit(int idle, int active, int lq, int lq_len, int requests, int max_children_reached, int slow_rq, size_t memory_max, 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, size_t memory_max, int action, struct fpm_scoreboard_s *scoreboard);
struct fpm_scoreboard_s *fpm_scoreboard_get(void);
struct fpm_scoreboard_proc_s *fpm_scoreboard_proc_get(struct fpm_scoreboard_s *scoreboard, int child_index);

View File

@@ -514,7 +514,7 @@ int fpm_sockets_init_main(void)
}
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, 0, FPM_SCOREBOARD_ACTION_SET, wp->scoreboard);
fpm_scoreboard_update(-1, -1, -1, (int)lq_len, -1, -1, 0, 0, FPM_SCOREBOARD_ACTION_SET, wp->scoreboard);
}
}

View File

@@ -94,6 +94,7 @@ int fpm_status_export_to_zval(zval *status)
add_assoc_long(status, "max-active-processes", scoreboard.active_max);
add_assoc_long(status, "max-children-reached", scoreboard.max_children_reached);
add_assoc_long(status, "slow-requests", scoreboard.slow_rq);
add_assoc_long(status, "memory-peak", scoreboard.memory_peak);
array_init(&fpm_proc_stats);
for(i=0; i<scoreboard.nprocs; i++) {
@@ -244,6 +245,7 @@ int fpm_status_handle_request(void) /* {{{ */
"<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"
"<tr><th>memory peak</th><td>%zu</td></tr>\n"
"</table>\n";
if (!full) {
@@ -309,7 +311,8 @@ int fpm_status_handle_request(void) /* {{{ */
"<total-processes>%d</total-processes>\n"
"<max-active-processes>%d</max-active-processes>\n"
"<max-children-reached>%u</max-children-reached>\n"
"<slow-requests>%lu</slow-requests>\n";
"<slow-requests>%lu</slow-requests>\n"
"<memory-peak>%zu</memory-peak>\n";
if (!full) {
short_post = "</status>";
@@ -357,7 +360,8 @@ int fpm_status_handle_request(void) /* {{{ */
"\"total processes\":%d,"
"\"max active processes\":%d,"
"\"max children reached\":%u,"
"\"slow requests\":%lu";
"\"slow requests\":%lu,"
"\"memory peak\":%zu";
if (!full) {
short_post = "}";
@@ -426,6 +430,9 @@ int fpm_status_handle_request(void) /* {{{ */
"# HELP phpfpm_slow_requests The number of requests that exceeded your 'request_slowlog_timeout' value.\n"
"# TYPE phpfpm_slow_requests counter\n"
"phpfpm_slow_requests %lu\n"
"# HELP phpfpm_memory_peak The memory usage peak since FPM has started.\n"
"# TYPE phpfpm_memory_peak gauge\n"
"phpfpm_memory_peak %zu\n"
"# EOF\n";
has_start_time = 0;
@@ -457,7 +464,8 @@ int fpm_status_handle_request(void) /* {{{ */
"total processes: %d\n"
"max active processes: %d\n"
"max children reached: %u\n"
"slow requests: %lu\n";
"slow requests: %lu\n"
"memory peak: %zu\n";
if (full) {
full_syntax =
@@ -496,7 +504,8 @@ int fpm_status_handle_request(void) /* {{{ */
scoreboard_p->idle + scoreboard_p->active,
scoreboard_p->active_max,
scoreboard_p->max_children_reached,
scoreboard_p->slow_rq);
scoreboard_p->slow_rq,
scoreboard_p->memory_peak);
} else {
spprintf(&buffer, 0, short_syntax,
scoreboard_p->pool,
@@ -511,7 +520,8 @@ int fpm_status_handle_request(void) /* {{{ */
scoreboard_p->idle + scoreboard_p->active,
scoreboard_p->active_max,
scoreboard_p->max_children_reached,
scoreboard_p->slow_rq);
scoreboard_p->slow_rq,
scoreboard_p->memory_peak);
}
PUTS(buffer);

View File

@@ -39,7 +39,7 @@ $tester->close();
Done
--EXPECTF--
Test Start
array(15) {
array(16) {
["pool"]=>
string(10) "unconfined"
["process-manager"]=>
@@ -68,6 +68,8 @@ array(15) {
int(0)
["slow-requests"]=>
int(0)
["memory-peak"]=>
int(0)
["procs"]=>
array(1) {
[0]=>

View File

@@ -35,6 +35,7 @@ class Status
'max active processes' => '\d+',
'max children reached' => '\d+',
'slow requests' => '\d+',
'memory peak' => '\d+',
];
/**
@@ -266,6 +267,9 @@ class Status
"# HELP phpfpm_slow_requests The number of requests that exceeded your 'request_slowlog_timeout' value\.\n" .
"# TYPE phpfpm_slow_requests counter\n" .
"phpfpm_slow_requests " . $fields['slow requests'] . "\n" .
"# HELP phpfpm_memory_peak The memory usage peak since FPM has started\.\n" .
"# TYPE phpfpm_memory_peak gauge\n" .
"phpfpm_memory_peak " . $fields['memory peak'] . "\n" .
"# EOF)\n";
if (!preg_match($pattern, $body)) {