Repository navigation
Description
The idea
The Go runtime starts every runsc process with one P per available CPU, and each P (about 16 KB) is allocated on the heap. On hosts with more than about 160 CPUs, the P structures alone push short-lived runsc commands (state, kill, delete, create, ...) and the gofer past the 4 MB first-GC trigger during package init. That GC then stops the world and starts mark workers on every P, which on a 192-CPU host costs more than the rest of small commands like runsc state, and leaves the gofer with about 45 extra threads per sandbox for no reason.
runsc could lower GOMAXPROCS to 8 in an init() that imports only runtime and syscall, so it runs before any package that allocates, but only when GOMAXPROCS is above 128 and the GOMAXPROCS environment variable is not set. The gofer, which is long-lived, would then restore the runtime default (runtime.SetDefaultGOMAXPROCS()) at the start of Execute. A test could check, via GODEBUG=inittrace=1,gctrace=1, that no GC runs before this init. With 128 CPUs or fewer, nothing changes, because the shrink itself stops the world and would cost more than it saves. containerd and Docker already set GOMAXPROCS for runsc commands, so there the CLI gain only applies to callers that exec runsc directly. runsc strips the variable for the gofer, so the gofer gain applies everywhere.
Note: this is complementary with #16153, which specifically sizes the Gofer.
Performance impact
- On a 192-CPU host:
runsc state-48% wall and -67% CPU; a create/start/checkpoint/restore/kill/delete cycle -20% wall and -67% CPU. - Gofer on 192 CPUs: PSS 10.0 MB → 8.2 MB, and 53 → 8 threads per sandbox, on every path.
SizeEmptycontainer size is -12% even when Docker setsGOMAXPROCS. - On hosts with somewhere between 129 and 160 usable CPUs, small commands are 8-13% slower (
runsc state+13% under a 150-CPU quota), but a full lifecycle is still 3-11% faster and uses 31-56% less CPU. - No change for hosts between 2 and 128 CPUs.
//test/benchmarkson 192 CPUs withGOMAXPROCSunset: Startup -2 to -4%, Checkpoint -11 to -13%, Restore -5%, no regressions. With Docker's defaultGOMAXPROCS: neutral.
Beat the autoresearch
The following benchmark results were benchmarked using this patch: master...EtiennePerot:gvisor:autoresearch/cli-gofer-early-gomaxprocs
Add value by beating these benchmark numbers, or reducing any regressions they cause, or both
goos: linux
goarch: amd64
pkg: gvisor.dev/gvisor/test/benchmarks (GOMAXPROCS unset in runsc env)
│ before │ after │
│ sec/op │ sec/op vs base │
StartupEmpty-192 260.1m ± 1% 249.8m ± 1% -3.98% (p=0.000 n=16)
StartupNginx-192 600.1m ± 1% 589.4m ± 1% -1.77% (p=0.004 n=16)
CheckpointEmpty-192 123.4m ± 3% 106.9m ± 3% -13.36% (p=0.000 n=16)
RestoreEmpty-192 289.9m ± 1% 274.3m ± 1% -5.36% (p=0.000 n=16)
CheckpointNginx-192 173.1m ± 4% 153.3m ± 4% -11.46% (p=0.000 n=16)
RestoreNginx-192 383.7m ± 1% 363.0m ± 3% -5.42% (p=0.000 n=16)
SizeEmpty-192 494.3m ± 2% 466.7m ± 1% -5.59% (p=0.000 n=16)
SizeNginx-192 985.1m ± 1% 957.0m ± 1% -2.86% (p=0.000 n=16)
FioRead/libaio/j1/4K/bindfs-192 140.5m ± 2% 140.5m ± 4% ~ (p=0.468 n=16)
FioRead/libaio/j1/4K/tmpfs-192 140.2m ± 2% 140.2m ± 1% ~ (p=0.897 n=16)
FioRead/libaio/j1/4K/rootfs-192 141.0m ± 2% 138.5m ± 2% ~ (p=0.184 n=16)
FioWrite/sync/j1/4K/bindfs-192 137.9m ± 2% 136.7m ± 4% ~ (p=0.056 n=16)
FioWrite/sync/j1/4K/tmpfs-192 138.4m ± 2% 136.3m ± 1% ~ (p=0.239 n=16)
FioWrite/sync/j1/4K/rootfs-192 140.2m ± 1% 136.5m ± 4% -2.58% (p=0.004 n=16)
Sysbench/testname.CPU-192 607.9m ± 29% 582.2m ± 37% ~ (p=0.239 n=16)
Sysbench/testname.CPU/threads.16-192 428.4m ± 2% 400.9m ± 2% -6.43% (p=0.000 n=16)
Sysbench/testname.Memory-192 1.401 ± 0% 1.379 ± 1% -1.56% (p=0.000 n=16)
Sysbench/testname.Memory/threads.16-192 1.536 ± 1% 1.532 ± 1% ~ (p=0.254 n=16)
Sysbench/testname.Mutex-192 426.1m ± 3% 395.8m ± 3% -7.11% (p=0.000 n=16)
Syscallbench/syscall.getpid-192 37.96m ± 11% 26.07m ± 11% -31.31% (p=0.000 n=16)
Syscallbench/syscall.getpidopt-192 40.03m ± 8% 23.64m ± 7% -40.95% (p=0.000 n=16)
StartupNode-192 767.7m ± 3% 754.7m ± 2% ~ (p=0.104 n=14)
geomean 272.3m 252.0m -7.48%
│ before │ after │
│ average_container_size.bytes │ average_container_size.bytes vs base │
SizeEmpty-192 43.33M ± 6% 32.16M ± 19% -25.78% (p=0.000 n=16)
SizeNginx-192 47.46M ± 14% 33.03M ± 33% -30.40% (p=0.001 n=16)
geomean 45.35M 32.60M -28.13%
│ before │ after │
│ bandwidth.bytes_per_second │ bandwidth.bytes_per_second vs base │
FioRead/libaio/j1/4K/bindfs-192 276.7M ± 18% 276.7M ± 46% ~ (p=0.202 n=16)
FioRead/libaio/j1/4K/tmpfs-192 299.8M ± 13% 276.7M ± 18% ~ (p=0.594 n=16)
FioRead/libaio/j1/4K/rootfs-192 228.0M ± 5% 249.7M ± 11% +9.52% (p=0.025 n=16)
FioWrite/sync/j1/4K/bindfs-192 749.0M ± 22% 655.4M ± 33% ~ (p=0.647 n=16)
FioWrite/sync/j1/4K/tmpfs-192 873.8M ± 14% 749.0M ± 22% ~ (p=0.118 n=16)
FioWrite/sync/j1/4K/rootfs-192 655.4M ± 27% 582.5M ± 29% ~ (p=0.751 n=16)
geomean 448.2M 419.7M -6.37%
│ before │ after │
│ io_ops.ops_per_second │ io_ops.ops_per_second vs base │
FioRead/libaio/j1/4K/bindfs-192 67.56k ± 18% 67.56k ± 46% ~ (p=0.202 n=16)
FioRead/libaio/j1/4K/tmpfs-192 73.20k ± 13% 67.56k ± 18% ~ (p=0.594 n=16)
FioRead/libaio/j1/4K/rootfs-192 55.65k ± 5% 60.95k ± 11% +9.52% (p=0.025 n=16)
FioWrite/sync/j1/4K/bindfs-192 182.9k ± 22% 160.0k ± 33% ~ (p=0.647 n=16)
FioWrite/sync/j1/4K/tmpfs-192 213.3k ± 14% 182.9k ± 22% ~ (p=0.118 n=16)
FioWrite/sync/j1/4K/rootfs-192 160.0k ± 27% 142.2k ± 29% ~ (p=0.751 n=16)
geomean 109.4k 102.5k -6.37%
│ before │ after │
│ cpu_events.events_per_second │ cpu_events.events_per_second vs base │
Sysbench/testname.CPU-192 515.2 ± 8% 488.4 ± 7% ~ (p=0.381 n=16)
Sysbench/testname.CPU/threads.16-192 349.2 ± 13% 319.8 ± 11% ~ (p=0.210 n=16)
geomean 424.2 395.2 -6.83%
│ before │ after │
│ memory_operations.ops_per_second │ memory_operations.ops_per_second vs base │
Sysbench/testname.Memory-192 1.079M ± 1% 1.071M ± 1% -0.77% (p=0.047 n=16)
Sysbench/testname.Memory/threads.16-192 950.8k ± 1% 939.8k ± 1% -1.16% (p=0.019 n=16)
geomean 1.013M 1.003M -0.96%
│ before │ after │
│ average_execution_time.s │ average_execution_time.s vs base │
Sysbench/testname.Mutex-192 100.0µ ± ? 100.0µ ± ? ~ (p=0.750 n=16)
│ before │ after │
│ average_latency.s │ average_latency.s vs base │
Sysbench/testname.Mutex-192 60.00µ ± 267% 65.00µ ± 223% ~ (p=0.993 n=16)
│ before │ after │
│ stddev_execution_time.s │ stddev_execution_time.s vs base │
Sysbench/testname.Mutex-192 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=16) ¹
¹ all samples are equal
pkg: gvisor.dev/gvisor/test/benchmarks (docker shim sets GOMAXPROCS=4)
│ before │ after │
│ sec/op │ sec/op vs base │
StartupEmpty-192 232.1m ± 1% 235.3m ± 1% ~ (p=0.073 n=16)
StartupNginx-192 576.8m ± 1% 578.9m ± 1% ~ (p=0.468 n=16)
CheckpointEmpty-192 94.30m ± 3% 93.72m ± 3% ~ (p=0.224 n=16)
RestoreEmpty-192 264.3m ± 2% 264.7m ± 1% ~ (p=0.897 n=16)
CheckpointNginx-192 138.4m ± 3% 139.5m ± 4% ~ (p=0.445 n=16)
RestoreNginx-192 341.1m ± 1% 342.8m ± 2% ~ (p=0.780 n=16)
SizeEmpty-192 438.9m ± 1% 443.7m ± 1% ~ (p=0.160 n=16)
SizeNginx-192 927.0m ± 1% 931.2m ± 2% ~ (p=0.642 n=16)
FioRead/libaio/j1/4K/bindfs-192 134.6m ± 4% 136.0m ± 1% +1.07% (p=0.008 n=16)
FioRead/libaio/j1/4K/tmpfs-192 133.9m ± 4% 136.4m ± 3% ~ (p=0.102 n=16)
FioRead/libaio/j1/4K/rootfs-192 135.2m ± 2% 135.1m ± 2% ~ (p=0.956 n=16)
FioWrite/sync/j1/4K/bindfs-192 132.0m ± 3% 132.9m ± 2% ~ (p=0.239 n=16)
FioWrite/sync/j1/4K/tmpfs-192 131.6m ± 3% 133.6m ± 3% ~ (p=0.780 n=16)
FioWrite/sync/j1/4K/rootfs-192 133.7m ± 2% 133.7m ± 2% ~ (p=1.000 n=16)
Sysbench/testname.CPU-192 565.1m ± 32% 578.8m ± 32% ~ (p=0.468 n=16)
Sysbench/testname.CPU/threads.16-192 381.6m ± 2% 381.1m ± 2% ~ (p=0.669 n=16)
Sysbench/testname.Memory-192 1.368 ± 0% 1.369 ± 1% ~ (p=0.724 n=16)
Sysbench/testname.Memory/threads.16-192 1.506 ± 1% 1.503 ± 1% ~ (p=0.539 n=16)
Sysbench/testname.Mutex-192 378.6m ± 3% 387.7m ± 2% ~ (p=0.073 n=16)
Syscallbench/syscall.getpid-192 16.40m ± 7% 17.36m ± 7% ~ (p=0.138 n=16)
Syscallbench/syscall.getpidopt-192 16.32m ± 18% 16.30m ± 5% ~ (p=0.897 n=16)
StartupNode-192 739.4m ± 1% 745.5m ± 2% ~ (p=0.512 n=15)
geomean 233.0m 235.1m +0.91%
│ before │ after │
│ average_container_size.bytes │ average_container_size.bytes vs base │
SizeEmpty-192 41.06M ± 7% 36.13M ± 10% -12.00% (p=0.000 n=16)
SizeNginx-192 51.28M ± 16% 47.94M ± 5% ~ (p=0.270 n=16)
geomean 45.89M 41.62M -9.29%
│ before │ after │
│ bandwidth.bytes_per_second │ bandwidth.bytes_per_second vs base │
FioRead/libaio/j1/4K/bindfs-192 349.5M ± 21% 275.9M ± 19% ~ (p=0.129 n=16)
FioRead/libaio/j1/4K/tmpfs-192 269.0M ± 15% 283.6M ± 9% ~ (p=0.581 n=16)
FioRead/libaio/j1/4K/rootfs-192 249.7M ± 17% 238.3M ± 5% ~ (p=0.530 n=16)
FioWrite/sync/j1/4K/bindfs-192 553.4M ± 35% 655.4M ± 14% ~ (p=0.177 n=16)
FioWrite/sync/j1/4K/tmpfs-192 811.4M ± 19% 873.8M ± 14% ~ (p=0.666 n=16)
FioWrite/sync/j1/4K/rootfs-192 582.5M ± 18% 524.3M ± 17% ~ (p=0.458 n=16)
geomean 427.9M 421.4M -1.53%
│ before │ after │
│ io_ops.ops_per_second │ io_ops.ops_per_second vs base │
FioRead/libaio/j1/4K/bindfs-192 85.33k ± 21% 67.37k ± 19% ~ (p=0.129 n=16)
FioRead/libaio/j1/4K/tmpfs-192 65.68k ± 15% 69.24k ± 9% ~ (p=0.581 n=16)
FioRead/libaio/j1/4K/rootfs-192 60.95k ± 17% 58.18k ± 5% ~ (p=0.530 n=16)
FioWrite/sync/j1/4K/bindfs-192 135.1k ± 35% 160.0k ± 14% ~ (p=0.177 n=16)
FioWrite/sync/j1/4K/tmpfs-192 198.1k ± 19% 213.3k ± 14% ~ (p=0.666 n=16)
FioWrite/sync/j1/4K/rootfs-192 142.2k ± 18% 128.0k ± 17% ~ (p=0.458 n=16)
geomean 104.5k 102.9k -1.53%
│ before │ after │
│ cpu_events.events_per_second │ cpu_events.events_per_second vs base │
Sysbench/testname.CPU-192 510.2 ± 12% 504.3 ± 3% ~ (p=0.838 n=16)
Sysbench/testname.CPU/threads.16-192 321.4 ± 24% 284.8 ± 29% ~ (p=0.323 n=16)
geomean 404.9 378.9 -6.41%
│ before │ after │
│ memory_operations.ops_per_second │ memory_operations.ops_per_second vs base │
Sysbench/testname.Memory-192 1.059M ± 1% 1.063M ± 0% ~ (p=0.094 n=16)
Sysbench/testname.Memory/threads.16-192 932.0k ± 1% 943.2k ± 2% ~ (p=0.119 n=16)
geomean 993.2k 1.002M +0.84%
│ before │ after │
│ average_execution_time.s │ average_execution_time.s vs base │
Sysbench/testname.Mutex-192 100.0µ ± ? 100.0µ ± ? ~ (p=0.545 n=16)
│ before │ after │
│ average_latency.s │ average_latency.s vs base │
Sysbench/testname.Mutex-192 115.0µ ± 74% 130.0µ ± 69% ~ (p=0.703 n=16)
│ before │ after │
│ stddev_execution_time.s │ stddev_execution_time.s vs base │
Sysbench/testname.Mutex-192 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=16) ¹
¹ all samples are equal
pkg: runsc CLI microbenchmark (runsc state of a missing container)
│ before │ after │
│ sec/op │ sec/op vs base │
RunscState/cpus=2 1.468m ± 0% 1.456m ± 0% -0.82% (p=0.000 n=900)
RunscState/cpus=4 1.801m ± 1% 1.786m ± 0% -0.83% (p=0.000 n=900)
RunscState/cpus=16 1.947m ± 0% 1.899m ± 0% -2.44% (n=900)
RunscState/cpus=48 2.080m ± 0% 2.055m ± 0% -1.20% (p=0.000 n=900)
RunscState/cpus=96 2.559m ± 1% 2.513m ± 1% -1.80% (p=0.000 n=900)
RunscState/cpus=192 11.386m ± 1% 5.895m ± 1% -48.22% (n=900)
RunscState/cpus=192/quota=150 3.263m ± 2% 3.683m ± 1% +12.89% (p=0.000 n=400)
geomean 2.690m 2.466m -8.33%
│ before │ after │
│ cpu-sec/op │ cpu-sec/op vs base │
RunscState/cpus=2 1.364m ± 0% 1.358m ± 0% -0.44% (p=0.001 n=900)
RunscState/cpus=4 1.833m ± 0% 1.821m ± 0% -0.68% (p=0.008 n=900)
RunscState/cpus=16 1.997m ± 1% 1.945m ± 1% -2.63% (p=0.000 n=900)
RunscState/cpus=48 2.126m ± 0% 2.107m ± 1% -0.89% (p=0.001 n=900)
RunscState/cpus=96 2.610m ± 1% 2.567m ± 0% -1.65% (p=0.000 n=900)
RunscState/cpus=192 22.760m ± 1% 7.399m ± 1% -67.49% (n=900)
RunscState/cpus=192/quota=150 3.259m ± 2% 3.608m ± 2% +10.71% (p=0.000 n=400)
geomean 2.973m 2.546m -14.36%
pkg: runsc container lifecycle harness (9 runsc commands per cycle)
│ before │ after │
│ sec/op │ sec/op vs base │
Lifecycle/cpus=16 86.10m ± 1% 85.83m ± 1% ~ (p=0.402 n=40)
Lifecycle/cpus=48 94.43m ± 1% 94.04m ± 1% ~ (p=0.365 n=40)
Lifecycle/cpus=96 129.2m ± 1% 130.1m ± 1% ~ (p=0.512 n=40)
Lifecycle/cpus=192 278.6m ± 2% 223.3m ± 2% -19.85% (p=0.000 n=40)
Lifecycle/cpus=192/taskset=128 156.5m ± 1% 155.6m ± 2% ~ (p=0.676 n=40)
Lifecycle/cpus=192/taskset=144 172.4m ± 1% 167.5m ± 1% -2.85% (p=0.000 n=40)
Lifecycle/cpus=192/taskset=160 198.9m ± 1% 177.4m ± 2% -10.78% (p=0.000 n=40)
LifecycleStep/cpus=192/checkpoint 49.67m ± 8% 42.58m ± 5% -14.28% (p=0.000 n=40)
LifecycleStep/cpus=192/create 52.41m ± 5% 47.32m ± 3% -9.72% (p=0.000 n=40)
LifecycleStep/cpus=192/kill 12.304m ± 3% 6.812m ± 4% -44.64% (p=0.000 n=40)
LifecycleStep/cpus=192/restore 84.09m ± 2% 77.66m ± 2% -7.64% (p=0.000 n=40)
LifecycleStep/cpus=192/start 26.25m ± 3% 20.30m ± 3% -22.65% (p=0.000 n=40)
LifecycleStep/cpus=192/state 12.814m ± 5% 6.761m ± 3% -47.23% (p=0.000 n=40)
geomean 72.10m 60.90m -15.53%
│ before │ after │
│ cpu-sec/op │ cpu-sec/op vs base │
Lifecycle/cpus=16 31.18m ± 1% 31.14m ± 1% ~ (p=0.778 n=40)
Lifecycle/cpus=48 32.77m ± 1% 32.71m ± 1% ~ (p=0.424 n=40)
Lifecycle/cpus=96 39.67m ± 1% 39.17m ± 0% -1.25% (p=0.009 n=40)
Lifecycle/cpus=192 257.47m ± 3% 85.39m ± 1% -66.84% (p=0.000 n=40)
Lifecycle/cpus=192/taskset=128 51.81m ± 5% 51.05m ± 1% ~ (p=0.206 n=40)
Lifecycle/cpus=192/taskset=144 73.56m ± 5% 50.59m ± 3% -31.22% (p=0.000 n=40)
Lifecycle/cpus=192/taskset=160 130.45m ± 2% 57.77m ± 2% -55.71% (p=0.000 n=40)
geomean 65.53m 47.02m -28.24%
Benchmark environment
GCE c4-standard-2/4/16/48/96/192 (cpus=; the 192-CPU VM is a 2-socket Xeon 8581C), COS cos-129-19506-448-8 (kernel 6.12.105+), hyperdisk-balanced, cgroup v2. before is master at 2511bc60218a, after is the patch above; arms are interleaved and the page cache is dropped before each run. The //test/benchmarks blocks run the real startup, size, fio (4K, 1 job), sysbench and syscallbench targets on the 192-CPU VM through Docker, one binary invocation per sample. In the first block, a wrapper runtime unsets GOMAXPROCS so the bound applies to runsc commands. In the second, Docker passes GOMAXPROCS=4, so only the gofer is affected. The sysbench and syscallbench time gains come from container startup being inside the timed iteration, and the fio bandwidth/io_ops columns are quantized by fio's 1 ms runtime resolution. The CLI microbenchmark times runsc state on a missing container (quota=150 runs it in a cgroup with a 150-CPU quota, which gives GOMAXPROCS 150). The lifecycle harness times 9 runsc commands per cycle (create, start, state, checkpoint, delete, restore, state, kill, delete) on a sleeping container, with taskset= limiting the CPUs on the 192-CPU VM. The gofer PSS and thread figures come from averages over 5 sandboxes and are not in the table.
Activity