Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Shopify Engineering 8 min read Incident hardMaster

Debugging Systems in the Cloud: MySQL, Kubernetes, and Cgroups

Slow MySQL Pod startup and degraded query performance on long-running GKE nodes in Shopify's KateSQL platform traced back to a Linux kernel memory cgroup leak: roughly 50K zombie memory cgroups made mem_cgroup_commit_charge slow, so each 128MB mmap during InnoDB buffer pool initialization took about 100 ms. The investigation used strace, perf flamegraphs, slabtop and /proc/cgroups, and Google kernel engineers confirmed it as a side effect of slab reparenting on cgroup removal. Forcing kubepods memory.force_empty cut cgroups to about 1800, and an 80G buffer pool then initialized in five seconds. The permanent fix was upgrading to GKE 1.18 (COS 85, kernel 5.4). Interim options included recycling nodes, dropping caches and isolating short-lived Pods.

Assumes: Linux cgroupsKubernetes Pods and nodesInnoDB buffer poolperf and strace

Related posts

  • The case of the vanishing CPU: A Linux kernel debugging story

    ClickHouse hardMaster

    Intermittent, indefinite CPU saturation of ClickHouse Cloud pods, seen only on GCP, turned out to be a Linux kernel memory-management livelock. Pods sat just under their cgroup memory limit while every CPU spun in shrink_lruvec during memcg reclaim triggered by page-cache readahead on page faults. The investigation used gdb backtraces, bpftrace syscall latency histograms, perf top/stat, pidstat and an on-call runbook to reach a reproducible test case and a kernel fix, after which another kernel bug surfaced. One lesson along the way: signal-based user-space stack traces hide kernel time entirely, so gdb backtraces pointed the team at the wrong code.

  • Spin Infrastructure Adventures: Containers, Systemd, and CGroups

    Shopify Engineering hardMaster

    Spin development instances run systemd inside Kubernetes containers, and processes launched through systemd escaped the pod's memory cgroup, so pod memory limits were not enforced and instances could exceed their allotment and disturb neighbours. Using kubectl top and a stress test, the team showed that processes started via kubectl exec landed in the kubepods cgroup while those started via spin shell landed in an effectively unlimited hierarchy. Reproductions across containerd, Docker and Podman traced the cause to the cgroupfs driver: Podman's systemd cgroup driver correctly delegates limits to the in-container systemd. The leak came from bind-mounting /sys/fs/cgroup read-only, which leaves subdirectories writable, and the fix is switching to the systemd cgroup driver, which Container-Optimized OS plans to make the default in version 101.

  • Node.js and the tale of worker threads

    Zalando Engineering mediumAdept

    A Node.js service using cluster mode called os.cpus().length inside a Kubernetes container, which returns the host's core count, not the pod's CPU allocation. On a 48-core node it forked 48 processes inside a 2GB pod. Each needed about 120MB, so the processes were killed under memory pressure and immediately re-forked by the exit handler, flooding a translation service with startup requests (1,000 to 20,000 rpm) and causing cancelled connections and read timeouts. The initial diagnosis of a retry feedback loop caused by process.exit() on fetch failure turned out to be wrong. The fix was to drop cluster mode and let Kubernetes handle scaling, and the incident motivated adding event-loop lag and other signals through an internal Node.js observability SDK.

  • The Shift to cgroup v2 in Kubernetes: What You Need to Know

    Kubernetes Blog mediumAdept

    Kubernetes has deprecated cgroup v1: from v1.35 the kubelet refuses to start on cgroup v1 nodes by default (`failCgroupV1: true`), kubeadm preflight errors on it, and the fallback is slated for removal in v1.38. cgroup v2 enables Memory QoS with `memory.high` throttling and tiered `memory.min`/`memory.low` reservations, container-wide OOM kills via `memory.oom.group`, safe rootless delegation, eBPF-based device control, PSI metrics, and accurate Pod-level in-place resizing. Migration requires kernel 5.8+ (5.9+ for Memory QoS), a cgroup v2-capable runtime, and matching cgroup drivers, ideally systemd with CRI auto-detection. A step-by-step procedure traces Pod resource limits from the API through CRI, OCI spec, and systemd scope down to the actual cgroup files.

  • Clouds, caches and connection conundrums

    incident.io mediumAdept

    After migrating to Google Cloud, sporadic Postgres and memcached connection timeouts on GKE turned out to be node-wide, not process-local. Bursts of rapidly opened TCP connections, from concurrent cache sets, GCS URL generation and a runaway query fanning out external calls, spiked CPU in the Dataplane V2 anetd agent and caused dropped packets. Partial mitigations helped: static Postgres pools with a longer connection lifespan cut new connections from ~200/s to ~1/s, and raising memcache MaxIdleConns from 2 to 20 also reduced timeouts. The lasting fix is connection reuse plus limits on outbound network concurrency rather than disabling Dataplane V2. Network timeouts should be investigated at the node level, not just per pod.

The quest for software engineering knowledge.

Look:
Layout: