Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Kubernetes HFT tuning

Every latency setting in this guide, where it goes, and its evidence. Traced links to the nri-shared-cpus lab in this repository. Not measured here means the setting rests on kernel, vendor or Kubernetes documentation only. Node needs node-level access (boot line, kubelet, root on the host); a pod cannot set it. Pod works from the pod spec or the app.

Terms: deployment glossary.

This chapter is the list. It is not an image and it is not a second chart. The shared-CPU grant is Shared CPUs: public image ghcr.io/mimran1980/ergon-shared-cpus:0.1.6 and chart oci://ghcr.io/mimran1980/charts/ergon-shared-cpus version 0.1.6 (EKS AL2023 hot pods need kubeletConfigDir: EKS install). The refusal of an exec probe on a pod labelled ergon.io/latency: hot is the admission policy in Latency Pods. Hugepages, the isolated cpuset partition, io_uring seccomp and the NIC PHC are opt-in grants in that same image. The chart writes seccomp and ptp as "off". The kind sample k8s/nri-shared-cpus/examples/try installs the public chart, prints the shared-CPU grant on an unlabelled pod, and shows the two hot-pod refusals: the plugin’s (no isolcpus on kind) and the admission policy’s. Not yet run on kind. It does not measure the rows below.

Settings

settingwhat it doeswhereevidenceapply
CPU isolationkeeps tasks, the timer tick, RCU callbacks and new interrupts off the busy CPUsnodeNO_HZ, kernel-parameters.txt; traced: with the quiet-CPU settings below an isolated CPU’s max was 4.81 to 5.52 µs (nri-shared-cpus)boot line isolcpus=managed_irq,domain,<busy> nohz_full=<busy> rcu_nocbs=<busy> irqaffinity=<housekeeping> (hosts)
NIC queue interrupts off the loop’s CPU, irqbalance off, re-pinned after every NIC resetthe interrupt handler does not run on the loop’s CPUnodeENA’s driver source (ena_setup_io_intr); not measured herehosts
ENA moderation off: adaptive-rx off rx-usecs 0one interrupt per packet; no adaptive-moderation work on the polling CPUnodeENA driver, AWS Graviton performance runbook; not measured hereethtool -C <if> adaptive-rx off rx-usecs 0, again after every NIC reset
SMT off (x86)one Kubernetes CPU is one physical corenodesiblings share one core’s execution units; not measured hereEC2 CpuOptions ThreadsPerCore: 1, or nosmt (SMT off)
static CPU manager, full-pcpus-onlyGuaranteed whole-CPU containers get CPUs of their ownnodeKubernetes CPU management; not measured herekubelet block
reservedSystemCPUs = the housekeeping CPUssystem daemons stay off the exclusive CPUsnodesame Kubernetes page; not measured herekubelet block
no CPU quota on a busy containerthe kernel never stops the container mid-periodnode + podsched-bwc, Kubernetes PR #127525 (kubelet 1.33+); not measured here (tune/src/quota.rs T9)kubelet 1.33+, static CPU manager, Guaranteed pod, whole-number cpu. Not cpuCFSQuota: false (why)
Guaranteed QoS, whole-number cputhe only pods the static CPU manager gives exclusive CPUspodKubernetes CPU management page; not measured herepod block
each busy thread pinned to one CPU of the pod’s cpusetthe thread stays on its exclusive CPUpodnot measured heresched_setaffinity from Cpus_allowed_list (busy-spin loop)
an io_uring SQPOLL thread on its own CPUthe kernel’s polling thread does not share the loop’s corepodnot measured herepin it to a CPU of the pod’s own outside the shared CPUs (shared CPUs)
transparent hugepages neverno khugepaged (it runs under madvise too), whose lru_add_drain_all runs a kworker on every CPU with queued pagesnodetraced: it was an isolated CPU’s only context switch and its 16.25 µs max (nri-shared-cpus)transparent_hugepage=never on the boot line, or never into /sys/kernel/mm/transparent_hugepage/enabled at boot
fair server off on the isolated CPUsno 1 s deadline-server timer kicking them (a nohz kick and a reschedule IPI) and keeping their tick onnodetraced, kernel 6.12: 56 kicks a minute with gaps to 14.1 µs, then 0 after (nri-shared-cpus)echo 0 > /sys/kernel/debug/sched/fair_server/cpu<N>/runtime for each isolated N, at every boot after debugfs is mounted (not persistent; kernel 6.12+). Only where nothing real-time runs on those CPUs: not with SCHED_FIFO
node events out of trading hourslru_add_drain_all callers (block-device ioctls, systemctl daemon-reload and generators, mlock, page migration) and BPF loads (systemd units, container starts with seccomp, SSH logins) reach every isolated CPUnode (operations)traced: a systemd daily timer gave a 40.60 µs max and one context switch (nri-shared-cpus)systemd timers moved off trading hours, no pod churn and no SSH logins on the node during trading
Aeron directory on a sized 2 MiB hugetlbfs, AERON_FILE_PAGE_SIZE=2097152, AERON_TERM_BUFFER_SPARSE_FILE=falseno 4 KiB page faults on the log buffersnode (pool, mount) + driver podhugetlbpage; not measured here. An unsized hugetlbfs reports no free space, which Aeron’s storage check refuses (aeron_fileutil.c:952-959 in rusteron-media-driver 0.2.11)hosts; the three variables in the driver pod’s env
AERON_CLIENT_PRE_TOUCH_MAPPED_MEMORY=truea client faults its mapped terms in at startpod (client)aeronc.h:170 (rusteron-client 0.2.11); not measured herepod block
net.core.rmem_max, wmem_max ≥ Aeron’s socket bufferslets the kernel grant AERON_SOCKET_SO_RCVBUFnodefunctional, not latency: the driver refuses a window larger than the granted SO_RCVBUF (aeron_driver.c:407-456, rusteron-media-driver 0.2.11). Aeron’s default is 128 KiB (aeron_driver_context.c:191); only a raised buffer, such as 2 MiB, needs itsysctl -w net.core.rmem_max=16777216 net.core.wmem_max=16777216
automatic NUMA balancing offno balancing page faults on pinned threadsnodenot measured heresysctl -w kernel.numa_balancing=0
topology manager single-numa-nodea pod’s CPUs and devices on one NUMA nodenodeKubernetes topology manager docs; not measured herekubelet block
the CPU that takes the NIC interrupts capped at C1 (intel_idle)an interrupt does not wait for that CPU to wake from C6nodecpuidle; not measured here. acpi_idle (AWS c7a): nothing deeper than C1 to cap. ergon-tune T20per CPU echo 1 > /sys/devices/system/cpu/cpu<N>/cpuidle/state<i>/disable for every state past C1, or pm_qos_resume_latency_us 1; intel_idle.max_cstate=1 caps every CPU. Write it at every boot
C-states capped at C1 on every CPU (x86)an idle housekeeping core wakes fasternodenot measured hereoptional; a spinning core never idles, so it reaches only the housekeeping cores
TCP autocorking offa small send goes out at once, not after the previous one’s transmit completes (TCP_NODELAY does not stop autocorking)pod netns, or node for hostNetworknet/ipv4/tcp.c tcp_should_autocork; not measured here. ergon-tune T21sysctl -w net.ipv4.tcp_autocorking=0; in a pod securityContext.sysctls, allowed by the kubelet’s --allowed-unsafe-sysctls
SCHED_FIFO on the loopreal-time prioritypodsched-rt-group: RT throttling can take the CPU away; not measured here. Not built into the Kubernetes pluginsthe app keeps SCHED_OTHER (latency pods)
ENA receive ring rx 4096room for burstsnodenot measured hereethtool -G <if> rx 4096
global busy polling (net.core.busy_read, busy_poll)every socket read on the host spinsnodeNAPI; not measured hereleave unset: it reaches every socket on the host; busy-poll per socket (SO_BUSY_POLL)
quiet-core spin testfinds CPUs the platform stallsnodenot measured here. A pod cannot choose its coresrun it on new nodes; cordon or replace noisy ones
no exec probes, no restartPolicy: Always sidecars on hot podsno probe process lands on the loop’s CPUpodan exec starts on any CPU of the cpuset (k8s/nri-shared-cpus/README.md, Limits); not measured herehttpGet/tcpSocket/grpc probes; the admission policy enforces it
both hosts in one cluster placement groupshorter network path between the pairnode (cloud)AWS docs; not measured herethe node group’s placement group
build for the CPU (-mcpu, target-cpu)Graviton: inline atomics instead of gcc’s outline helpersbuildnot measured herehosts
chrony on a PTP clockCLOCK_REALTIME stays close to UTCnodevendor docs; not a latency setting (Clocks)time sync

