How to monitor RAM usage:
free -h
:- This command shows your system's total, used, and free memory in a human-readable format.
- Key metrics:
total
: Total RAM.used
: RAM currently in use.free
: Unused RAM.buff/cache
: RAM used for file system buffers and page cache. This is good; Linux uses free RAM for this and frees it when applications need it.available
: The most important metric. This estimates how much memory is available for starting new applications without swapping.
- Run it before and after: Run
free -h
before you increasemax_children
and then after your server has been running for a while under typical load with the new settings. Compare theavailable
memory.
htop
(recommended if installed):htop
(you might need tosudo apt install htop
) provides a real-time, interactive view of processes and resource usage, including a visual bar for memory usage.- It's excellent for seeing how much RAM each PHP-FPM process (
php-fpm: pool ...
processes) is consuming. You can estimate the memory per process and multiply by your newmax_children
to get a rough idea of the total.
top
:- Less user-friendly than
htop
, but still effective. - Look at the
%MEM
column to see memory usage per process.
- Less user-friendly than
Practical Steps for Increasing pm.max_children
and Monitoring RAM:
- Determine Current PHP Process Memory Usage:
- Run
htop
(ortop
). - Find a few
php-fpm
processes from thekartscode
pool. Look at theirRES
(Resident Set Size) orVIRT
(Virtual Memory Size) columns intop
/htop
. This is the actual memory they are consuming. Let's say, on average, a PHP-FPM process uses 50MB.
- Run
- Calculate Potential Max Memory:
- Current
max_children = 16
. At 50MB/process, that's16 * 50MB = 800MB
for PHP processes. - If you increase
max_children
to30
, that would be30 * 50MB = 1500MB
(1.5GB).
- Current
- Check
free -h
: Look at youravailable
memory. If you only have 500MB available, increasing to 30 processes (requiring 1.5GB) will cause severe swapping. - Increment Gradually: Instead of a big jump, increase
pm.max_children
in small steps (e.g., from 16 to 20, then 20 to 24). - Monitor: After each increase, let the server run under load for an hour or two, then check
free -h
andhtop
to see how memory is being utilized. Look for sustained lowavailable
memory or increasingswap
usage.
Your 17002705575366718.conf
settings:
pm = ondemand
pm.max_children = 16
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 8
The fpm.txt
output showed max-children-reached => 10
, but pm.max_children
is set to 16
. This indicates that the max_children
limit you hit might be determined by the system-wide limits or another PHP-FPM configuration, or that max-children-reached
refers to the number of actively processing children at a specific moment, not necessarily the pm.max_children
limit itself. Given the total-processes
of 16 in fpm.txt
, it seems like your max_children
is indeed 16, and you're hitting that. This explains why new requests would queue or drop if more than 16 concurrent PHP processes were needed.
Action to take with pm.max_children
: Based on the fpm.txt
showing total-processes: 16
and max-children-reached: 10
, it strongly suggests you are hitting your concurrent process limit for active requests. Since pm.max_children
is 16, this means all 16 are being spawned, but perhaps only 10 were 'active' in the sense of processing requests at the very peak snapshot.
Let's increase pm.max_children
for this pool. Given your server has 2 CPUs, you have some room.
- Edit
/etc/php/8.2/fpm/pool.d/17002705575366718.conf
- Change
pm.max_children = 16
to something higher. A common starting point for a server with 2 CPUs (assuming adequate RAM) might be20
or25
. - Save the file.
- Reload PHP-FPM:
sudo systemctl reload php8.2-fpm
(orsudo systemctl reload php-fpm
if your distro uses a generic name).
Before and after this change, use free -h
to monitor RAM. If you have 4GB or more RAM, increasing to 20-25 processes is generally safe to test. If you have less (e.g., 2GB), be more cautious and increase by smaller increments.