<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Thomas Zachmann</title>
    <description>The latest articles on DEV Community by Thomas Zachmann (@thomaszachmann).</description>
    <link>https://dev.to/thomaszachmann</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4266824%2F566fb46a-3ea2-4ef1-9e79-d5c4aaca8c82.jpg</url>
      <title>DEV Community: Thomas Zachmann</title>
      <link>https://dev.to/thomaszachmann</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thomaszachmann"/>
    <language>en</language>
    <item>
      <title>A 500m CPU limit turned 2,000 req/s into 70 % errors – measured on k3s</title>
      <dc:creator>Thomas Zachmann</dc:creator>
      <pubDate>Thu, 26 Nov 2026 12:06:03 +0000</pubDate>
      <link>https://dev.to/thomaszachmann/a-500m-cpu-limit-turned-2000-reqs-into-70-errors-measured-on-k3s-1l42</link>
      <guid>https://dev.to/thomaszachmann/a-500m-cpu-limit-turned-2000-reqs-into-70-errors-measured-on-k3s-1l42</guid>
      <description>&lt;p&gt;I moved a small URL shortener from three VMs onto a three-node k3s cluster and measured it with k6 before and after every change. One change looked harmless and wasn't: a CPU limit.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;k3s, three nodes (one with 4 vCPUs, two with 2 vCPUs)&lt;/li&gt;
&lt;li&gt;a Go service with two replicas, PostgreSQL via CloudNativePG&lt;/li&gt;
&lt;li&gt;k6 with a &lt;strong&gt;constant arrival rate&lt;/strong&gt;: 2,000 requests per second for 20 seconds, 90 % redirects, 10 % writes&lt;/li&gt;
&lt;li&gt;the service gives up on a request after 2 seconds (a timeout it already had)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then two runs that differ in exactly one line of the Deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  The result
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pod resources&lt;/th&gt;
&lt;th&gt;Requests/s served&lt;/th&gt;
&lt;th&gt;Failed requests&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;requests.cpu: 250m&lt;/code&gt;, &lt;code&gt;limits.cpu: 500m&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;1,344–1,390&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;69–75 %&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;requests.cpu: 250m&lt;/code&gt;, no CPU limit&lt;/td&gt;
&lt;td&gt;1,946–1,964&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0 %&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two runs each, on different days. At 1,000 requests per second the limit caused no errors at all – only p95 latency went from 10 ms to 23 ms. That is the dangerous part: in normal traffic, nobody notices. At the next peak, three out of four requests fail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why: CFS throttling
&lt;/h2&gt;

&lt;p&gt;A CPU limit of &lt;code&gt;500m&lt;/code&gt; does not mean "half a core". The kernel's CFS scheduler gives the container &lt;strong&gt;50 ms of CPU time per 100 ms window&lt;/strong&gt;, summed over all threads. A Go service spreads 1,000 requests per second across several threads and burns through that budget early in the window. For the rest of the window the container is not scheduled at all. Requests queue up, the queue grows, and once a request waits longer than the 2-second timeout it fails.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0jymhh2hw8co27pw4l53.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0jymhh2hw8co27pw4l53.png" alt="Timeline of three 100 ms CFS windows: four threads run for about 12.5 ms each, using the 50 ms quota, then all are throttled until the next window" width="799" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to see it in your own cluster
&lt;/h2&gt;

&lt;p&gt;The kubelet counts the windows. You don't need to log in to the node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# CFS periods and throttled periods of every container named "kurz" on node s2&lt;/span&gt;
kubectl get --raw /api/v1/nodes/s2/proxy/metrics/cadvisor \
  &lt;span class="o"&gt;|&lt;/span&gt; grep -E &lt;span class="s1"&gt;'^container_cpu_cfs_(periods|throttled_periods)_total'&lt;/span&gt; \
  &lt;span class="o"&gt;|&lt;/span&gt; grep &lt;span class="s1"&gt;'container="kurz"'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At 1,000 req/s, 44–67 % of all windows were throttled – with zero errors and a perfectly normal-looking CPU graph. In Prometheus, alert on the ratio:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rate(container_cpu_cfs_throttled_periods_total[5m])
  / rate(container_cpu_cfs_periods_total[5m])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: these counters only exist for containers &lt;strong&gt;with&lt;/strong&gt; a CPU limit. And &lt;code&gt;kubectl top&lt;/code&gt; is the wrong tool for this – metrics-server averages over 15 seconds and hides the bursts.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I do now
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CPU: request yes, limit only with a reason.&lt;/strong&gt; The request reserves capacity and gives weight when the node is busy. Without a limit, the pod may use idle CPU.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory: request and limit.&lt;/strong&gt; Memory can't be throttled, only taken away. In the same lab an 8 Mi limit started fine and got both pods &lt;code&gt;OOMKilled&lt;/code&gt; at the same moment under load.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;If you need limits&lt;/strong&gt; (multi-tenant clusters, &lt;code&gt;Guaranteed&lt;/code&gt; QoS): size them from measured bursts, not averages. With &lt;code&gt;cpu: 1&lt;/code&gt; as request and limit the same service had zero throttled windows at 1,000 req/s.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;p&gt;One service, one homelab, k6 running on one of the nodes. The exact numbers will differ in your cluster; the mechanism won't. Measure your own service under a constant arrival rate before you trust a limit.&lt;/p&gt;




&lt;p&gt;This is day 2 of my free hands-on course &lt;em&gt;System design on Kubernetes&lt;/em&gt; – every pattern on a real cluster, every decision measured with k6. Day 2 ("Measuring in the cluster") has all commands to reproduce it, no sign-up needed:&lt;br&gt;
&lt;a href="https://itdrills.com/books/system-design-kubernetes/course/tag02?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=cpu-limits" rel="noopener noreferrer"&gt;https://itdrills.com/books/system-design-kubernetes/course/tag02?utm_source=devto&amp;amp;utm_medium=social&amp;amp;utm_campaign=cpu-limits&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
      <category>performance</category>
      <category>sre</category>
    </item>
  </channel>
</rss>
