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:
<div _ngcontent-ng-c2080784976="" class="code-block ng-tns-c2080784976-89 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation" jslog="223238;track:impression;BardVeMetadataKey:[["r_459b5055c3a7abbe","c_22643fe4d9561dbb",null,"rc_0acabc077aae8f53",null,null,"en",null,1,null,null,1,0]]">
<div _ngcontent-ng-c2080784976="" class="formatted-code-block-internal-container ng-tns-c2080784976-89">
<div _ngcontent-ng-c2080784976="" class="animated-opacity ng-tns-c2080784976-89">
<pre _ngcontent-ng-c2080784976="" class="ng-tns-c2080784976-89"><code _ngcontent-ng-c2080784976="" role="text" data-test-id="code-content" class="code-container formatted ng-tns-c2080784976-89 no-decoration-radius" data-sourcepos="135:1-141:24">pm = ondemand
pm.max_children = 16
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 8