sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Kubernetes resource limits

Open gajus opened this issue 4 years ago • 2 comments

I am trying to understand what is the correct value to use for Kubernetes pod resource limits.

Kubernetes documentation says:

Limits and requests for CPU resources are measured in cpu units. One cpu, in Kubernetes, is equivalent to 1 vCPU/Core for cloud providers [..] CPU is always requested as an absolute quantity, never as a relative quantity; 0.1 is the same amount of CPU on a single-core, dual-core, or 48-core machine.

– https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu

Meanwhile, I am on a 8 core machine and my configuration is:

resources:
  requests:
    memory: '1Gi'
    cpu: '50m'
  limits:
    memory: '4Gi'
    cpu: '2000m'

However, if I check sharp.concurrency(), it says that it is using 8 threads. Should I limit concurrency to 2, since Kubernetes resource limit is 2 cores?

gajus avatar Jul 06 '20 02:07 gajus

Yes, you'll probably want to experiment with sharp.concurrency(2) in this case to see if it offers better throughput for your given task.

I think cpu: '2000m' means schedule work on no more than 2 cores at any given point in time, which is not the same thing as how many cores are exposed inside a container and therefore available on which to schedule work.

lovell avatar Jul 06 '20 08:07 lovell

I think cpu: '2000m' means schedule work on no more than 2 cores at any given point in time, which is not the same thing as how many cores are exposed inside a container and therefore available on which to schedule work.

If I am reading their docs right, 2000m means use at the most the power of 2 CPUs, but it could be spread against any number of CPUs:

CPU is always requested as an absolute quantity, never as a relative quantity; 0.1 is the same amount of CPU on a single-core, dual-core, or 48-core machine.

I am asking here to get clarification from someone who might have experimented with different settings.

gajus avatar Jul 06 '20 13:07 gajus

I'll close as this hasn't attracted any further discussion but please feel free to reopen with more details if further help is required.

lovell avatar Apr 21 '23 09:04 lovell