optimum values for php-mpm module

optimum values for php-mpm module

by Cham Pereira -
Number of replies: 5

We are running moodle 3.9 on Cent OS 8 . We have total 3000 users and today we had quiz for 250-300 people. But server starts restarting when users reached 100+. I had to postpose and find problems. 

We have given 64 GB ram with 8 virtual cpus in Vspere, Hence I think resources are good enough. 

But default php memory limit was not changed. it was 128M then I changed it to -1 (hope assigned to get maximum that can get per script).

Other than that  php-fpm error log has error "you may need to increase pm.start_servers" I have used all the default values that comes with php 7.2. I'm using mpm_event_module.

Could you please correct me about php memory limit and how set values for the mpm_event_module. 

Thanks in Advance.

Average of ratings: -
In reply to Cham Pereira

Re: optimum values for php-mpm module

by Alex Rowe -
There are many good articles online about how to properly configure/tune your PHP/Apache Settings.

Apache MPM event is configured through /etc/apache2/mods-enabled/mpm_event.conf on Ubuntu, CentOS would be different but similar.

The default settings for you would probably be ok, but maybe raise "MaxRequestWorkers" from the default 150 to 400 or something. I think over 400 requires a higher serverlimit configuration but I'm not sure as we run load balanced servers and don't need a higher value.

PHP FPM settings would be in /etc/php//fpm/pool.d/www.conf on Ubuntu, as before it would similar on CentOS.

The default www.conf settings only give you about 5 php processes I think, not enough to run 300 students on a quiz. There is no exact rule here to set the pm.* values but it does depend on the basic formula of "RAM free / PHP process size".

An average PHP process size (depending on what you're doing) could be 300M (round up to give some padding). Say 64 GB is only running the web server, take off 2GB for the OS, maybe 1GB for Opcache, xGB for something else and you have 60GB left.

pm.max_children would then be 60GB * 1024MB = 61440MB / 300MB = ~200 processes

pm.start_servers then runs on a different formula of "min_spare_servers + (max_spare_servers - min_spare_servers) / 2"

Those might look like: (min/max just made up values, but you may want more/less spare than that)
pm.start_servers = 40
pm.min_spare_servers = 30
pm.max_spare_servers = 50

If you also run the DB on this server too and any other caching, you also need to remove all that RAM from the available pool before you calculate how much PHP can use.

Also, leaving the php memory limit to -1 may cause issues with scripts taking all the ram. Best to leave it as a hard value and only raise it if needed. Moodle will also automatically raise it for areas such as backups if required.
Average of ratings: Useful (1)
In reply to Alex Rowe

Re: optimum values for php-mpm module

by Cham Pereira -
Alex,
I had automatically server restart issue. Yesterday updated the cent os kernal and today revised php fpm settings. But server restarts suddenly without any sign.
In reply to Cham Pereira

Re: optimum values for php-mpm module

by Alain Raap -
Picture of Particularly helpful Moodlers
I have used these articles in the past, maybe you can use them for tuning:

https://medium.com/@sbuckpesch/apache2-and-php-fpm-performance-optimization-step-by-step-guide-1bfecf161534

https://wiki.mikejung.biz/Apache#Event_MPM

https://serversforhackers.com/c/php-fpm-process-management

MPM Event takes some time to figure out how to configure it together with Apache and PHP-FPM
A good performancetest with a baseline is important if you're tweaking with these components for a better performance
Average of ratings: Useful (1)