<p>I have a service deployed in Kubernetes and I am trying to optimize the <a href="https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#resource-requests-and-limits-of-pod-and-container" rel="nofollow noreferrer">requested cpu resources</a>.</p>

<p>For now, I have deployed 10 instances and set <code>spec.containers[].resources.limits.cpu</code> to <code>0.1</code>, based on the "average" use. However, it became obvious that this average is rather useless in practice because under constant load, the load increases significantly (to 0.3-0.4 as far as I can tell).</p>

<p>What happens consequently, when multiple instances are deployed on the same node, is that this node is heavily overloaded; pods are no longer responsive, are killed and restarted etc.</p>

<p>What is the best practice to find a good value? My current best guess is to increase the requested cpu to 0.3 or 0.4; I'm looking at Grafana visualizations and see that the pods on the heavily loaded node(s) converge there under continuous load.
However, how can I know if they would use more load if they could before becoming unresponsive as the node is overloaded?</p>

<p>I'm actually trying to understand how to approach this in general. I would expect an "ideal" service (presuming it is CPU-focused) to use close to <code>0.0</code> when there is no load, and close to 1.0 when requests are constantly coming in. With that assumption, should I set the <code>cpu.requests</code> to <code>1.0</code>, taking a perspective where actual constant usage is assumed?</p>

<p>I have read some <a href="https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-resource-requests-and-limits" rel="nofollow noreferrer">Kubernetes best practice guides</a>, but none of them seem to address how to set the actual value for cpu requests in practice in more depth than "find an average".</p>

Carsten
<p>Basically come up with a number that is your lower acceptable bound for how much the process runs. Setting a request of <code>100m</code> means that you are okay with a lower limit of your process running 0.1 seconds for every 1 second of wall time (roughly). Normally that should be some kind of average utilization, usually something like a P99 or P95 value over several days or weeks. Personally I usually look at a chart of P99, P80, and P50 (median) over 30 days and use that to decide on a value.</p>

<p>Limits are a different beast, they are setting your CPU timeslice quota. This subsystem in Linux has some persistent bugs so unless you've specifically vetted your kernel as correct, I don't recommend using it for anything but the most hostile of programs.</p>
