6

I would like to ask how to get the best (maximum) number of php-fpm threads per one core? How to benchmark it (on linux/debian)? And how to recognize that this count is already too much? Thank you.

thorewi
  • 63
  • 1
  • 3
  • 3
    Possible duplicate of [Can you help me with my capacity planning?](http://serverfault.com/questions/384686/can-you-help-me-with-my-capacity-planning) – D34DM347 Oct 17 '16 at 12:28

1 Answers1

5

You probably mean processes in the pool. This depends primarily on how much blocking does your actual PHP code. The more it just waits, the more processes you need to have, because more children will just block and wait for something (for example - for external HTTP requests to end). This actual number does depend on the amount of memory you have, on the other hand. The basic rule 2-4 processes per core applies to some ideal code that doesn't block much. Of course you can determine the formal number of threads per core by looking at the specs of your CPU, for instance # of Threads per core for Intel E5-2640 CPU would be 2.

The simple approach on determining the actual number of children in the pool is simple: make it #of Threads for your CPU at the start, then increase slightly, while repeating the benchmarking test for your installation. Once the performance stops to increase, or once you hit the memory cap, stop increasing.

Also keep in mind that in a situation when some external resource will hit it's cap or become unresponsive (i.e. - database server, or some external HTTP server that your code may query) - you will hit the cap no matter how much children in the pool you have, they will just stuck in a waiting state. So you should keep in mind this possible bottleneck while determining your pool cap.

drookie
  • 8,051
  • 1
  • 17
  • 27
  • Ok and when I have a server, where just PHP runs and this server has 2xCPU and I decide that 4 processes per core is optimal, so I set pm.max_children = 8 and in php.ini I have memory_limit = 128M, so maximum memory consumed by php will be +/- 1GB ? – thorewi Oct 17 '16 at 06:28
  • In a very pessimistic set of events - yes, no more than 1 Gb. But in ordinary operation cycle - way less. – drookie Oct 17 '16 at 08:52
  • 1
    when I tried to set the "pm.children" to 20 on 2 cores server and benchmark it via "ab" (ab -n 100 -c 20), it took 13 seconds, when I set the "pm.children" to 4, it took 50 seconds... is this benchmarking correct? – thorewi Oct 18 '16 at 22:13