How to compute for php-fpm child process on a Kubernetes Cluster

10/6/2018

I have recently migrated my application from a single server w/ docker into Google Kubernetes Engine for the reasons of scaling. I am new to the kubernetes platform, and I may not yet fully understand the concepts of it but I do get the basics.

I have successfully migrated my application on a cluster size of 3 each with 1vCPU and 3.75 GB RAM

Now I came across on what is the best configuration for the php-fpm processes running in a kubernetes cluster. I have read a few articles on how to setup the php-fpm processes such as

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

https://www.kinamo.be/en/support/faq/determining-the-correct-number-of-child-processes-for-php-fpm-on-nginx

On my cluster I have an Elasticsearch, Redis, Frontend and a REST Api and my understanding about kubernetes, each has their own pods running on my cluster, I tried to access the pod for the REST Api and see 1 vCPU and 3.75 GB RAM which is what I set on my cluster specs. And the RAM has only 1.75GB left, so I think there are other services or pods using the memory.

So now I wanted to increase the size of the following based on the articles I shared above.

pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 4
pm.max_spare_servers = 8 

But my problem is since the pod is on a worker, if I change the configuration base on the available memory left (base on the articles I shared above on Calculating pm.max_children) I might end up a pod consuming all memory space left, and will not be able to allocate for the other services. Is my problem makes sense? or is there an idea I am missing?

Base on the article since my worker has 3.75 GB RAM and and other services is already consuming 1.5GB ram so my best aim is at 1 GB RAM.

pm.max_children brings us to 1024 Mb / 60 Mb = 17 max_children

pm.max_children = 17
pm.start_servers = 8
pm.min_spare_servers = 7
pm.max_spare_servers = 10
pm.max_requests = 500

Which leads me to the question How to compute for the php-fpm child process on a Kubernetes Cluster when there are other services or pods shares the same resources.

Thank you for reading until the end, and thanks in advance for your inputs.

-- Efx
docker
google-cloud-platform
google-kubernetes-engine
kubernetes
php

1 Answer

10/9/2018

GKE comes with multiple system pods (such as kube-DNS and fluentd). Some of these pods do not scale up much, this means if you add additional nodes, they will have more available resources.

The nodes are also running an OS so some of the memory is being assigned to that. You can also view the resources available per node by using kubectl describe no | grep Allocatable -A 5

This will show you the amount of resources left after the node's consumption. Using kubectl describe no | grep Allocated -A 5 you can view the amount of memory and CPU that is already requested by current pods.

All this being said, you should choose the number of child processes based on your need. Once you know the amount of memory the pod will need, set resource requests and limits to your pod config so that the kubernetes scheduler can put the php-fpm on a node with sufficient resources.

Kubernetes strength is that you tell it what you want and it will try to make that happen. Instead of worrying too much about how much you can fit, choose an amount for your pod based on your expected/required performance and tell kubernetes that's how much memory you need. This way, you can also increase the number of pods using HPA instead of managing and scaling up the number of child processes.

-- Patrick W
Source: StackOverflow