roots / trellis

WordPress LEMP stack with PHP 8.2, Composer, WP-CLI and more
https://roots.io/trellis/
MIT License
2.49k stars 608 forks source link

Add PHP-FPM conf and tuning settings #1496

Closed swalkinshaw closed 1 year ago

swalkinshaw commented 1 year ago

Allows customization of the PHP-FPM service configuration. Previously only the pool configuration was exposed in Trellis. This allows for more advanced performance tuning.

Note: moved over from #1444 by @paulbrzeski (added you as co-author) to make this easier to manage and deal with conflicts + Git history.

Below is the original description:

Sharing a couple of changes we've made to our Trellis so we can fine tune PHP settings for high traffic websites.

Changes include,

This PR only provides the defaults, you can override these settings like any other using your group_vars configs.

PHP FPM for a server sharing environment with MariaDB. New variables to add to group_vars/%ENV%/php.yml,

# Allow a max of 100 children, based on 16GB of ram and 164mb per child.
php_fpm_pm_max_children: 100
# Start and go up in small incremenets as we have the CPU to spare.
php_fpm_pm_start_servers: 5
php_fpm_pm_min_spare_servers: 5
php_fpm_pm_max_spare_servers: 35
# Allow lots of requests as we have the resources to spare.
php_fpm_pm_max_requests: 1000

# Emergency restart settings.
# Restart after 60 seconds if 10 PHP instances have not responded for 5 min

# Number of child processes not responding
php_fpm_set_emergency_restart_threshold: true
php_fpm_emergency_restart_threshold: 10

# Length of time children not responding.
php_fpm_set_emergency_restart_interval: true
php_fpm_emergency_restart_interval: 5m

# Time to wait before restarting after interval passes.
php_fpm_set_process_control_timeout: true
php_fpm_process_control_timeout: 60s

More info - https://geekflare.com/php-fpm-optimization/

(previously roots/trellis#1430)