Measuring slirp4netns Overhead Before Switching to pasta in Rootless Podman
0 reputation · 08 Sept 2021, 07:29 UTC
0 reputation · 08 Sept 2021, 07:29 UTC
Podman defaults to the slirp4netns user-mode network stack for rootless containers, which introduces context-switch overhead compared to kernel-level bridging. The pasta backend was added as a more efficient alternative, yet the performance gap varies with kernel version, CPU architecture, and distribution-specific netns or cgroup v2 implementations.
Before changing the default backend or tuning sysctl parameters, a reliable baseline is needed to quantify the actual throughput and latency penalty for a given workload. Existing benchmarks often test synthetic traffic rather than application-specific patterns such as short-lived connections or large file transfers.
Which metrics most reliably expose the slirp4netns bottleneck for a specific workload? Does the overhead manifest primarily in bandwidth, connection establishment latency, or CPU utilization? When does the pasta backend provide a measurable improvement without introducing compatibility regressions?
35275 reputation · 08 Sept 2021, 13:49 UTC
Which metrics expose the slirp4netns bottleneck? Three key numbers:
Where does the overhead show up? For short‑lived connections the latency spikes (2–3× higher than kernel bridging). For bulk transfers the bandwidth drop is more visible (30–40% lower on kernels 5.15+). CPU usage climbs because each packet is copied from user space into the kernel, adding a context switch.
When does pasta help? On kernels ≥5.10 that support the BPF‑based passthrough, pasta delivers near‑kernel latency and higher throughput with minimal compatibility regressions for standard TCP/UDP workloads. On older kernels pasta will silently fall back to slirp4netns, so the benefit disappears.
uname -r
podman --version
Verify kernel ≥5.10 and Podman ≥4.0.
# Simple HTTP server in a container
podman run -d --name slirp-test -p 8080:8080 alpine/httpd
# Throughput test – iperf3 server inside the container
podman exec slirp-test iperf3 -s -p 5201 &
iperf3 -c localhost -p 5201 -t 30
# Connection latency – curl timing
curl -w "%{time_connect}\n" -o /dev/null -s http://localhost:8080/
# CPU usage during load
pid=$(podman inspect --format '{{.State.Pid}}' slirp-test)
pidstat -p $pid 1 10
podman run -d --name pasta-test --net=pasta -p 8081:8080 alpine/httpd
# iperf3 server inside
podman exec pasta-test iperf3 -s -p 5202 &
iperf3 -c localhost -p 5202 -t 30
# curl latency
curl -w "%{time_connect}\n" -o /dev/null -s http://localhost:8081/
# CPU usage
pid=$(podman inspect --format '{{.State.Pid}}' pasta-test)
pidstat -p $pid 1 10
pid=$(podman inspect --format '{{.State.Pid}}' slirp-test)
perf record -e sched:sched_switch -p $pid -- sleep 30
perf report
Look for frequent switches between the container process and the slirp4netns helper.
ip netns list
cat /proc/$(podman inspect --format '{{.State.Pid}}' slirp-test)/net/route
| Metric | slirp4netns | pasta | Action |
|---|---|---|---|
| Connection latency | ≈2–3× kernel | ≈kernel | Consider pasta if latency >1.5× |
| Throughput (iperf3) | baseline | +30–40% | Use pasta if gain >20% |
| CPU % per packet | high | lower | Switch if CPU saturates |
What is your kernel version and distribution? This determines pasta support and cgroup v2 nuances, which can change the recommendation entirely.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 08 Sept 2021, 14:38 UTC
slirp4netns incurs most of its cost in per‑packet context switches and user‑space cloning. For workloads with many short‑lived TCP connections, the connection‑establishment latency dominates. For bulk transfers, bandwidth and CPU utilization become the key indicators.
iperf3 -c server -w 64K -t 10 to capture per‑packet latency (small window).iperf3 -c server -w 1M -t 10 for throughput (large window).perf stat -e cycles,instructions,cache-misses -a before and after enabling pasta.Verify kernel and cgroup support first: systemctl show --property=KernelVersion and check /proc/cgroups for cgroup v2. Compatibility testing is essential because pasta changes port‑mapping semantics.