Linux: understanding cgroups and CPU quotas
How cgroups work (quota and period) and commands to observe per-group usage.
Cgroups (control groups) are the Linux kernel mechanism that limits and measures the resources (CPU, memory, I/O) used by a group of processes. They underpin Docker container resource isolation.
CPU quota principle
Think of a carousel: you buy a number of tickets that are valid for a given time.
- the tickets are the quota (allowed CPU time);
- the duration (for example one day) is the period.
A group can therefore only use its CPU quota per period; beyond that it is throttled until the next period.
Observing cgroups
# Live resource usage per cgroup (systemd)
systemd-cgtop
# CPU statistics, including throttling (cgroup v1)
cat /sys/fs/cgroup/cpu/cpu.stat