You write go handle(), call log.Printf, or launch a tiny service on a beefy server. It feels routine. Under the hood, the Linux kernel hooks syscalls, the Go scheduler juggles goroutines, and the runtime carves out caches per core. Here are four internals that matter in production.
Getting started with eBPF in Go: loading and attaching via cilium/ebpf
eBPF runs user bytecode safely inside the Linux kernel without building kernel modules, verified before startup. In Go, teams use cilium/ebpf (v0.22.0) and bpf2go: //go:generate go tool bpf2go compiles C with clang and embeds bytecode right into a Go package, so you deploy a single binary.
In a basic probe, the C program attaches to syscalls/sys_enter_write, gets the PID via bpf_get_current_pid_tgid() >> 32, and filters by my_pid. Go loads the object into the kernel:
// Raise memlock limit (for Linux kernels older than 5.11)
if err := rlimit.RemoveMemlock(); err != nil {
log.Fatal(err)
}
spec, err := probe.LoadBpf()
if err != nil {
log.Fatal(err)
}
// Pass our PID into the C program's global variable
_ = spec.Variables["my_pid"].Set(int32(os.Getpid()))
var objs probe.BpfObjects
if err := spec.LoadAndAssign(&objs, nil); err != nil {
log.Fatal(err)
}
defer objs.Close()
tp, err := link.Tracepoint(
"syscalls", "sys_enter_write", objs.HandleTp, nil,
)
if err != nil {
log.Fatal(err)
}
defer tp.Close()
Even without a test loop, two lines appear in /sys/kernel/debug/tracing/trace_pipe right away because log.Printf itself calls write(). You need Linux, CAP_BPF and CAP_PERFMON (or sudo), and a Dual BSD/GPL license in C. In production, use eBPF maps and ring buffers instead of bpf_printk.
Property-based testing in practice: how Teleport uses rapid
Unit tests check a handful of examples you picked. Property-based testing (PBT) checks general rules across hundreds of random inputs. The Teleport team pulls properties straight from RFD design docs: for genericLister pagination, they defined seven rules (pageSize cap, default when pageSize <= 0, uniqueness, completeness, termination, empty final token, and page-size independence).
In Go, they run properties with rapid (pgregory.net/rapid v1.3.0), which shrinks failures down to a minimal case:
rapid.Check(t, func(t *rapid.T) {
n := rapid.IntRange(0, 300).Draw(t, "n")
isDesc := rapid.Bool().Draw(t, "isDesc")
// Small pages hit pagination boundaries more often
pageSize := rapid.IntRange(1, 5).Draw(t, "pageSize")
fix := newTestListerFixture(n, isDesc, pageSize)
seen := make(map[int]int, n)
for item, err := range fix.lister.Range(t.Context(), "", "") {
require.NoError(t, err)
seen[item]++
require.Equal(t, 1, seen[item], "duplicate item %d", item)
}
require.Len(t, seen, n)
})
One rule isn't enough (reversing a list twice passes on a stub), so combine multiple rules. Since rapid lacks coverage feedback and local tests miss network faults, Teleport tests cluster-wide safety and liveness properties in the deterministic Antithesis simulator.
GOMAXPROCS for small Go services on multi-core servers
The number of logical processors P in GOMAXPROCS directly drives runtime overhead: each P holds its own mcache allocator cache, sync.Pool shard, and GC background workers (a quarter of P). On a 64-core Xeon (Linux 6.12, Go 1.27.1) with 1 MB of live data, GC ran 308 times at GOMAXPROCS=64 versus 165 times at GOMAXPROCS=2.
At scale, the waste compounds: 100 copies of a background ticker service at GOMAXPROCS=64 used 684 MiB RAM and 2,240 OS threads, versus 503 MiB and 476 threads at GOMAXPROCS=2 (for comparison, 100 Rust copies on single-threaded Tokio used 16 MiB and 100 threads). CPU usage tells the same story:
CPU usage of 100 background service copies on 64 cores
Since Go 1.25, runtime includes container-aware GOMAXPROCS, but it only reads hard cpu.max limits (not cpu.weight) and needs go 1.25 in go.mod. For a small sidecar without a hard quota, capping GOMAXPROCS at two is safer:
func main() {
// Respect the env var and any stricter cgroup limit
if os.Getenv("GOMAXPROCS") == "" {
runtime.GOMAXPROCS(min(2, runtime.GOMAXPROCS(0)))
}
// ...
}
This cap leaves room for background GC and timers (setting 1 slows them down), respects manual env settings, and cuts idle resource use nearly in half on dense nodes.
How one million goroutines fit on five OS threads
On a 4-core Linux VM (Go 1.27.3), one million goroutines waiting on <-done start in 545–881 ms using just 5 OS threads. The price is stack RAM: 2 KB per starting goroutine adds up to 1,953 MB (m.StackSys), with CPU spent in runtime.stackpoolalloc.
This works thanks to the G-M-P model: goroutine G, OS thread M (~8 MB stack), and processor P with a 256-slot local queue. A parked goroutine waits without holding an OS thread. When a local queue fills, half spills to the global queue; an idle P steals half a neighbor's queue (work stealing); and since Go 1.14, sysmon sends SIGURG after 10 ms to preempt even empty for {} loops.
Network I/O via epoll and time.Sleep don't block OS threads: 1,000 sleeping goroutines use 6 threads, while 1,000 syscall.Nanosleep calls spawn 1,005. Blocking syscalls, file I/O, and cgo trigger handoffp to spin up new threads. You can inspect queues and preemption with GODEBUG=schedtrace=500 and GODEBUG=asyncpreemptoff=1 from runtime.


