How to increase performance of a PHP app in Kubernetes?

I’ve just started using Kubernetes. I have a Laravel Application running on a Basic Droplet 4vCPUs/8GB Memory. Doing a ApacheBench gives me ~160 requests/sec. Doing the same test on the same Laravel Application but running in Kubernetes on a 40vCPU/160GB Droplet, gives me only ~40 requests/sec. I’m using one DO LoadBalancer. Even if I only use one 4vCPUs/8GB Droplet I get ~35 requests/sec. I’ve checked the logs and the requests are being processed by all pods in use. Is it generally slower to run all requests through the load balancer -> ingress controller -> nginx -> php-fpm?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This is a really interesting but there are a lot of details to explore to get to the bottom of this.

The first thing I would note is that requests per second might not be the best metric to measure. You probably should measure average response time or, even better, P99 latency.

Also, do you know how ApacheBench is running its test? How many parallel requests is performs? One at a time? Something else?

Also, do you know the baseline processing time of your Laravel app? In other words, ignoring network time, how long does it take for your app to process a request? If your app is super fast, then even the smallest network slowness will significantly change your requests/sec: Compare (100ms network + 1ms processing) to (150ms network + 1ms processing).

That said, I think it’s reasonable that you will have some overhead if you use a Kubernetes cluster with a Load Balancer compared to an all-in-one droplet. You basically end up with something like:

  • Load balancer
  • Kubernetes node (nginx ingress)
  • Kubernetes node (Laravel --> nginx + php-fpm)