Skip to main content

Writing

Envoy performance, measured

A PGO and ThinLTO rebuild of unmodified Envoy cut CPU per request 20% to 40% against a standard optimized build of the same commit, on HTTP/1 and HTTP/2 proxy benchmarks; expect less where TLS or the kernel dominate. On v1.40.2, an lld ordering file cut cycles per request 7% to 10%, with no training step. Two patches on our fork saved less than the rebuild and under narrower conditions: path-first route matching 11% on direct responses (1,000 routes, match last), and batched statsd about 8% (opt-in, plain statsd sink, 1,000 clusters). Most figures come from one 2016 server over loopback.

12 studies · one method · data and code public: harness and data, code on our Envoy fork

The reference · part 1

Envoy CPU cost of filters, settings and releases: a price list

External authorization: about +55% CPU per request with an HTTP service, +81% with gRPC (lower bounds).

For anyone choosing filters, tracing, stats sinks, TLS settings or a release: every row priced, with its conditions.

Part 2

Envoy with PGO and ThinLTO: 20% to 40% less CPU per request

In a VM on an AMD Zen 2 workstation, across 12 workload shapes at 2,000 requests per second: 27% to 40% less CPU per request than a same-commit standard build.

For teams that build their own Envoy binary: the numbers, the costs and the recipe.

Part 3

Envoy code layout: PGO vs AutoFDO, BOLT and lld ordering

On v1.40.2, an lld ordering file, a relink with no training step, cut cycles per request 7% to 10%.

For teams weighing PGO against AutoFDO, BOLT or an ordering file, on x86-64 and Arm.

Part 4

What a 1,000-route table costs Envoy per request

About 335 instructions per route passed over; checking the path first cut cycles by 11% on direct responses, 1,000 routes, match last.

For operators of large route tables, plus constant response headers by reference.

Part 5

Envoy TLS handshakes and HTTP/3: what connections cost in CPU

A new TLS 1.3 connection: 1,145k cycles with ECDSA P-256, 3,054k with RSA-2048.

For deployments with connection churn, or weighing HTTP/3 or TLS to the upstream.

Part 6

Envoy tcp_proxy vs HTTP proxy: what a second hop costs in CPU

A second proxy that relays TCP instead of HTTP: 33% less CPU per request for the pair, and that hop gives up everything Envoy does per request.

For topologies with a second Envoy in the request path.

Part 7

Find the CPU in your Envoy config: a priced checklist

Ten HTTP filters that take no action: +9.5% CPU per request; a tracer at 0% sampling: +6.7%.

For anyone with high Envoy CPU who wants to know which settings to check first.

Part 8

Envoy worker imbalance: uneven load, exact_balance and connection recycling

Four heavy connections out of 16: under Envoy's default the busiest worker did 44% of worker CPU time; recycling every 1,000 requests cut that by 13.78 points in one session, even not established (loopback, this CPU).

For anyone whose Envoy shows one busy worker while the pod looks idle.

Part 9

Envoy CPU per request under load: does a price hold at every request rate?

20 constant response headers: +3.23% CPU per request at 2,560 req/s, +4.41% at 7,808 (one session, loopback). For a deferred-span patch, the change between the two rates was not a finding.

For anyone who reads a price measured at one request rate and runs Envoy at another.

Part 10

What Envoy's stats cost in CPU: flushes, sinks and counters

A plain statsd sink: +19.69% CPU per request at 5,200 req/s with 118,396 stats (one session, loopback); most of it on the workers, one datagram per histogram sample.

For anyone who runs a stats sink or many clusters: what the flush and the per-request stat updates cost, and on which thread.

Part 11

Arm64 atomics in Envoy main and stats cost: no resolved difference

Exclusive loads (ldaxr) in the arm64 binary: 84 in v1.40.2, 29,324 at main 5e1439980a (17 November). The cost of the store's stats differed by −0.09% [−0.85, +0.67] of worker cycles (12 workers, one Arm cloud VM).

For anyone who builds or runs Envoy on arm64 and wants to know what changed in its atomics, and what it costs.

Part 12

Envoy --concurrency under a CPU limit: what 4 and 8 workers cost against Envoy's own 2

Under a 2-CPU limit and steady load, 8 workers used about 9% more CPU time per request than Envoy's own choice of 2 at 2,080 req/s and about 25% more at 5,824 to 7,072 req/s (one session, loopback).

For anyone who runs Envoy under a container CPU limit and sets, or inherits, a --concurrency value.

