Profiling and finding the bottleneck
A method for "the service is slow": narrow from the outside in, check every resource with the USE method, read flame graphs, find waiting time that a CPU profile cannot see, and recognize the usual culprits, with tested C#.
GuideApplied21 min readUpdated
- 6 code samples
- 7 interviewer follow-ups
- 3 self-checks
On this page12 sectionsHLDSenior depth
Read first: Latency, throughput and queues
- Narrow a slow request from the outside in, with cheap broad checks before narrow expensive tools.
- Run the USE method over every resource, including the software ones (threads, pools, locks).
- Read a flame graph, know what a CPU profile cannot see, and use off-CPU analysis when the CPU is idle.
- Recognize the common signatures: lock contention, GC, thread pool starvation, N+1 calls, pool exhaustion, container CPU throttling.
- Predict the effect of a fix with Amdahl's reasoning, then verify it and add a guard against regression.
2 code samples (108 lines), collapsed so the explanation stays in focus.
"The service is slow" is the start of an investigation, not a diagnosis. The skill is a method that narrows quickly, does not chase noise, and ends with evidence you can show someone. Without one, people optimize the code they happen to know, and the code they optimize is rarely the code that matters.
Start by making the symptom precise: which endpoint, which percentile, since when, for whom, and what changed around then (a deploy, a config flag, traffic, data growth, a dependency). A time series that shows the step is worth more than any tool.
slow request
|
+-- outside our code (client, network, a queue before the app)
| -> compare client and server latency; fix upstream
|
+-- inside the service: which resource is full?
|
+-- CPU busy ........... CPU profile
+-- CPU idle, waiting .. off-CPU view: locks, pools, I/O
+-- memory, GC ......... allocation profile, GC counters
+-- disk or network .... queue depths, retransmits- Is the time inside the service at all? The caller's latency includes the network, the load balancer and the wait before your code starts. If the service's own timer shows the same rise, the problem is inside it. If not, look upstream.
- Which resource is full? Check utilization, saturation and errors for every resource (the USE method below). This takes seconds and rules out most of the map.
- What is it doing with that resource? Only now reach for a profiler: a CPU profile if the CPU is the limit, an off-CPU view if threads are waiting, an allocation profile if memory churn is the cost, a trace if the time is spread across services.
- Predict, change one thing, measure again. The prediction is what turns a hunch into a test.
Brendan Gregg's USE method is a checklist you can run without understanding the system: for every resource, check Utilization (how busy), Saturation (is work waiting) and Errors. Resources include the hardware (CPUs, memory, disks, network interfaces) and the software that behaves like one: thread pools, connection pools, locks, queues, file descriptors. The point is completeness. A bottleneck you did not think to look at is the one you will miss.
| Resource | Utilization | Saturation | Errors |
|---|---|---|---|
| CPU | Busy percentage, per core | Run queue length beyond the core count | Machine check errors, throttling |
| Memory | Used versus available | Swapping, page scanning, GC pressure | Out-of-memory kills, allocation failures |
| Disk | Busy time | Queue length, wait time | Device errors |
| Network | Bytes against line rate | Drops, retransmits, queue backlog | Interface errors, resets |
| Thread or connection pool | Busy fraction | Callers waiting, queue length | Timeouts, rejections |
| Lock | Held fraction of time | Threads blocked on it | Deadlocks, timeouts |
A short, standard sequence (popularized by Brendan Gregg at Netflix) covers most of the table above before you open a profiler:
| Command | What it shows | What to look for |
|---|---|---|
uptime | Load averages over 1, 5 and 15 minutes | Rising load. On Linux it counts tasks waiting on disk I/O as well as on the CPU |
dmesg -T (last lines) | Kernel messages | Out-of-memory kills, TCP drops, hardware errors |
vmstat 1 | Run queue r, swapping, CPU split us sy id wa st | r above the core count means CPU saturation; si and so mean swapping; high sy is kernel time; st is time stolen by the hypervisor |
mpstat -P ALL 1 | Per-core utilization | One core at 100% with the rest idle: a single-threaded bottleneck or poor interrupt spreading |
pidstat 1 | CPU per process | Which process is burning it |
iostat -xz 1 | Disk wait time, queue size, busy percentage | High wait or busy time means a saturated device |
free -m | Memory and file cache | Low available memory, a shrinking cache |
sar -n DEV 1 | Network throughput per interface | A link near its limit |
sar -n TCP,ETCP 1 | TCP connections and retransmits | Retransmits that never reach zero |
top | A summary of everything above | A check that nothing was missed |
Averages over a minute hide bursts, so also look at one-second data, as these commands do. A core that touches 100% for 200 ms every second is a queue factory, and it will not show in a one-minute average.
| Kind | How it works | Good for | Watch out for |
|---|---|---|---|
| Sampling (on-CPU) | Interrupt about 99 times a second per core and record the stack | Finding where CPU time goes, with low overhead | Statistical: short events and exact counts are invisible |
| Instrumentation | Add code at function entry and exit, or use a tracer | Exact counts and timings in a narrow, controlled area | The overhead distorts what it measures |
| Off-CPU | Record the stack when a thread blocks and when it resumes | Time spent waiting on locks, I/O, pools and other threads | Needs scheduler events (on Linux, eBPF tools); output is large |
| Allocation | Sample allocations with their stacks | Garbage collection pressure, where the churn comes from | Allocation rate matters, not just size |
| Distributed tracing | Spans with timing across services | Where a request spends time across hops | Sampling decides which slow requests you will have a trace for |
Why 99 Hz and not 100. A sampler that runs at exactly 100 Hz can stay in lockstep with a timer that fires every 10 ms and see the same code over and over. Sampling at 99 Hz drifts relative to it. How precise a sampling profile is follows from how many samples land in a frame: a function at 1% of 3,000 samples has about 30 samples behind it, enough to rank it and not enough to compare it to a frame at 1.2%.
On-CPU versus off-CPU. A CPU profile only sees time spent running. A request that waits 200 ms for a lock, a connection or a downstream call spends that time off the CPU, so it is invisible in a CPU flame graph. This is the classic trap: low CPU, high latency, and a profile that shows nothing wrong. When the CPU is idle and the requests are slow, switch to an off-CPU view or a thread dump.
Symbolization. A profile is only useful if frames have names. Native stacks need frame pointers or debug information to unwind. Managed runtimes need help: for .NET on Linux, perf can read a map of JIT-compiled code if the process runs with DOTNET_PerfMapEnabled=1, and the dotnet-trace tool records managed stacks directly through the runtime's event pipe. Garbled stacks are a tooling problem, not a finding.
Continuous profiling. Sampling is cheap enough to leave on. Google's published design (Google-Wide Profiling) samples across a whole fleet all the time, so that when something regresses you can compare yesterday's profile with today's instead of reproducing the problem. Open-source continuous profilers exist for the same idea. The rules are the ones for any production telemetry: low and bounded overhead, a symbolization pipeline, access control (stacks can reveal data), and a way to attach a profile to a deploy.
A flame graph (invented by Brendan Gregg) merges thousands of stack samples into one picture:
- Width is the share of samples. A frame twice as wide was on the stack twice as often. The horizontal order is alphabetical, not chronological, so left to right is not "before to after".
- Height is stack depth. The bottom is the entry point, each frame above it was called by the one beneath.
- The top edge is where the CPU was. Wide plateaus at the top are functions that burn time themselves (self time). A wide frame that is only wide because its children are wide (total time) is a place to look further up.
- Look for the widest plateau first, then ask whether it is necessary work, repeated work or accidental work.
- A differential flame graph colors frames by how their share changed between two profiles, which is the fastest way to see what a deploy did.
Underneath, a flame graph is a tree built from "folded" stacks: one line per distinct stack, with a sample count, such as main;Handle;Validate;Regex..ctor 450. That format is easy to produce, aggregate and diff, and it is worth being able to write the aggregator, because it shows what the picture is made of.
C# · FrameNode, FlameProfile
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
public sealed class FrameNode
{
private readonly Dictionary<string, FrameNode> _children = new Dictionary<string, FrameNode>();
public FrameNode(string name) { Name = name; }
public string Name { get; }
/// <summary>Samples where this frame, or anything it called, was on the stack.</summary>
public long Total { get; private set; }
public IReadOnlyDictionary<string, FrameNode> Children => _children;
/// <summary>Samples where this frame itself was the top of the stack: time spent in its own code.</summary>
public long Self => Total - _children.Values.Sum(c => c.Total);
internal void Add(string[] stack, int depth, long samples)
{
Total += samples;
if (depth == stack.Length) return;
if (!_children.TryGetValue(stack[depth], out var child)) _children[stack[depth]] = child = new FrameNode(stack[depth]);
child.Add(stack, depth + 1, samples);
}
}
public static class FlameProfile
{
/// <summary>Build the tree from folded stacks: "main;Handle;Parse 12" means this stack was seen in 12 samples.</summary>
public static FrameNode Parse(IEnumerable<string> folded)
{
var root = new FrameNode("all");
foreach (var line in folded)
{
if (string.IsNullOrWhiteSpace(line)) continue;
int space = line.LastIndexOf(' '); // the count follows the last space: frame names can contain spaces
long samples = long.Parse(line.Substring(space + 1), CultureInfo.InvariantCulture);
root.Add(line.Substring(0, space).Split(';'), 0, samples);
}
return root;
}
// A function can appear in many stacks, so its self time is the sum over all of them.
private static Dictionary<string, long> SelfByFunction(FrameNode root)
{
var self = new Dictionary<string, long>();
void Walk(FrameNode node)
{
if (node != root) self[node.Name] = self.GetValueOrDefault(node.Name) + node.Self;
foreach (var child in node.Children.Values) Walk(child);
}
Walk(root);
return self;
}
public static List<(string Function, long Self)> HottestBySelf(FrameNode root, int top) =>
SelfByFunction(root).Where(kv => kv.Value > 0)
.OrderByDescending(kv => kv.Value).ThenBy(kv => kv.Key, StringComparer.Ordinal)
.Take(top).Select(kv => (kv.Key, kv.Value)).ToList();
/// <summary>How each function's share of the samples moved between two profiles: the idea behind a differential flame graph.
/// Shares, not counts, so profiles of different length or load can be compared.</summary>
public static List<(string Function, double Change)> ShareChange(FrameNode before, FrameNode after)
{
var a = SelfByFunction(before);
var b = SelfByFunction(after);
return a.Keys.Union(b.Keys)
.Select(f => (f, (double)b.GetValueOrDefault(f) / after.Total - (double)a.GetValueOrDefault(f) / before.Total))
.OrderByDescending(x => Math.Abs(x.Item2)).ThenBy(x => x.f, StringComparer.Ordinal)
.ToList();
}
/// <summary>The most a frame holding `share` of the CPU can speed the whole thing up if it became free (Amdahl).</summary>
public static double MaxSpeedup(double share) => 1 / (1 - share);
}C#
var before = FlameProfile.Parse(new[]
{
"main;Handle;Validate;Regex..ctor 450",
"main;Handle;Serialize;Json.Write 250",
"main;Handle;Query;Db.Execute 150",
"main;Handle;ReadBody 100",
"main;Gc 50",
});
var after = FlameProfile.Parse(new[]
{
"main;Handle;Validate;Regex.IsMatch 90", // the pattern is now built once and reused
"main;Handle;Serialize;Json.Write 250",
"main;Handle;Query;Db.Execute 150",
"main;Handle;ReadBody 100",
"main;Gc 50",
});
Debug.Assert(before.Total == 1000 && after.Total == 640); // the same traffic costs 36% less CPU
var hottest = FlameProfile.HottestBySelf(before, 2);
Debug.Assert(hottest[0] == ("Regex..ctor", 450) && hottest[1] == ("Json.Write", 250));
var handle = before.Children["main"].Children["Handle"];
Debug.Assert(handle.Total == 950 && handle.Self == 0); // wide because of its children, with no time of its own
var moved = FlameProfile.ShareChange(before, after);
Debug.Assert(moved[0].Function == "Regex..ctor" && Math.Abs(moved[0].Change + 0.45) < 1e-9); // 45 points of share, gone
Debug.Assert(Math.Abs(FlameProfile.MaxSpeedup(0.45) - 1.818) < 0.001); // a 45% frame caps the gain at 1.8xThe last line is the habit worth keeping. Before you spend a week on a frame, convert its share into the largest possible gain. A frame at 5% can never buy more than 5%.
| What you see | Likely cause | Confirm with | Typical fix |
|---|---|---|---|
| CPU high, mostly user time, a wide plateau in the profile | A hot loop, serialization, regular expressions, logging, an algorithm that scales badly | CPU flame graph | Remove repeated work, cache, change the algorithm |
CPU high, large system time (sy) | Too many system calls, context switches or small I/O operations | pidstat -w, perf trace or strace -c (which slows the process a lot) | Batch, buffer, reduce syscalls |
| CPU low, latency high, threads waiting | Lock contention, an exhausted pool, a slow dependency | Off-CPU view, thread dump, lock contention counters | Shrink critical sections, shard locks, add timeouts and bulkheads |
| Regular latency spikes, high allocation rate | Garbage collection, especially generation 2 and large-object collections | Runtime counters: collections per generation, time in GC, allocation rate | Allocate less (pooling, spans, structs), tune GC mode |
| .NET: pool queue length grows while CPU is low | Thread pool starvation from blocking on async work (.Result, .Wait()) | Pool queue length and thread count counters | Make the path asynchronous end to end. The pool adds threads slowly (about one per half second past its minimum) |
| Many small sequential calls in a trace | N+1 queries or a chatty protocol | A trace, or the database's query log | Batch, join, cache, fetch what the page needs in one call |
| Timeouts waiting for a connection | Connection pool too small, leaked connections, long transactions | Pool wait metrics | Size from Little's Law, fix leaks, shorten transactions |
| Latency spikes with CPU well under its limit, in a container | CPU quota throttling (below) | nr_throttled and throttled time in the cgroup's CPU stats | Raise or remove the CPU limit, or run fewer busy threads |
| Throughput stuck with no resource busy | A software limit: a lock, a single-threaded loop, a rate limiter, a per-connection window | Per-thread CPU, TCP window and round-trip time | Remove or widen the limit |
| Steady retransmits, slow transfers | Packet loss or buffer problems | sar -n ETCP, ss -ti, packet capture | Fix the path, tune buffers, move closer |
| Latency worse right after a deploy, then better | Cold caches, connection pools and compiled code | Hit ratio, connection counts at deploy time | Warm up, coalesce duplicate requests, stagger restarts |
| Inconsistent results on a cloud host | A noisy neighbor, or stolen time (st in vmstat) | Compare runs on dedicated hosts | Move, isolate, or pin |
A container trap: CPU quota throttling
A container with a CPU limit gets a quota of CPU time per scheduling period (100 ms by default). A limit of 2 CPUs means 200 ms of CPU time per 100 ms period, spread across any number of threads. If eight threads are busy, they use the whole quota in 25 ms of wall-clock time, and then every thread is frozen for the remaining 75 ms of the period. Average CPU use over a minute can sit well below the limit while requests that land in the frozen window wait up to 75 ms. The signature is p99 latency that jumps in steps near multiples of the period, a modest average CPU, and a throttling counter that keeps rising. Kubernetes exposes it as throttled periods against total periods for the container.
0 ms 25 ms 100 ms
|-------------------|-----------------------------------------------|
| 8 threads run: | throttled: every thread is frozen until the |
| 8 x 25 ms = 200 | next period begins |public static class Cfs
{
/// <summary>Milliseconds of each period a container spends frozen, given its CPU limit and the number of busy threads.</summary>
public static double ThrottledMs(double limitCpus, double periodMs, int busyThreads)
{
double quotaMs = limitCpus * periodMs; // CPU time allowed per period
return Math.Max(0, periodMs - quotaMs / busyThreads); // the quota runs out after quota / threads of wall time
}
}Debug.Assert(Cfs.ThrottledMs(limitCpus: 2, periodMs: 100, busyThreads: 8) == 75); // 8 threads, 2 CPUs: frozen three quarters of the time
Debug.Assert(Cfs.ThrottledMs(2, 100, 2) == 0); // 2 threads never outrun a 2 CPU quota
Debug.Assert(Cfs.ThrottledMs(4, 100, 16) == 75); // the same ratio, the same stallThe fix depends on the goal. For latency-sensitive services, a request (the guaranteed share) without a hard limit avoids throttling entirely. If you must limit, cap the number of runnable threads to the limit, because more threads than CPUs only brings the freeze closer.
This is a composite example with illustrative numbers. The /search endpoint's p99 went from 180 ms to 360 ms about three minutes after a deploy. The p50 barely moved.
- Scope it. Only
/search, with a clear step in the time series right after the deploy. The deploy is the prime suspect, but the evidence must still come from measurement. - Inside the service? The service's own latency histogram shows the same rise. The time is not in the network or the load balancer.
- USE every resource. Average CPU went from 40% to 62%, with bursts near 100% on some cores. Memory is flat and the garbage collector's counts are unchanged. Pool queues are empty, database latency has not moved. CPU is the resource to examine.
- Profile it. A 30-second CPU profile at 99 Hz, compared with the one from the previous release, shows 45% of samples under
Validate, all inRegex..ctor. The previous profile had no such frame. - Form the hypothesis and a prediction. The deploy replaced a pre-built regular expression with one constructed on every request. Removing it should cut CPU by about 36% (the "after" profile above is 640 samples against 1,000) and, because the p99 comes from bursts that queue behind busy cores, bring p99 back near 180 ms. Amdahl's bound says the best possible throughput gain is 1.8×.
- Change one thing. Build the pattern once, in a static field.
- Measure again. CPU returns to about 40%, and the p99 to about 190 ms: the prediction held, which is the evidence that the diagnosis was right rather than lucky.
- Lock it in. Add an allocation benchmark for the validation path with a threshold, keep the profile diff in the release checklist, and alert on CPU per request, not just CPU.
Measuring allocations
Many regressions are allocation regressions: no single function is slow, but the garbage they create keeps the collector busy. You can measure allocation directly and turn it into a test. The runtime counts the bytes each thread allocates, so a function's allocation cost is a difference of two readings.
public static class AllocationMeter
{
/// <summary>Bytes the current thread allocates while `work` runs. It runs once first, so one-time costs (type loading, caches) are not counted.</summary>
public static long Measure(Action work)
{
work();
long start = GC.GetAllocatedBytesForCurrentThread();
work();
return GC.GetAllocatedBytesForCurrentThread() - start;
}
}// Building a 2,000-character string by repeated concatenation copies it every time: about 2,000 strings, each longer than the last.
long concatenated = AllocationMeter.Measure(() => { string s = ""; for (int i = 0; i < 2_000; i++) s += "x"; });
long buffered = AllocationMeter.Measure(() =>
{
var sb = new StringBuilder();
for (int i = 0; i < 2_000; i++) sb.Append('x');
sb.ToString();
});
Debug.Assert(concatenated > 50 * buffered); // megabytes of garbage against kilobytes: hundreds of times moreInterviewer follow-upL5A service is slow. Walk me through what you do.How to answer
Make the symptom precise (endpoint, percentile, start time, what changed). Decide whether the time is inside the service by comparing client-side and server-side latency. Run a USE check on every resource, including pools and locks. Profile the resource that is full: a CPU profile if the CPU is busy, an off-CPU view if threads are waiting, allocations if memory churn is the cost. Form a hypothesis with a predicted effect, change one thing, and measure again. Add a guard so the fix stays.
Interviewer follow-upL6A CPU flame graph shows 35% of samples in JSON serialization. Is that the problem?How to answer
Not necessarily. First ask whether the CPU is the bottleneck for the symptom at all: a flame graph only shows where running time goes, not what requests wait on. Then bound the gain: if serialization became free, throughput could improve by at most 1 ÷ (1 − 0.35) = 1.54×. Then ask whether the work is necessary (is it serializing the same object repeatedly, or more fields than the caller needs?). Only then decide if the fix is worth its cost.
Interviewer follow-upL6CPU is low, latency is high, and the profile shows nothing wrong. What next?How to answer
The time is being spent waiting, so use an off-CPU view or thread dumps. Look for threads blocked on a lock, a pool or a socket. Check pool wait metrics, connection counts, the slow-query log and downstream latencies, and compute Little's Law for each pool to see whether the limit is simply too small. In .NET, check the thread pool queue length and for blocking calls on async paths.
Interviewer follow-upL6In Kubernetes, p99 spikes while the container's CPU is at 40% of its limit. Why?How to answer
Likely CFS quota throttling. The limit is enforced per 100 ms period, so a multi-threaded process can spend its quota in a fraction of the period and then be frozen for the rest, even though the average over a minute is low. Confirm with the throttling counters. Fix by removing or raising the limit (keeping a request for scheduling), by reducing the number of busy threads, or by sizing the limit for the burst rather than the average.
Interviewer follow-upL7How do you profile a production service safely?How to answer
Prefer low-overhead sampling (on the order of 99 Hz, with overhead measured and bounded), started on a small canary share of instances first. Avoid tools that stop the process or trace every call. Keep symbolization and storage off the hot path, restrict who can read the profiles (stacks and arguments can expose data), and tag every profile with the build and the deploy. Continuous profiling makes this routine: you always have the "before" to compare with, and you never have to reproduce the problem to see it.
Interviewer follow-upL7Latency spikes every ten minutes. How do you find the cause?How to answer
Treat the period as the clue. Line the spike times up with things that run on a timer: cron jobs, garbage collection (generation 2), compaction or checkpointing in a datastore, cache expiry with the same TTL on many keys, log rotation, certificate or configuration reloads, DNS refresh, autoscaler cycles, a health check storm. Plot those events on the same time axis as the latency. Then catch a spike in the act: keep a ring buffer of traces or profiles and dump it when latency crosses a threshold, so you inspect the actual event.
Interviewer follow-upL7Throughput stops growing but no resource is saturated. Where do you look?How to answer
At software limits that do not show up as hardware utilization: a lock or a single-threaded event loop (check per-thread CPU), a pool or semaphore sized too small, a rate limiter, a per-connection window (throughput cannot exceed window ÷ round-trip time; see network performance), a downstream concurrency cap, or the load generator itself. Compute each candidate's ceiling the way the first lesson in this section does (units ÷ demand per request) and compare it with the observed plateau. The one that matches is the bottleneck.
- Clarify the symptom: which request, which percentile, when it started and what changed.
- Locate the time: client or server, and which hop, using timers and traces.
- Run USE over every resource, hardware and software, before choosing a tool.
- Choose the profiler to match: on-CPU, off-CPU, allocation or trace.
- Bound the gain with Amdahl and a prediction before changing anything.
- Change one thing and re-measure with the same method.
- Prevent a repeat: a benchmark or an alert, and a profile attached to every release.
A slow service is diagnosed by narrowing: outside or inside, which resource is full (USE, over hardware and software resources alike), then what that resource is doing, with a profiler chosen to match. A CPU flame graph shows only running time, so waiting needs an off-CPU view. The usual culprits have recognizable signatures, from garbage collection to thread pool starvation to container CPU throttling. Bound any fix with Amdahl, predict its effect, verify it, and leave a guard behind.
Try answering out loud before you reveal each answer.
QuestionA function holds 20% of the samples in a CPU profile. If you made it twice as fast, what is the best overall speedup?Reveal answer
Halving a 20% share removes 10% of the time, so the work takes 90% as long: a speedup of 1 ÷ 0.9 ≈ 1.11×. Even making it free tops out at 1 ÷ 0.8 = 1.25×.
QuestionLatency is high, CPU is at 15%, and the CPU flame graph looks healthy. Why, and what do you do?Reveal answer
The requests are waiting, not running, and a CPU profile only sees running time. Use an off-CPU analysis or thread dumps to find what the threads block on: locks, pools, I/O or a slow dependency. Check pool wait metrics and apply Little's Law to each pool.
QuestionA container limited to 2 CPUs runs 8 busy threads with a 100 ms period. How long is it frozen in each period, and what does the user see?Reveal answer
The quota is 200 ms of CPU time per period. Eight busy threads use it in 25 ms, so the container is frozen for the remaining 75 ms. Requests arriving in that window wait up to 75 ms, so p99 rises even though average CPU is below the limit.
- Brendan Gregg, "Linux Performance Analysis in 60,000 Milliseconds", Netflix Technology Blog, 2015: the ten-command checklist.
- Brendan Gregg, "The Flame Graph", ACM Queue 14(2), 2016; and Systems Performance, 2nd edition, Addison-Wesley, 2020, for the USE method, off-CPU analysis and the Linux tools.
- Ren and co-authors, "Google-Wide Profiling: A Continuous Profiling Infrastructure for Data Centers", IEEE Micro, 2010.
- Microsoft documentation for the .NET diagnostics tools (
dotnet-counters,dotnet-trace,dotnet-gcdump) and forGC.GetAllocatedBytesForCurrentThread. - The Linux kernel documentation on CFS bandwidth control, which defines the quota and period behind container CPU limits.