Skip to main content

Envoy performance · part 6 of 6

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

By Otto van der Schaaf, We-Amp ·

A second Envoy in front of the origin about doubles the proxy CPU per request. When that second proxy relays TCP instead of proxying HTTP, the pair costs 33% less with about as many syscalls on that hop (9.9 against 9.7), and the hop no longer balances, retries, logs or applies policy per request. This post prices the hop both ways for Envoy v1.40.2, lists what a relaying hop no longer does, counts the syscalls behind one relayed message, prices the two of them that carry no data with an experimental patch that removes them, and prices a Unix domain socket for a hop on the same host. It is a companion to the Envoy price list and uses its method. It is one machine and loopback networking, so read every figure as a price on that rig. The other posts of the series are listed on Envoy performance, measured.

CPU cycles per request, user plus kernel, 4 KB responses at 5,200 req/s (Measured; medians of one session):

Setup All proxies Second hop, user Second hop, kernel
One proxy 525.5k – –
Two proxies, second hop proxies HTTP 1,042.2k 351.8k 177.4k
Two proxies, second hop relays TCP (tcp_proxy) 698.6k 46.7k 140.8k

The kernel part of the second hop falls by a fifth; the user part nearly disappears.

CPU cycles per request, user plus kernel, 4 KB responses at 5,200 req/sStacked horizontal bars. One proxy: 525.5k cycles per request. Two proxies with an HTTP second hop: 1,042.2k, of which the second hop is 351.8k user and 177.4k kernel. Two proxies with a second hop that relays TCP: 698.6k, of which the second hop is 46.7k user and 140.8k kernel. The same figures are in the table above.First proxy (or the only one)Second hop, userSecond hop, kernel0k250k500k750k1,000kOne proxy: 525.5k cycles per requestOne proxy525.5kTwo proxies, second hop proxies HTTP: 1,042.2k cycles per request; second hop 351.8k user, 177.4k kernelTwo proxies, second hop proxies HTTP1,042.2kTwo proxies, second hop relays TCP (tcp_proxy): 698.6k cycles per request; second hop 46.7k user, 140.8k kernelTwo proxies, second hop relays TCP698.6k
CPU cycles per request of all proxies, user plus kernel, 4 KB responses at 5,200 req/s, Envoy v1.40.2 on one host (Measured; medians of one session). The coloured segments are the second hop. Hover or tap a bar for its figures.

Key findings

  • A second proxy that relays TCP costs the pair 33% less CPU. On one host, tcp_proxy instead of a minimal HTTP proxy on the second hop cut the pair’s CPU per request by 33% (−32.9% [−33.6, −32.3]; −30.8% [−31.5, −30.1] with mutual TLS on that hop; 4 KB responses, HTTP/1.1). That hop then no longer balances, retries, logs or applies policy per request. (Measured)
  • About as many syscalls, a third of the cycles. The relaying hop made 9.9 syscalls per request against 9.7 for the HTTP hop, and cost 187.4k cycles per request against 529.3k. About nine tenths of the difference (305k of 342k cycles) is user-space HTTP work. (Measured; the syscall counts are Measured [mechanism])
  • Envoy relays a small TCP message with five syscalls, two of which carry no data. 4.86 per message, with one readv returning EAGAIN and 0.96 zero-timeout epoll_wait calls, for about 74k cycles per message (counts Measured [mechanism], cycles Measured). From one kernel profile we estimated the two at about 9% of that (range 7 to 11; Exploratory). An experimental patch that removes the two calls then measured them: 12.5% [11.1, 13.8] of the CPU of a relayed 64-byte message inside one patched build (Measured) and 11.0% [9.7, 12.3] against the official binary (Exploratory), over loopback on this 2016 Xeon with page-table isolation, where a kernel call is dearer than on a current CPU. It is an experiment, not a proposed change: its larger half depends on a change to the bundled libevent and is not suitable for upstream in this form, and on an HTTP/2-multiplexed relay both changes together made 17% to 19% more send calls per message (single traced runs; the CPU effect was not measured). Small messages and 4 KB responses only, no bulk transfer: the section below has the rows.
  • A Unix domain socket saves kernel time on a same-host hop. −6.0% [−6.8, −5.2] of the pair’s CPU for the hop between two proxies, with both ends counted, and −4.5% [−5.7, −3.3] of the proxy’s CPU for the hop to the origin, with the proxy’s end only, on a host with connection tracking active on loopback. (Measured)

