modify PHP-FPM config customization

taker18

Verified User
Joined
Oct 18, 2021
Messages
149
Location
USA
I have 64G ram Server 8 core, but my but i have one of my site is very large and heavy, and all the times the admin site is extremely sluggish

this is my PHP-FPM config customization

./data/users/admin/php/php-fpm83.conf​


  1. [admin]
  2. user = $pool
  3. group = $pool
  4. listen = /usr/local/php83/sockets/$pool.sock
  5. listen.owner = $pool
  6. listen.group = apache
  7. listen.mode = 660
  8. pm = ondemand
  9. pm.max_children = 10
  10. pm.process_idle_timeout = 20
  11. pm.max_requests = 500


    Now I am convinced that I shouldn't switch pm = Ondemand to Dynamic, it should stay the same as Ondemand ok fine.
    but what about the rest

    pm.max_children = 10
    pm.process_idle_timeout = 20
    pm.max_requests = 500

    in fact some recommendation to add
    pm.max_children = 60
    pm.start_servers = 6
    pm.min_spare_servers = 4
    pm.max_spare_servers = 10


    any recommendation I want to change pm.max_children = 60 (increase it more than the default 10)
    Thank you
 
this is my Top

Code:
Top:
Tasks:
CPU(s):
KiB Mem:
KiB Swap:
21:16:48 up 251 days, 13:55, 0 users, load average: 0.32, 0.37, 0.36
320 total, 2 running, 318 sleeping, 0 stopped, 0 zombie
0.0 us, 0.4 sy, 0.0 ni, 99.6 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
63707.6 total, 1821.3 free, 3795.3 used, 58809.0 buff/cache
32735.0 total, 32477.5 free, 257.5 used. 59912.3 avail Mem
 
the admin site is extremely sluggish

That can be caused by a bunch of reasons. You might enable slow logs in PHP-FPM and see what is causing issues. Common reasons:

1. too slow SQL queries
2. requests to remote services, sites
3. operations with images (re-sizing, converting, etc)
 
As has been mentioned there can be many causes for performance issues, withought knowing more about your site, possibly what framework it is running, it is hard to give specific recomendations.

But, I have found that slow PHP sites are often related more to other factors than just throwing more PHP processes at the problem.

1) Needing more memory for the php process. Can be increased in most cases by creating a ".user.ini" in the root of the website (in public_html) and set a specific memory limit say "memory_limit = 512M", example if your running WordPress with WooCommerce I would make that at least 1024M, don't forget to also edit the WordPress config memory limit also (define('WP_MEMORY_LIMIT', '512M');)

2) Mysql table optimisation, add missing indexes, etc.. If you have a really large database then it would be a good idea to do some optimization of Mysql itself, a tool like MySQLTuner can help with this ( https://github.com/major/MySQLTuner-perl ), as with any tool, only use what it says to change as a guide, double check what it is suggesting.

3) If there are a lot of files in the website that get loaded the speed of the file system can become a factor. Hopefully your running on NVMe drives where this is really not as much of an issue, but if your running on SATA SSD or spinning disks this can really help. If many files get opened on every page load the update of the file access time can become a factor on EXT4 file systems, you can adjust the fstab and add the option "lazytime" to delay writing out to disk the the last access times to reduce the amount of writes.

4) Check your Swappiness, personally I set mine to 1, so swapping doesn't happen untill i'm almost OOM. If swapping is occuring it will slow things down.

5) If running WordPress watch out the number of plugins that you use, try to keep it to a minimum. Some visual editors can cause performance issues (ie: Elementor), also increase the PHP memory limit more if you are using one it can help. If your not using a cache plugin it would be a good idea (Surge is a basic one that works well).

6) Almost forgot, if you have Resource Limits set for the user running the website, make sure they are high enough.

These are just some suggestions that may be able to help with performance. More information would be required to find and fix the exact root cause for your site(s).
 
Back
Top