Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes CPU multithreading

Tags:

cpu

kubernetes

I have a 4 cores CPU, I create a Kubernetes Pod with CPU resource limit 100m, which mean it will occupy 1/10 of a core power.

I wondering in this case, 100m is not even a full core, if my app is a multithread app, will my app's threads run in parallel? Or all the threads will run in the part of core (100 milli core) only?

Can anyone further explain the mechanism behind?

like image 765
Sam YC Avatar asked Nov 13 '18 08:11

Sam YC


People also ask

What is 500m CPU in Kubernetes?

For example, 500m CPU represents the roughly same amount of computing power whether that container runs on a single-core, dual-core, or 48-core machine. Note: Kubernetes doesn't allow you to specify CPU resources with a precision finer than 1m .

Should I set CPU limits Kubernetes?

CPU limits and Throttling Google, among others, highly recommends it. The danger of not setting a CPU limit is that containers running in the node could exhaust all CPU available. This can trigger a cascade of unwanted events such as having key Kubernetes processes (such as kubelet ) to become unresponsive.

How many threads can run in a pod?

You may use pod CPU limit 56 and run 56 threads to utilize all node cores.

How many cpus do I need for Kubernetes?

Total CPU limit of a cluster is the total amount of cores used by all nodes present in cluster. If you have a 2 node cluster and the first node has 2 cores and second node has 1 core, K8s CPU capacity will be 3 cores (2 core + 1 core).


1 Answers

The closest answer I found so far is this one:

For a single-threaded program, a cpu usage of 0.1 means that if you could freeze the machine at a random moment in time, and look at what each core is doing, there is a 1 in 10 chance that your single thread is running at that instant. The number of cores on the machine does not affect the meaning of 0.1. For a container with multiple threads, the container's usage is the sum of its thread's usage (per previous definition.) There is no guarantee about which core you run on, and you might run on a different core at different points in your container's lifetime. A cpu limit of 0.1 means that your usage is not allowed to exceed 0.1 for a significant period of time. A cpu request of 0.1 means that the system will try to ensure that you are able to have a cpu usage of at least 0.1, if your thread is not blocking often.

I think above sound quite logical. Based on my question, 100m core of CPUs power will spread across all the CPU cores, which mean multithreading should work in Kubernetes.

Update:

In addition, this answer explain quite well that, although it might be running a thread in single core (or less than one core power as per question), due to operating system's scheduling capability, it will still try to run the instruction unit in parallel, but not exceed the clocking power (100m as per question) as specified.

like image 146
Sam YC Avatar answered Sep 21 '22 10:09

Sam YC