Kubernetes CPU multithreading Kubernetes CPU multithreading kubernetes kubernetes

Kubernetes CPU multithreading


The closest answer I found so far is this one:

For a single-threaded program, a cpu usage of 0.1 means that if youcould freeze the machine at a random moment in time, and look at whateach core is doing, there is a 1 in 10 chance that your single threadis running at that instant. The number of cores on the machine doesnot 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 previousdefinition.) There is no guarantee about which core you run on, andyou might run on a different core at different points in yourcontainer's lifetime. A cpu limit of 0.1 means that your usage is notallowed to exceed 0.1 for a significant period of time. A cpu requestof 0.1 means that the system will try to ensure that you are able tohave a cpu usage of at least 0.1, if your thread is not blockingoften.

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.


Take a look to this documentation related to resources in Kubernetes:

You can use resources as described in the article:

To specify a CPU request for a Container, include the resources:requests field in the Container resource manifest. To specify a CPU limit, include resources:limits.

In this exercise, you create a Pod that has one Container. The Container has a request of 0.5 CPU and a limit of 1 CPU. Here is the configuration file for the Pod:

apiVersion: v1kind: Podmetadata:  name: cpu-demo  namespace: cpu-examplespec:  containers:  - name: cpu-demo-ctr    image: vish/stress    resources:      limits:        cpu: "1"      requests:        cpu: "0.5"    args:    - -cpus    - "2"

Additional to your question:Yes it is not gonna run in parallels (multi core threads). But you can show few core for your application in pod and then use multi threads to execute it.

The args section of the configuration file provides arguments for the Container when it starts. The -cpus "2" argument tells the Container to attempt to use 2 CPUs.


I had a close look at the GitHub Issue Thread in question. There is a bit of back and forth in the thread, but I think I made sense of it and would like to share a couple of things that seem to be missing from the answers so far:

  • 100m is not the same as a 1/10 of core power. It is an absolute quantity of CPU time and will remain the same regardless of the number of cores in the node.
  • While CPU time might well given on multiple cores of the node, true parallelism still depends on having a CPU limit that is well over the CPU required by a single thread. Otherwise, your multi-threaded application will run concurrently (i.e. threads take turns on the CPU) rather than in parallel.