php-fpm and memory

LawsHosting

Verified User
Joined
Sep 13, 2008
Messages
2,367
Location
London UK
Ever since I moved from mod_php, memory usage has been shocking..

8gb VM with 2gb swap, php 5.6 and 7.2...... After a while, memory and swap can occasionally run out (0)....... When I restart the fpm's, memory is free'd, before I restart them, usage can be up to 3gb.

I know 8gb is not that much these days, but still.

server-status said:
Server load: 3.55 2.63 2.64
Total accesses: 334285 - Total Traffic: 5.0 GB
CPU Usage: u682.54 s29.8 cu.12 cs.02 - 1.18% CPU load
5.56 requests/sec - 87.2 kB/second - 15.7 kB/request
3 requests currently being processed, 125 idle workers
Does this mean, fpm starts with 128 workers by default?
 
I believe Apache server-status does not show anything related to PHP-FPM.
PHP-FPM settings can be found under /usr/local/directadmin/data/templates/php-fpm.conf

By default they are:

Code:
pm = ondemand
pm.max_children = |MAX_CHILDREN|
pm.process_idle_timeout = 20

where |?MAX_CHILDREN=100|
 
Do you see anything

Code:
cd /var/log/httpd/domains/; grep [B]'CHAR'[/B] *.log | grep -v error.log | awk '{print $1}' | cut -d\: -f2 | sort | uniq -c | sort -rn
?
 
Nothing :(

I do know this client has one domain that is heavily visited - fpm processes take CPU % non-stop with about a minimum of 3 appearing constantly for this user..... Also, it's behind cloudflare, so it ought to be better...... It was on php 5.6, thought to try 7.2, its speed increased (as it should), but the memory drain continued.

I know most of the memory is cached, but it's worrying that it's running out.

See attached top output example...
 

Attachments

  • top_view.jpg
    top_view.jpg
    64.2 KB · Views: 41
This is the total of shared memory (https://en.wikipedia.org/wiki/Shared_memory), not the actual one. Similar processes share lots of their memory, so physical memory usage is usually lower than VMEM usage. It should be possible to count physical (actual) memory usage in recent OS, so, that'd be a feature request to DA. I'd suggest collecting meminfo stats from /proc to have a better idea of which user (php-fpm) process is using the memory (as if you run out of swap, it means something is really using it up, unless some RAM is oversold).
 
I know which account/processes is most active...... This sounds n00bish, but can you guide me to some tutorial to debug this situation?

This has just been happening recently, as you can see the uptime of the VM. The VM has always been busy..
 
If you disable opcache you will see much smaller fpm processes.
I actually didn't have it enabled (in CB), but I'm not sure if it is actually disabled as I always see it referenced at compile time... I guess if it's not referenced in the 10-directadmin.ini, it means it's disabled?..

I enabled it to see if it'll improve....

I also edited the user's php-fpm.conf with these:
pm = dynamic
pm.max_children = 20
pm.start_servers = 16
pm.min_spare_servers = 8
pm.max_spare_servers = 16
pm.max_requests = 1000
pm.process_idle_timeout = 10
Now the DA services page state a steady 2.7Gb (obviously because it doesn't spawn processes above 16/32), but memory is still being used (well, I know it's cached but)...

Code:
#free -m
             total  used free  shared  buffers  cached
Mem:         12288  11596  691   0     0      6937
+ buffers/cache: 4658  7629
Swap:        2000   617  1382
 
Back
Top