Skip to main content

PHP-FPM tuning: Using ‘pm static’ for max performance best php training trivandrum

PHP-FPM tuning: Using ‘pm static’ for max performance


PHP-FPM process manager (PM) similarities to CPUFreq Governor

Using ‘pm static’ to achieve your server’s max performance

Linux top php-fpm static pm
In the screenshot above this server has pm = static and pm.max_children = 100 which uses a max of around 10GB of the 32GB installed. Take note of the highlighted columns, self explanatory. During that screenshot there were about 200 ‘active users’ (past 60 seconds) in Google Analytics. At that level, about 70% of PHP-FPM children are still idle. This means PHP-FPM is always set to the max capacity of your server’s resources regardless of current traffic. Idle process stay online waiting for traffic spikes and responding immediately, rather than having to wait on the pm to spawn children and then kill them off after x pm.process_idle_timeout expires. I have pm.max_requests set extremely high because this is a production server with no PHP memory leaks. You can use pm.max_requests = 0 with static if you have 110% confidence in your current and future PHP scripts. However, it’s recommended to restart scripts over time. Set the # of requests to a high number since the point is to avoid pm overhead. So for example at least  pm.max_requests = 1000 …depending on your # of pm.max_children and # of requests per second.
top -bn1 | grep php-fpm

When to use pm ‘ondemand’ and ‘dynamic’

WARNING: [pool xxxx] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 4 idle, and 59 total children
PM dynamic and especially ondemand can be save you however, when you have multiple PHP-FPM pools. For example, hosting multiple cPanel accounts or multiple websites under different pools. I have a server for example with 100+ cpanel accounts and about 200+ domains and it would be impossible for pm.static or even dynamic to perform well. Only ondemand performs well since more than two third’s of the websites receive little to no traffic and with ondemand it means all children will be shutdown saving tons of server memory! Thankfully, cPanel devs figured this out and now defaults to ondemand. Previously with dynamic as default it made PHP-FPM not an option on busy shared servers. Many would use suPHP because of pm dynamic eating up memory even on idle cPanel PHP-FPM pools/accounts. Chances are, if you receive good traffic, you won’t be hosted on a server with lots of PHP-FPM pools (shared hosting).

Conclusion

PHP-FPM tuning: Using 'pm static' for max performance...CLICK TO TWEET
When it comes to PHP-FPM, once you start to serve serious traffic, ondemand and dynamic process managers for PHP-FPM can limit throughput because of the inherent overhead. Know your system and set your PHP-FPM processes to match your server’s max capacity. Start with pm.max_children set based on max usage of pm dynamic or ondemand and then increase to the point where memory and CPU can process without becoming overwhelmed. You will notice that with pm static, because you keep everything sitting in memory, traffic spikes over time cause less spikes to CPU and your server’s load and CPU averages will be smoother. The average size of your PHP-FPM process will vary per web server requiring manual tuning, thus why the more automated overhead process managers – dynamic and ondemand – are more popular recommendations.  Hope this was a useful article.

Comments

Popular posts from this blog

Memory leak in 7.x json_decode()? Best Php Training Trivandrum

Memory leak in 7.x json_decode()? There appears to be a memory leak in 7.x json_decode(). I've uploaded a huge JSON file to demonstrate the problem. Here is the sample code: <?php echo memory_get_usage(false) . ' : ' .memory_get_usage(true) . PHP_EOL; $json = json_decode(file_get_contents('http://zaremedia.com/big.json')); echo memory_get_usage(false) . ' : ' .memory_get_usage(true) . PHP_EOL; unset($json); echo memory_get_usage(false) . ' : ' .memory_get_usage(true) . PHP_EOL; Below is output from 7.x and then 5.6: // Running on 7.0 and 7.1 349608 : 2097152 27245512 : 29360128 375552 : 29360128 The process starts with 0.3mb used / 2.0mb allocated. After json_decode(), it's 27.2 / 29.4mb, after unset, it's 3.7mb / 29.4mb -- The second value (memory allocated by php via emalloc()) has not been freed, though PHP's gc has correctly freed up the object usage. // Running on 5.6 221136 : 262144 31577064 : 35913728 420104 : 86507

How do I deploy my Symfony API - - Deploy best php training trivandrum

How do I deploy my Symfony API -  - Deploy This is the forth post from a series of posts that will describe the whole deploy process from development to production.  The first article is available  here , the second  here  and the third  here . After covering the steps 1-3 and having prepared our infrastructure, we can see how to  deploy  our application to production. Almost the same approach can be used to deploy not only to production but also to test environments. Workflow Different "git push" operation should trigger different actions. Just as example a push to  master  should trigger a deploy to production, while other branches may trigger a deploy to a test environment, or not trigger deploys at all. I've used  Circe CI Workflows  to manage this set of decisions. Workflows are just another section from the same  .circleci/config.yml  file and here they are: workflows: version: 2 build_and_deploy-workflow: jobs: - build - d

A DateTimePeriod library for working with temporal intervals php training trivandrum

An implementation of the datetime period type for working with temporal intervals. The library includes the full set of relations on intervals defined by  Allen's Interval Algebra . For further information see the "Usage" and "How it works" paragraphs. Requirements PHP 7.1+ Installation $ composer require pwm/datetime-period Usage Creation: $start = new DateTimeImmutable ( ' 2010-10-10T10:10:10+00:00 ' ); $end = new DateTimeImmutable ( ' 2011-11-11T11:11:11+00:00 ' ); $period = new DateTimePeriod ( $start , $end ); // Start/end instants and their interval $start = $period -> getStart(); // DateTimeImmutable('2010-10-10T10:10:10+00:00') $end = $period -> getEnd(); // DateTimeImmutable('2011-11-11T11:11:11+00:00') $interval = $period -> getInterval(); // DateInterval('P1Y1M1DT1H1M1S') Restrictions: // Throws TimeZoneMismatch exception new DateTimePeriod ( new Da