From dc060f97402064f228499672ab7b0fab7636c223 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Mon, 3 Feb 2025 01:12:05 +0100 Subject: [PATCH] chore(k8s): add troubleshooting note about golang apps underperforming --- knowledge base/kubernetes/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/knowledge base/kubernetes/README.md b/knowledge base/kubernetes/README.md index 26d90bc..bc99f30 100644 --- a/knowledge base/kubernetes/README.md +++ b/knowledge base/kubernetes/README.md @@ -40,6 +40,7 @@ Hosted by the [Cloud Native Computing Foundation][cncf]. 1. [Edge computing](#edge-computing) 1. [Troubleshooting](#troubleshooting) 1. [Dedicate Nodes to specific workloads](#dedicate-nodes-to-specific-workloads) + 1. [Golang applications have trouble performing as expected](#golang-applications-have-trouble-performing-as-expected) 1. [Recreate Pods upon ConfigMap's or Secret's content change](#recreate-pods-upon-configmaps-or-secrets-content-change) 1. [Run a command in a Pod right after its initialization](#run-a-command-in-a-pod-right-after-its-initialization) 1. [Run a command just before a Pod stops](#run-a-command-just-before-a-pod-stops) @@ -884,6 +885,17 @@ Leverage taints and node affinity: effect: "NoSchedule" ``` +### Golang applications have trouble performing as expected + +By default, Golang sets the `GOMAXPROCS` environment variable (the number of OS threads for Go code execution) **to the +number of available CPUs on the node running the Pod**.
+This is **different** from the amount of resources the Pod is allocated when a CPU limit is set in the Pod's +specification, and the Go scheduler might try to run more or less threads than the application has CPU time for. + +Properly set the `GOMAXPROCS` environment variable in the Pod's specification to match the limits imposed to the +Pod.
+If the CPU limit is less than `1000m` (1 CPU core), set `GOMAXPROCS=1`. + ### Recreate Pods upon ConfigMap's or Secret's content change Use a checksum annotation to do the trick: