Search slows each morning since moving to Kubernetes
Your task
It is 09:35 on Thursday. The product search API is a Python app served by gunicorn. Until last Friday it ran on 6 VMs with 4 vCPUs each. On Monday it moved to Kubernetes: 12 pods, each with 2 CPUs and 2 GiB of memory as both its request and its limit. A horizontal pod autoscaler (HPA) runs between 12 and 20 pods and adds pods when average CPU passes 70% of the request. This alert fires:
SearchLatencyP95: p95 above 1 s for 10 minutes (current 9.1 s)
What you see:
- p95, the time 95% of requests finish within, is 70 ms overnight at about 100 requests a second. Since Monday it climbs from about 08:45 each day. Now, at 300 requests a second, many requests time out at the load balancer's 10 s limit. The VMs served the same peak last week at 90 ms.
- Each pod uses about 0.6 CPU of its 2, so the HPA stays at 12 pods. Memory is 210 MiB per pod.
- Each pod's start-up log has
Listening at: http://0.0.0.0:8000 (1),Using worker: syncandBooting worker with pid: 7. - Postgres allows 200 connections, and 30 are in use. Each gunicorn worker keeps a pool of 2 connections.
What do you change this morning, and what do you check before you roll it out?
It covers
- Gunicorn
- Worker processes
- Kubernetes