Copy-paste

Kubelet (EKS NodeConfig; k3s: Kubernetes):

apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cpuManagerPolicy: static
cpuManagerPolicyOptions:
  full-pcpus-only: "true"
reservedSystemCPUs: "0"          # the housekeeping cores
topologyManagerPolicy: single-numa-node
# cpuCFSQuota stays true: the kubelet drops it for exclusive CPUs (1.33+)

App pod: Guaranteed, whole cores, Aeron’s directory on the node’s hugetlbfs. AERON_FILE_PAGE_SIZE and AERON_TERM_BUFFER_SPARSE_FILE are read only by the media driver: set them on the driver’s pod.

apiVersion: v1
kind: Pod
spec:
  priorityClassName: <your latency class>
  containers:
  - name: app
    resources:
      requests: { cpu: "2", memory: 1Gi, hugepages-2Mi: 1Gi }
      limits:   { cpu: "2", memory: 1Gi, hugepages-2Mi: 1Gi }
    env:
    - { name: AERON_CLIENT_PRE_TOUCH_MAPPED_MEMORY, value: "true" }
    volumeMounts:
    - { name: huge, mountPath: /mnt/huge-aeron }
  volumes:
  - name: huge
    hostPath: { path: /mnt/huge-aeron, type: Directory }