Diagram of one request's path through Envoy with each part of the Envoy performance series placed at the stage it measures, and the parts that apply to the whole binary in a band below.A request's path through Envoy from left to right: listener and accept, TLS handshake, route match, filter chain, and the upstream connection and relay. Everything from the TLS handshake to the upstream runs on the worker thread that accepted the connection, drawn as a shaded area around those stages. A dashed line labelled stats flush leads from the worker to the main thread's stats flush and sink. Each part of the series sits at the stage it measures, as a numbered marker that links to the post: part 8, worker imbalance, at accept, where the listener picks the worker; part 12, worker count under a CPU limit, beside it; part 5, connections and TLS, at the TLS handshake; part 4, route tables, at route match; part 7, the config checklist, at the filter chain; part 6, the second hop, at the upstream and relay; part 10, stats, twice, on the worker for per-request stat updates and at the main thread's flush. A band under the path, labelled whole binary, holds the parts that apply to every stage: part 1, the price list; part 2, PGO and ThinLTO; part 3, code layout; part 9, cost by load; part 11, arm64 atomics.ONE REQUEST, LEFT TO RIGHTOn the worker thread that accepted the connectionPart 10: stats10StatsListenerand acceptTLShandshakeRoutematchFilterchainUpstreamand relayPart 8: worker imbalance8WorkerimbalancePart 12: worker count under a CPU limit12WorkercountPart 5: connections and TLS5Connectionsand TLSPart 4: route tables4RoutetablesPart 7: the config checklist7ConfigchecklistPart 6: the second hop6Secondhopstats flushMain threadstats flush and sinkPart 10: stats10StatsWhole binary: every stage abovePart 1: the price list1Price listPart 2: PGO and ThinLTO2PGO and ThinLTOPart 3: code layout3Code layoutPart 9: cost by load9Cost by loadPart 11: arm64 atomics11Arm64 atomicsDiagram of one request's path through Envoy with each part of the Envoy performance series placed at the stage it measures, and the parts that apply to the whole binary in a band below.A request's path through Envoy from top to bottom: listener and accept, TLS handshake, route match, filter chain, and the upstream connection and relay. Everything from the TLS handshake to the upstream runs on the worker thread that accepted the connection, drawn as a shaded area around those stages. A dashed line labelled stats flush leads from the worker to the main thread's stats flush and sink. Each part of the series sits at the stage it measures, as a numbered marker that links to the post: part 8, worker imbalance, at accept, where the listener picks the worker; part 12, worker count under a CPU limit, beside it; part 5, connections and TLS, at the TLS handshake; part 4, route tables, at route match; part 7, the config checklist, at the filter chain; part 6, the second hop, at the upstream and relay; part 10, stats, twice, on the worker for per-request stat updates and at the main thread's flush. A band under the path, labelled whole binary, holds the parts that apply to every stage: part 1, the price list; part 2, PGO and ThinLTO; part 3, code layout; part 9, cost by load; part 11, arm64 atomics.ONE REQUEST, TOP TO BOTTOMListener and acceptPart 8: worker imbalance8Worker imbalancePart 12: worker count under a CPU limit12Worker countTLS handshakePart 5: connections and TLS5Connections and TLSRoute matchPart 4: route tables4Route tablesFilter chainPart 7: the config checklist7Config checklistUpstream and relayPart 6: the second hop6Second hopOn the worker thread thataccepted the connectionPart 10: stats10Statsstats flushMain thread:stats flush and sinkPart 10: stats10StatsWhole binary: every stage abovePart 1: the price list1Price listPart 2: PGO and ThinLTO2PGO and ThinLTOPart 3: code layout3Code layoutPart 9: cost by load9Cost by loadPart 11: arm64 atomics11Arm64 atomics
Where each part of the series measures, along one request’s path through Envoy. Numbers are the part numbers; each marker links to its post. From the TLS handshake to the upstream, the work runs on the worker thread that accepted the connection; part 8 covers how the listener picks that worker. Part 12, beside it, covers how many workers to run under a CPU limit. Part 10 appears twice: per-request stat updates on the worker, and the flush on the main thread. Parts 1, 2, 3, 9 and 11 cover the whole binary (settings and releases, builds, load levels, and the stats atomics of arm64 builds), so they sit in the band. The connections post also prices upstream protocols, and the checklist also prices route options; each is drawn at its main stage.

What did not hold up?

Several results we believed for a while were wrong; all were caught before publication, and each left a rule in the method below.

  • Connection reuse in the load generator: Nighthawk’s default (mru) left 2 to 4 of Envoy’s 4 workers carrying the load, so we now spread it and fail any run one worker dominates (how we found it; the PGO post says where its earlier runs are affected).
  • Our own regression: an earlier path-first revision also reordered regex routes and ran 2.1 to 4.1 times slower on the case it hurts (route-table post).
  • Misrouting in the route index prototype, on regex alternation and quantified literals, fixed with differential tests against the linear scan (route-table post).

All withdrawn results in full, and the ideas we dropped

How do we measure Envoy’s CPU now?

  • Paired runs at a fixed request rate, in balanced order, 12 rounds or more unless a post says otherwise, with the load spread over every worker, an A/A run of the same binary to set the smallest difference worth reporting, and CPU cycles of the proxy process divided by the responses it served. Most figures come from one 2016 two-socket Xeon server over loopback; the long form of the method is in the price list.
  • A validity gate that fails closed. Missed rates, client-side queuing, busy cores or shared hardware counters void the run, and only optimized binaries with recorded hashes count.
  • A basis on every number. Measured: from paired or interleaved runs, with the interval or range given in the post. No verdict: measured, but the same-build repeat in that cell missed our own rule. Not resolved: the change was inside the noise of those runs, which is not the same as no effect. Exploratory: chosen after seeing the data, or outside the comparisons named before the run. Modelled: arithmetic on measured inputs. Bracketed ranges are 95% intervals.
  • How we screen ideas before they reach this method: an agent at the load generator, part of Proxy benchmarking.
  • What this does not cover. A network card in the path (client, proxy and origin share a machine in all but one comparison of the PGO post), a saturated proxy (only the PGO post has saturation sweeps), memory, and traffic or route tables taken from production; arm64 only in the code-layout post’s build comparisons, the stats post’s microbenchmarks and one Arm row, and the arm64 atomics post.

Where are the code and the data?

All patches, code and data: every code change in these posts, with its branch on our Envoy fork, its measured effect and its status, sits beside the harness and raw data in github.com/We-Amp/envoy-price-list (code under Apache 2.0, data under CC BY 4.0). The patches are on our fork, and any error in them is ours. The constant-headers change is priced in the route-table post.

The author is an emeritus maintainer of Nighthawk, the load generator used here. Envoy’s route matching, header code, matcher tree and benchmarks are the work of its contributors; PGO and ThinLTO are LLVM’s. Corrections go to the harness’s issue tracker.

By Otto van der Schaaf, We-Amp · · updated

← All writing