What to do: if a hop only needs to move bytes, measure it as tcp_proxy on your own traffic before you size it as an HTTP proxy, with the list of what it gives up in hand.

The setup: two proxies, one host, 4 KB responses

The chain is client → proxy → proxy → origin, all on one host. The official Envoy v1.40.2 binary runs with 4 workers and speaks HTTP/1.1 over loopback. A load generator sends a fixed request rate, and the price is the proxies’ CPU cycles (user plus kernel) divided by the responses served, given as a simple percent change with its 95% interval. One session on 23 November 2026, 8 rounds in a balanced order, with a second copy of the reference configuration in the same rounds as a same-build check (A/A). The rest of the method is the price list’s.

  • Machine. The price list’s: a bare-metal dual-socket Intel Xeon E5-2673 v4 server from 2016, clock fixed at 2.3 GHz, Ubuntu 24.04 with kernel 6.8. The kernel ran its default mitigations (page-table isolation on this CPU), and connection tracking was active on loopback.
  • Traffic. 4 KB responses from the origin at 5,200 req/s on warm connections, unless a section says otherwise. “4 KB” is the published name of that traffic and means 4,096 bytes; other sizes are in KiB.
  • Pools. Every HTTP hop used one upstream connection pool per downstream connection, as in the published second-hop row. That setting is not Envoy’s default.
  • Same-build check. A/A of the pair: +0.04% [−0.82, +0.90]. The check is judged in log points, 100 times the natural log of the ratio; for small effects a log point is close to a percent. Tables give log points next to the percent where the effect is large.
  • Labels. Measured, Exploratory and Not resolved are used as the series page defines them. One more appears here. Measured [mechanism]: a count or a profile share from one extra run under a tracer or profiler, never a price.

One departure from our plan applies to every row. The plan forbids a login on the machine during measured runs. An interactive session stayed open on the machine during the runs. We kept the rows and record it here: other tasks used at most 0.003 of a CPU on the proxy’s cores in any run.

What the second hop costs: HTTP against tcp_proxy

The pair of proxies with the second hop as tcp_proxy, against the same pair with a minimal HTTP hop, 4 KB responses at 5,200 req/s:

Row Price [95% interval] Basis
Second proxy runs tcp_proxy instead of an HTTP connection manager, plaintext between the proxies −32.9% [−33.6, −32.3] of the pair’s CPU per request (−39.93 log points) Measured
The same, with mutual TLS (TLS 1.2) on the hop between the proxies −30.8% [−31.5, −30.1] of the pair (−36.87 log points) Measured
Reference: the evenly loaded HTTP pair against one proxy (a repeat of the published +99.6%) +98.6% [+96.6, +100.6] Measured
What a tcp_proxy second hop adds, against one proxy +33.2% [+32.1, +34.4] Exploratory

When the second proxy in a pair relays TCP instead of proxying HTTP, the pair costs 33% less CPU per request. The relaying hop makes about as many syscalls as the HTTP hop (9.9 against 9.7) and costs about a third as much (187.4k cycles per request against 529.3k). The first hop is unchanged. Below, a relay means a hop that runs tcp_proxy.

Where the HTTP hop’s cycles go

The second hop on its own, per request, same traffic:

The second hop alone As tcp_proxy As a minimal HTTP hop Basis
CPU cycles per request, plaintext 187.4k 529.3k Measured
CPU cycles per request, mutual TLS on the hop 217.7k 557.5k Measured
User-space cycles per request, plaintext 46.7k 351.8k Measured
Syscalls per request 9.9 9.7 Measured [mechanism]

The relay costs 64.6% less than the HTTP hop in plaintext and 60.8% less with mutual TLS. Its user-space cycles are 87% lower and its kernel cycles 21% lower, with about as many syscalls: what a relaying hop removes is HTTP parsing and filter work, not kernel crossings. The 4 KB response reached each hop in one read and left in one write on both kinds of hop.

The HTTP hop compared was a minimal one: router only, no access log, no other filter. The 342k cycles per request it adds over the relay are the floor of what an HTTP hop adds in this setup. Scope: 4 KB responses on HTTP/1.1. With large bodies the share shrinks, because bytes dominate.

What a tcp_proxy hop gives up

A tcp_proxy hop keeps connection-level load balancing, TLS termination and peer-certificate checks, connection and byte stats, and network-level RBAC. It gives up everything Envoy does per request:

  • per-request load balancing (one upstream per client connection for its lifetime);
  • retries and per-request timeouts;
  • HTTP stats, access logs and tracing per request;
  • routing and policy on headers or paths;
  • protocol translation and multiplexing.