Pin each busy thread to one CPU of the pod’s cpuset before the loop starts (busy-spin loop).

Check it

# 1. no CPU quota on the busy container
cat /sys/fs/cgroup/cpu.max               # expect: max 100000
grep throttled /sys/fs/cgroup/cpu.stat   # nr_throttled stays flat

# 2. the pod got whole cores of its own
grep Cpus_allowed_list /proc/self/status

# 3. the host: ergon-tune names each missing setting and its fix
ergon-tune --hot <busy CPUs>         # on the node

Under ERGON_HOST_CHECKS=require a caller of ergon-tune refuses to start while any check warns or a proof check stays unproven (ergon-tune). In a stock static-CPU-manager pod K2 stays unproven, so require refuses it (checks inside a pod).

  • A pod that uses the shared-CPU plugin: check the node with ergon-cpus explain before it starts (shared CPUs).

Open

  • Nothing here measures hugepages, the RX ring, NUMA settings or the CPU quota on latency.
  • The nri-shared-cpus lab traced its own maxima: after THP never and the fair server off, an isolated CPU on one Azure Cobalt VM took max 4.81 to 5.52 µs and no context switch in 60 s reps, the rest below the guest kernel (the hypervisor, 3.5 to 5.5 µs) (benchmarks).

More

pagefor
Kubernetesthe EKS node config, No CPU quota, SMT off, keeping other pods off the node
Hoststhe same settings on a VM, and how to apply each
Shared CPUshelper threads on the node’s housekeeping CPUs (k8s/nri-shared-cpus)
Latency podshugepages, io_uring, PHC devices on a pod (k8s/nri-latency-pods)