This episode covers performance optimization: managing memory and CPU usage, serversTransport configuration for keep-alive and timeouts, TLS performance with session resumption and HTTP/2, middleware optimization strategy, and benchmarking with wrk, ab, and k6 to find bottlenecks.

A running Traefik is not necessarily an optimal Traefik. Episode 27 covers performance tuning: how Traefik uses resources, the parameters that most affect latency and throughput, and how to measure whether a change actually helps — not just feel that it does.
The main principle: do not optimize without measuring. We start with the transport connection, move into TLS, then discuss middlewares, and close with honest benchmarking. After this episode, you can get the most out of Traefik for your own workloads.
Traefik is lightweight, but memory usage is affected by a few things:
memRequestBodyBytes if memory is limited.bufferingSize adds to the memory footprint.Allocate CPU to Traefik proportionally: dual-core is comfortable for hundreds of requests per second with basic middlewares. Scale up when using many heavy middlewares or TLS with high traffic.
Traefik's connections to backends are governed by ServersTransport. The following parameters have the most impact:
http:
serversTransports:
prod:
maxIdleConnsPerHost: 100
idleConnTimeout: "90s"
responseHeaderTimeout: "30s"
dialTimeout: "5s"
insecureSkipVerify: falsemaxIdleConnsPerHost: the number of idle connections kept per backend. A high value reduces the cost of opening new connections — the biggest effect for burst traffic.idleConnTimeout: when an idle connection is considered stale and closed.responseHeaderTimeout: the wait time for response headers; a slow backend uses up this quota then the connection is closed.dialTimeout: the time limit for opening a new connection to the backend.A ServersTransport is attached to a service by name:
http:
services:
api-svc:
loadBalancer:
servers:
- url: "http://10.0.0.130:8080"
serversTransport: prodThe TLS handshake is the most expensive operation in a proxy — every handshake consumes cryptographic CPU. Tricks to speed it up:
acme.json is rarely accessed from disk.For very high TLS traffic, consider terminating TLS at the front load balancer and having Traefik receive internal traffic — a control vs. performance trade-off you must assess yourself.
Middlewares can become a burden, so install them deliberately:
minResponseBodyBytes) or already compressed files.Before and after every change, measure with consistent tools:
wrk -t4 -c200 -d30s http://localhost/apiab -n 10000 -c 100 http://localhost/apik6 run --vus 100 --duration 30s script.jsThree tools with different characteristics: wrk is very fast and lightweight, ab is classic and available everywhere, k6 is script-based and suits complex scenarios. The wrk command with 200 parallel connections over 30 seconds gives a throughput and latency baseline.
Watch three numbers: requests/sec (throughput), latency percentiles (p95, p99), and error rate. Compare the baseline with the post-tuning results — if p95 drops and throughput rises, your change worked. If nothing changes, you may be hitting a bottleneck elsewhere: the backend, the network, or CPU.
Warning
Benchmarks are raw numbers, not absolute truth. Always include background load, duration, and connection count with results. Numbers without context will only mislead decisions.
Key takeaways:
maxIdleConnsPerHost is the transport parameter with the most impact.In episode 28 next we will cover security hardening — least privilege principles, securing the dashboard, API, and metrics endpoints, strong TLS configuration, container security with non-root and read-only filesystems, and secret management with Docker secrets and Kubernetes secrets.