No setting brings these back: a tcp_proxy hop does not see requests.

Mutual TLS on a relayed hop

Mutual TLS on a tcp_proxy hop, against the same hop in plaintext, cost the pair +9.1% [+8.3, +10.0] CPU per request (+63k cycles; Exploratory). The hop negotiated TLS 1.2. In the same session the HTTP pair’s mutual TLS measured +5.8% [+4.9, +6.8]. In cycles the two are close (+63k against about +61k per request); the percentage is larger on the relayed pair because that pair costs less. The +5.8% compares with +6.4% [+5.6, +7.2] in the connections post.

One hop, small messages: a weaker comparison

This comparison is weaker than the pair rows above, and its figure should not be quoted without two facts. The two configurations ran at different load: the HTTP proxy at 42% busy, the tcp_proxy one at 15%. And the HTTP proxy used one pool per downstream connection, which is not Envoy’s default, and held 1,024 upstream connections against 512.

One proxy in front of an nginx origin that answers from memory, 8,000 req/s, small request and response:

Row Price [95% interval] Basis
HTTP proxy against tcp_proxy, 64-byte body +213.2% [+204.3, +222.3] Measured
HTTP proxy against tcp_proxy, 1 KiB body +208.9% [+199.3, +218.9] Measured

That is about 3.1 times: 465k cycles per request as an HTTP proxy against 148k as a relay.

  • By our estimate, not a measurement, at most about 3 points of the +213 could come from the 512 extra idle connections.
  • A/A: +0.26% [−2.13, +2.71] with the 64-byte body and −1.42% [−4.17, +1.41] with 1 KiB, which is close to its limit (1.43 against 1.5 log points).
  • Three rounds of this run were replaced once, by a rule fixed before the run (a client-side check on the HTTP configuration failed). With the original rounds the rows are +211.0% and +207.3%.

Five syscalls per relayed message, two with no data

Envoy relays a small TCP message with five syscalls, two of which return without sending or receiving data: a read that returns EAGAIN, then a zero-timeout wait before the send. The wait does poll and can return events; whether it did was not recorded.

Counts per relayed message on the tcp_proxy proxy of the section above (one request is two relayed messages):

Per relayed message tcp_proxy, a small message (44 bytes up, 226 down) Basis
All syscalls 4.86 Measured [mechanism]
readv 2.00, of which 1.00 returns EAGAIN Measured [mechanism]
sendto 1.00 Measured [mechanism]
epoll_wait 1.86, of which 0.96 with a zero timeout Measured [mechanism]
epoll_ctl, writev 0 Measured [mechanism]
CPU cycles about 74k (about 76k with a 1 KiB body), 77% of them in the kernel Measured
The two calls that carry no data, as a share of those cycles: the estimate from a profile about 9% (range 7 to 11) Exploratory
The same share, measured later with an experimental patch 12.5% [11.1, 13.8] inside one patched build; 11.0% [9.7, 12.3] against the official binary Measured; against the official binary Exploratory

Conditions: 8,000 req/s, the proxy 15% to 16% busy. Wire bytes per request: 44 up and 226 down with the 64-byte body. The counts are kernel tracepoint counts on the Envoy process over 160,033 requests, from one run under a tracer.

The order of the five calls is from our reading of the v1.40.2 source and was not traced: epoll_wait returns, readv reads the data, readv returns EAGAIN, epoll_wait with a zero timeout, sendto. (A write of a single buffer slice goes out through send(), which is why it appears as sendto and not writev.) By the same reading, the empty read is the read loop draining an edge-triggered socket, and the zero-timeout wait exists because the write is deferred to the next event-loop iteration. Removing either has a cost of its own: the empty read is how the loop learns an edge-triggered socket is drained, and the deferred write batches writes and keeps connections fair. A change needs its own check of both.

The counts are measured. The price of the two calls was at first an estimate, and the estimate was then measured (next section): 12.5% inside one patched build and 11.0% against the official binary for the relayed message, 3.1% and 2.4% for a proxied HTTP request. The estimate: from a kernel call-graph profile we put the empty read and the zero-timeout wait at about 9% of the CPU of a small relayed message (range 7 to 11), and at about 3% on a proxied HTTP request. Both are estimates on this 2016 Xeon with page-table isolation. Before the run we fixed two ways to bound that price. They came out far apart: 3.7% and 17.2%. The estimate between them came from a second, independent breakdown of the same profile, not from a comparison of runs, which is why it is Exploratory. The profiled runs cost 11% more cycles per request than the unprofiled ones, so the shares carry that error.

