title: How to compute for php-fpm child process on a Kubernetes Cluster
body: <p>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. </p>
  
  <p>I have successfully migrated my application on a <code>cluster size of 3 each with 1vCPU and 3.75 GB RAM</code></p>
  
  <p>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 </p>
  
  <p><a href="https://serversforhackers.com/c/php-fpm-process-management" rel="noreferrer">https://serversforhackers.com/c/php-fpm-process-management</a></p>
  
  <p><a href="https://www.kinamo.be/en/support/faq/determining-the-correct-number-of-child-processes-for-php-fpm-on-nginx" rel="noreferrer">https://www.kinamo.be/en/support/faq/determining-the-correct-number-of-child-processes-for-php-fpm-on-nginx</a></p>
  
  <p>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.</p>
  
  <p>So now I wanted to increase the size of the following based on the articles I shared above.</p>
  
  <pre><code>pm.max_children = 5
  pm.start_servers = 2
  pm.min_spare_servers = 4
  pm.max_spare_servers = 8 
  </code></pre>
  
  <p>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? </p>
  
  <p>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.</p>
  
  <p>pm.max_children brings us to 1024 Mb / 60 Mb = 17 max_children</p>
  
  <pre><code>pm.max_children = 17
  pm.start_servers = 8
  pm.min_spare_servers = 7
  pm.max_spare_servers = 10
  pm.max_requests = 500
  </code></pre>
  
  <p>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. </p>
  
  <p>Thank you for reading until the end, and thanks in advance for your inputs.</p>