kubernetes: [FG:InPlacePodVerticalScaling] Performance degradation in latency-sensitive services due to CPU affinity loss upon guaranteed QoS Pod scaling down

What happened?

For the latency-sensitive service in guaranteed QoS Pod, each worker has core affinity with a CPU. When the workload decreases, some workers are removed, and the worker’s affinity CPUs becoming idle. When the Pod scaling down, these idle CPUs were excepted to be removed. If the busy CPUs which run the busy worker are removed, the performance will be decreased for latency-sensitive services. For example: At the begin, there are 2 CPUs (CPU 1 anf CPU 11) are allocated to the Pod when Pod creation. When the workload increases, Pod scale up, and 4 additional CPUs (CPU 2,12,3,13) are allocated to the Pod, add another 4 workers and set core affinity to each CPU. Image

When the workload decreases, remove worker 4 and worker 5, CPU 3 and CPU 13 are idle, Ideal case: When Pod scale down, idle CPU 3 and CPU 13 are excepted to be removed. the workers not be affected. Image

Non-ideal case: When Pod scale down, busy CPU 2 and CPU 12 are removed. the worker2 and worker3 will be affected because of CPU migration due to CPU affinity loss. Image

What did you expect to happen?

When Pod scale down, idle CPU 3 and CPU 13 are removed, and busy CPUs are not removed.

So, we need some method or option to let container tell kubelet which CPU should be keep.

How can we reproduce it (as minimally and precisely as possible)?

Test based on https://github.com/kubernetes/kubernetes/pull/129719

Anything else we need to know?

No response

Kubernetes version

$ kubectl version
Client Version: v1.32.0
Kustomize Version: v5.5.0
Server Version: v0.0.0-master+da732990954ed92779d8fe396ab9e217f038d115

Cloud provider

Self-host

OS version

# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
6.5.0-41-generic #41~22.04.2-Ubuntu SMP PREEMPT_DYNAMIC Mon Jun  3 11:32:55 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here

Install tools

Container runtime (CRI) and version (if applicable)

Related plugins (CNI, CSI, …) and versions (if applicable)

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 22 (10 by maintainers)

Most upvoted comments

Migration between CPU cores is very cheap and fast operation on modern hardware. If application trying to do hard affinity of threads on dynamic resources, it should be able to handle situations when this resource disappears.

@kad For more complex situations, such as when there are multiple threads in a Pod. The app needs to regularly check the changes in cpuset and perform some operations on threads that need to change CPU affinity, which may take some time. In this case, for delay-sensitive services (such as carrier-grade services), in addition to the impact brought by CPU migration, during the recovery period, it is also need to share the CPU with other threads, and this period of time will have an impact on delay-sensitive services. To achieve seamless pod scaling for delay-sensitive services, it need to add an options to allow Pods to decide on CPU removal.

Hi! Just to add my two cents to it: Recently I’ve been doing some tests with network packet manipulation and capture using different scaling scenarios. Even when using pretty mid-range desktop systems and general internet browsing packet capture dumps I was able to show packet loss when switching CPU cores. I wasn’t looking deep into L1/L2 cache invalidation but rather overall performance dip when doing the switch. Taking microseconds to few milliseconds might have none or unnoticed impact on most applications, but will have linear impact on scenarios where data stream like packet capture if it gets faster the loss is bigger. Now considering carrier grade traffic rate when for example you want to log every packet with ‘new’ flag to have logs of users activity, when data rate is < 100 Mbps there’s almost no loss, but I’ve repeatedly saw few hundred packets loss at rates > 1 Gbps (~80 - 100 packets). In scenarios like this it is considerable data loss. And that’s using DPDK (I assume PF_RING would be the same) the loss was there, increasing caches of course only works up to certain point. So my point is there are scenarios where pinning to the core/setting affinity is only option to achieve high quality of service and there are for sure other applications/scenarios that need that featureset.

I wholeheartedly agree with two other issues that were raised here: dropping a portion of highly specific code with risk being potential huge pain to maintain without domain specific knowledge and general architectural approach. So for the first thing what we can do is to make sure there’s enough documentation to not leave any nooks and crannies undocumented and have it test covered. For the actual design as this is pretty complicated issue we’re open to any suggestions how in general would be a good, acceptable approach to implement this featureset.

I think a bug is fine, which should be solved in the context of the current in-place-VPA KEP

Thank you for your reply, is the in-place-VPA KEP you mentioned 1287-in-place-update-pod-resources?

yes this is the KEP I meant.