php / php-src

The PHP Interpreter
https://www.php.net
Other
38.29k stars 7.76k forks source link

8.4 wrong fpmstatus output #16932

Open PLTytus opened 1 day ago

PLTytus commented 1 day ago

Description

fpmstatus seems to return wrong values, sample

pool:                 www
process manager:      dynamic
start time:           25/Nov/2024:13:00:38 +0000
start since:          5057
accepted conn:        1
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       0 
active processes:     1
total processes:      1
max active processes: 11
max children reached: 0
slow requests:        0
memory peak:          81326080

accepted conn not incresing, even decreasing, e.g. shows 3 after refreshing it shows 1 again idle processes, active processes, idle processes: in this example there 15 running fpm processes in total

PHP Version

8.4.1

Operating System

No response

devnexen commented 1 day ago

We might need a bit more to understand if the issue is relevant, i.e. configuration, how the logs look ...

PLTytus commented 1 day ago

This is in /usr/local/etc/php-fpm.d/www.conf on php:8.4.1-fpm-alpine image

[www]
user = www-data
group = www-data

pm = dynamic
pm.max_children = 200
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 20
pm.max_requests = 200

pm.status_listen = 127.0.0.1:9001
pm.status_path = /fpmstatus

No errors in logs.

It kind of behaves like processes are overriding current stats: https://github.com/user-attachments/assets/61aab54b-2d25-45c7-b0d7-7562b8aaef2b

There is no such issue on PHP 8.3

lucasnetau commented 21 hours ago

Possibly this PR https://github.com/php/php-src/pull/14153

https://github.com/php/php-src/blob/ba6c00505d4218ff9fe4feb060f636524acfb125/sapi/fpm/fpm/fpm_request.c#L204

This is calling FPM_SCOREBOARD_ACTION_SET at the end of the request with all stats set to 0, the unmodified stats should be set as -1

so either don't set the values

--- fpm_scoreboard_update_commit(0, 0, 0, 0, 0, 0, 0, proc->memory, FPM_SCOREBOARD_ACTION_SET, NULL);
+++ fpm_scoreboard_update_commit(-1, -1, -1, -1, -1, -1, -1, proc->memory, FPM_SCOREBOARD_ACTION_SET, NULL);

or INC vs SET

--- fpm_scoreboard_update_commit(0, 0, 0, 0, 0, 0, 0, proc->memory, FPM_SCOREBOARD_ACTION_SET, NULL);
+++ fpm_scoreboard_update_commit(0, 0, 0, 0, 0, 0, 0, proc->memory, FPM_SCOREBOARD_ACTION_INC, NULL);
PLTytus commented 12 hours ago

Looking at fpm_scoreboard_update_commit definition, both @lucasnetau suggested solutions should resolve the issue. https://github.com/php/php-src/blob/afa08b509ed44cb30fbbab6b2bff2d0460ab395a/sapi/fpm/fpm/fpm_scoreboard.c#L100-L177