The same two calls appear on plain HTTP: one proxy on the 4 KB proxied traffic makes 9.49 syscalls per request, of them 4.00 readv (2.00 returning EAGAIN) and 3.49 epoll_wait (1.93 with a zero timeout) (Measured [mechanism], one run; this traffic carries the two extra request headers of the price list’s stack section). The counts for a streamed HTTP response are in the price list.

What the two empty calls cost

A relaying hop spends most of its CPU in the kernel, and for a small message two of its five kernel calls do nothing: a read that finds the socket empty and a zero-timeout poll before the send. We measured them with an experimental patch that can remove each call, behind its own switch, inside one build of Envoy v1.40.2. Together they cost 12.5% of the CPU cycles of a relayed 64-byte message (95% interval 11.1 to 13.8; 11.0% [9.7, 12.3] against the official binary), the empty read alone about 8%, and on an ordinary proxied 4 KB HTTP/1.1 request the same two calls are 3.1% [2.3, 3.9] (2.4% [1.6, 3.3] against the official binary). The patch is a measuring tool, not a proposed change. Its larger half, the change to the read, depends on a change to the libevent library bundled with Envoy and is not suitable for upstream in this form. With both changes on, a relay whose connections carry several messages at once (HTTP/2 over 16 connections) made 17% to 19% more send calls per message; those counts come from single traced runs, and the CPU effect under that load was not measured. The prices hold for 64-byte messages and 4 KB responses only, over loopback and plain TCP, on one 2016-era server with page-table isolation, where a kernel call is dearer than on a current CPU. No bulk transfer was measured.

CPU cycles (user plus kernel) of the proxy, against the same patched build with both changes off:

Which change is on Price [95% interval] Syscalls Basis
Both, per relayed 64-byte message −12.5% [−13.8, −11.1], which is 9.4k of 75.0k cycles; against the official binary −11.0% [−12.3, −9.7] (Exploratory) 2.96 per message, from 4.88 Measured
The read stops after a short read (no empty read), per relayed message −8.0% [−10.1, −6.0] (6.1k cycles) 3.92 per message Measured
The write goes out in the same event-loop iteration (no zero-timeout wait), per relayed message −2.9% [−5.2, −0.6] (2.2k cycles) 3.95 per message Not resolved
Both, per proxied 4 KB HTTP/1.1 request −3.1% [−3.9, −2.3], which is 16.3k of 528k cycles; against the official binary −2.4% [−3.3, −1.6] (Exploratory) 6.09 per request, from 9.59 Measured
  • Conditions. The relay of the section above: one proxy with a tcp_proxy listener, 8,000 req/s over 512 warm connections, the proxy about 15% busy. The HTTP row: 4 KB proxied at 5,200 req/s. One session in the night of 23 to 24 November 2026, 12 rounds per kind of traffic in a balanced order, the official v1.40.2 binary and its second copy in the same rounds.
  • Syscall counts. One run per configuration under a tracer, at the priced load (Measured [mechanism]). Each change removes exactly its own call: the empty read goes from 1.00 per message to 0, the zero-timeout wait from 0.96 to 0. The official binary and the patched build with both changes off make the same calls (4.88 per message here, 4.86 in the earlier run). At this load every configuration made 1.00 send calls per message.
  • The estimate against the measurement. The profile estimate was about 9% (range 7 to 11). The measured saving is 11.0% to 12.5%, depending on the reference: at or just above the top of that estimate. The kernel part came out as estimated; the user-space part was about twice the estimate.
  • Two references. The first figure in a row is the price of the calls inside one build. The second is what this experimental build gives over the official binary, and it is Exploratory: it was not a comparison fixed before the run. With both changes off, the patched build read +1.7% [−0.4, +3.8] against the official binary on the relayed message and +0.7% [−0.2, +1.6] on the HTTP request.
  • Same-build check. On the relayed message it missed its limit: +1.15% [−0.47, +2.80], which is 1.14 log points against a limit of 1.0. We then applied a three-times rule: a row stands only when its effect is at least three times that excursion (3.43 log points). Both changes together (13.31 log points) and the read change alone (8.36) pass it. The write change alone (2.94) does not, so its size is Not resolved; it did remove its call. On the HTTP request the check passed: −0.32% [−1.21, +0.57].
  • More send calls under multiplexed load. With HTTP/2 from the client over 16 connections through the relay, both changes together made about 1.5 send calls per message against about 1.25, while all syscalls per message still fell by about 30%. Either change alone did not add send calls. One traced run per configuration and rate (Exploratory).

The experiment is two commits on v1.40.2, on We-Amp’s Envoy fork as the branch experiments/relay-syscalls and, in the state that was measured, as the tag relay-syscalls-2026-11/v1. Each change is behind its own runtime guard: envoy.reloadable_features.raw_buffer_socket_stop_on_short_read for the read and envoy.reloadable_features.connection_write_in_current_iteration for the write. It is not part of any Envoy release and has not been reviewed by the Envoy project.

A Unix domain socket for a same-host hop

A Unix domain socket instead of loopback TCP, 4 KB responses at 5,200 req/s, the same run as the pair rows:

Row Price [95% interval] Basis
Unix domain socket instead of loopback TCP between two proxies −6.0% [−6.8, −5.2] of the pair’s CPU per request (−63k cycles, both ends of the hop counted) Measured
Unix domain socket instead of loopback TCP from the proxy to the origin −4.5% [−5.7, −3.3] of the proxy’s CPU per request (−25k cycles, the proxy’s end only) Measured
  • Same host only: a Unix socket cannot cross hosts.
  • The two rows count different things. The first counts both proxies, the second only the proxy, so they do not compare one for one.
  • The saving is kernel time: Envoy’s kernel cycles fell 15% (between the proxies, first hop) and 17% (to the origin), while user cycles moved by −2.7% and +1.9%. Context switches per request rose (+58% and +23%).
  • Loopback TCP on this host passes through connection tracking; its symbols show in the profile. A host without it would save less. That was not measured.
  • In the origin row the origin’s own CPU fell too (56 to 35 µs per request). It is not in the figure, so that row understates the total.

What was not resolved

  • The tcp_proxy idle timer. Setting idle_timeout: 0s on the relay changed total CPU by −2.38% [−5.76, +1.13] with the 64-byte body and −4.04% [−8.23, +0.34] with 1 KiB: inside the run’s noise at 15% busy (Not resolved). User-mode instructions per request fell by 9.6% [9.0, 10.2] (Exploratory).
  • The write change of the experimental patch on its own: −2.9% [−5.2, −0.6] of a relayed message, under the three-times rule of its section (Not resolved).
  • The CPU effect of that patch under multiplexed load, where it made 17% to 19% more send calls per message: not measured.
  • Latency through two hops. It stays unpublished, as in the price list.

What this does not cover

  • More than one host. Every hop here is on loopback, with connection tracking active.
  • A current CPU. On this 2016 Xeon with page-table isolation each syscall costs more than on a current CPU; by how much was not measured here.
  • Protocols other than HTTP/1.1, and bodies larger than 4 KB on the pair rows.
  • Relays under load. The one-hop relay rows and the syscall counts ran at 15% to 16% busy, and the prices of the two empty calls at about 15%.
  • Bulk transfer through a relay. The experimental patch was priced on 64-byte messages and 4 KB responses only.
  • Slow clients.
  • The first hop as tcp_proxy, and a chain of more than two proxies.

If one of these figures does not match what you see, compare the conditions first.

How to reproduce it

The syscall counts need none of our code:

  1. Run Envoy with a tcp_proxy listener in front of any origin.
  2. Send small requests over keep-alive connections.
  3. Attach a syscall tracer to the Envoy process for a fixed window.
  4. Divide each call’s count by the number of relayed messages (two per request).

The prices use the public A/B measurement harness at github.com/We-Amp/envoy-price-list (code under Apache 2.0, data under CC BY 4.0). The data for this post is in the harness repository at tag waves-2026-11d: the configurations in examples/wave7s1 and examples/wave7s5, the run notes in docs/wave-studies.md (relay syscalls) and the raw data in the release archives waves-2026-11d-data-second-hop.tar.gz and waves-2026-11d-data-relay-syscalls.tar.gz (checksums in SHA256SUMS).

If you reproduce this, post what you get as an issue on the A/B harness.

Credit

Envoy, its HTTP connection manager and tcp_proxy are the work of the Envoy project’s contributors. Nothing here is a defect report: both hops do what they are documented to do. The measurements and any error in them are ours.

← All writing