Skip to main content

Envoy performance · part 8 of 12

Envoy worker imbalance: uneven load, exact_balance and connection recycling

By Otto van der Schaaf, We-Amp ·

Envoy keeps each connection on one worker thread for the connection’s whole life. That keeps a request’s work on one thread without locks, and it means the load on each worker is only as even as the work on its connections. When a few client connections carry most of the requests, one worker can do far more than its share while the proxy’s average CPU looks fine.

We measured it in one session whose comparisons and readings were fixed in advance. On the shape we confirmed, 16 client connections of which 4 carry 76.9% of the requests, at 3,120 req/s, Envoy’s default left the busiest worker with 44% of worker CPU time on average; even is 25% (loopback, this CPU). Recycling connections every 1,000 requests (max_requests_per_connection) brought that down by 13.78 points in one session: lower, and not shown to be even. On that shape exact_balance and the shared listen socket made no difference we could resolve. On a second shape (32 connections, 8 of them carrying 98.8% of the requests), and for that shape and this load generator only, exact_balance brought the load back to even; CPU per request rose 3.15% [+1.43, +4.91] in one session, which includes the effect of the more even spread.

Every figure is from one 2016 server over loopback, the official Envoy v1.40.2 binary, 4 workers, HTTP/1.1 and 4 KB proxied responses. Loopback has no RSS, no NIC queues and no interrupt steering; on real hardware they decide part of the connection placement and of the per-core load. So the shapes and the relative effect of each setting are the finding, not the absolute shares. Below, the busiest worker’s share is its share of worker CPU time, written as a fraction of 1 (0.25 is even); changes in it are in points (0.01 is one point); CPU per request is in percent; bracketed ranges are 95% intervals. The other posts of the series are listed on Envoy performance, measured.

Contents

Why does Envoy load its workers unevenly?

Once a worker accepts a connection, every request on that connection runs on that worker. How new connections reach the workers depends on the listener:

  • Envoy’s default gives each worker its own listening socket (enable_reuse_port is on), and the kernel hashes each new connection to one of those sockets. No balancer is configured.
  • exact_balance (connection_balance_config on the listener) hands each new connection to the worker with the fewest open connections. It balances connection counts, not requests.
  • A shared listen socket (enable_reuse_port: false) has every worker accept from one socket, so by design a connection goes to whichever worker accepts it first.
Diagram: Envoy pins each client connection to one worker for its life; reuse_port, exact_balance and a shared socket only pick that first worker, so equal connection counts can still leave the heavy connections on one or two workers.An illustration. On the left, a client with 16 connections, 4 of them heavy; in the shape this post confirmed, the 4 heavy connections together carry 76.9% of the requests. In the middle, the listener places each new connection on one worker, once: with Envoy's default (reuse_port) the kernel hashes it to a worker's socket, with exact_balance it goes to the worker with the fewest open connections, and with a shared socket to the worker that accepts first. On the right, four workers with 4 connections each, equal counts, but two heavy connections on worker 0 and two on worker 1, so those two workers do most of the work and workers 2 and 3 little. A connection stays on its worker for its whole life. Recycling every 1,000 requests closes a connection; the client opens a new one and the listener places it again, whole, so a heavy connection still lands on one worker.Client16 connectionsListener: picks a workeronce, when it acceptsdefault (reuse_port):kernel hash to a socketexact_balance: fewestopen connectionsshared socket: firstworker to acceptworker 04 connectionsworker 14 connectionsworker 24 connectionsworker 34 connectionsequal connection counts, unequal workRecycling every 1,000 requests:the new connection is placedagain, whole, on one workerheavy: the 4 together carry 76.9% of the requests (the shape this post confirmed)lightPlacement drawn for illustration; measured shares are in the chart below.Diagram: Envoy pins each client connection to one worker for its life; reuse_port, exact_balance and a shared socket only pick that first worker, so equal connection counts can still leave the heavy connections on one or two workers.An illustration. On the left, a client with 16 connections, 4 of them heavy; in the shape this post confirmed, the 4 heavy connections together carry 76.9% of the requests. In the middle, the listener places each new connection on one worker, once: with Envoy's default (reuse_port) the kernel hashes it to a worker's socket, with exact_balance it goes to the worker with the fewest open connections, and with a shared socket to the worker that accepts first. On the right, four workers with 4 connections each, equal counts, but two heavy connections on worker 0 and two on worker 1, so those two workers do most of the work and workers 2 and 3 little. A connection stays on its worker for its whole life. Recycling every 1,000 requests closes a connection; the client opens a new one and the listener places it again, whole, so a heavy connection still lands on one worker.Client: 16 connectionsListener: picks a worker once,when it acceptsdefault (reuse_port): kernel hashexact_balance: fewest open connectionsshared socket: first worker to acceptworker 04 conn.worker 14 conn.worker 24 conn.worker 34 conn.equal connection counts, unequal workRecycling every 1,000 requests closes aconnection; the new one is placed again,whole, on one worker.heavy: the 4 together carry 76.9%of the requests (the confirmed shape)lightPlacement drawn for illustration; measuredshares are in the chart below.
Each of the three listener modes chooses a worker once, when a connection is accepted, and the connection then stays there. exact_balance evens out the connection counts, and the requests follow wherever the heavy connections landed. Recycling with max_requests_per_connection makes the client reconnect, and the listener places the new connection again as one piece. The measured shares for this shape (16 connections, 4 heavy ones carrying 76.9% of the requests, 3,120 req/s, 4 workers, loopback) are in the chart and tables below.

None of the three can move a connection once it is placed. If four connections carry most of the requests, the load on each worker depends on where those four landed, whichever mode placed them. The client matters as much as the proxy: a client that sends most of its requests over a few connections concentrates the work on whichever workers own them.

Where have we seen it before?

Twice, in our own work. Our load generator’s default connection reuse kept most requests on a few connections, so a few of Envoy’s workers carried the load and some of our early results were skewed. Between two Envoy proxies, a brief stall of the second one left its busiest worker carrying far more than its share for as long as we watched; the price list’s section on upstream connection reuse order has those rows. Both were about connections between our own components. This session asks the same question at the front door, where the shape of client traffic decides.

How uneven did the load get?

The shape we confirmed: 16 client connections, one per client worker; 4 heavy connections carry 76.9% of the requests, at 600 req/s each; 3,120 req/s in total. A shorter exploratory run chose which shapes to measure in full; this post quotes none of its numbers. The busiest worker’s share is measured per worker thread over a 20 s window.

On this shape an even split is possible by construction: each heavy connection carries 19.2% of the requests, so one heavy and three light connections per worker would put 25% of the requests on every worker. Under Envoy’s default, the busiest worker’s share of worker CPU time was above 0.53 in 5 of 30 starts (we call this the concentrated placement). If every connection landed on a worker independently and at random, 6.16 of 30 would be expected; that figure is computed on the share of requests, which is not the same scale as the share of CPU time. In those 5 starts the busiest worker’s share averaged 0.569; in the other 25, 0.416.

Over all 30 starts the busiest worker’s share averaged 0.441 [0.413, 0.470] under Envoy’s default, and the mean of its per-second shares was also 0.441 [0.413, 0.470]; the two agree to three decimals. On this machine a busier core spends less CPU per request, so a share of CPU time understates the busiest worker’s share of the requests.

One of the 5 starts above 0.53, second by second, picked by a rule fixed in advance:

Share of worker CPU time per second for each of Envoy's four workers, one start under Envoy's defaultLine chart over the 20-second measurement window, one line per worker, with a dashed line at an even share of 0.25. The busiest worker's line stays far above the even line in every second; the other three workers' lines stay well below the busiest worker's. One run, an illustration, not a price.Busiest workerThe other three workersEven split00.250.500.7515101520Second of the 20 s windowShare of worker CPU timebusiestevenShare of worker CPU time per second for each of Envoy's four workers, one start under Envoy's defaultLine chart over the 20-second measurement window, one line per worker, with a dashed line at an even share of 0.25. The busiest worker's line stays far above the even line in every second; the other three workers' lines stay well below the busiest worker's. One run, an illustration, not a price.Busiest workerThe other three workersEven splitShare of worker CPU time00.250.500.7515101520Second of the 20 s windowbusiesteven
Envoy's default; a start with the concentrated placement (5 of 30 starts); share of worker CPU time; loopback, this CPU; one run, an illustration, not a price.

What did connection balancing and recycling change, and what did they cost?

Each setting ran against Envoy’s default in its own Envoy process, 30 restart-paired rounds per comparison, measured in a test we fixed before the session. The share column is the change in the busiest worker’s share; the CPU column is the change in CPU per request. The “What it shows” column quotes the reading we fixed in advance for each result. For share changes we set a threshold of 5 points in advance: we make no claim about a smaller change.

Conditions for both tables: Envoy’s default as the reference; loopback, this CPU; share of worker CPU time; 3,120 req/s.

The shape we confirmed: 16 connections, 4 heavy ones carrying 76.9% of the requests.

Setting Busiest worker’s share, change What it shows CPU per request² Basis
Recycle connections every 1,000 requests (max_requests_per_connection: 1000) −13.78 points [−16.60, −10.96], one session “reduces it; even not established” −0.23% [−1.99, +1.55] no difference resolved; not a finding¹
exact_balance −2.81 points [−5.90, +0.28], one session no difference resolved; under the 5-point threshold +0.66% [−1.56, +2.92] no difference resolved; not a finding¹
Shared listen socket (enable_reuse_port: false) +1.73 points [−3.27, +6.73], one session no difference resolved; under the 5-point threshold −0.83% [−3.68, +2.10] no difference resolved; not a finding¹

A second shape: 32 connections, two per client worker; 8 of them carry 98.8% of the requests; 3,120 req/s total. Its results hold for this shape and this load generator.

Setting Busiest worker’s share, change What it shows CPU per request² Basis
exact_balance −16.31 points [−19.32, −13.30], one session “brings it back to even” +3.15% [+1.43, +4.91] 2% and over: one session; includes the effect of a more even spread
Recycle connections every 1,000 requests −10.89 points [−13.76, −8.02], one session “reduces it, not back to even” −0.55% [−2.07, +0.98] no difference resolved; not a finding¹
Shared listen socket −2.56 points [−6.97, +1.85], one session no difference resolved; under the 5-point threshold +0.30% [−1.66, +2.30] no difference resolved; not a finding¹

¹ Under about 1% from one session: not a finding by the price list’s rule, quoted under how we measured.
² The wider of the 95% interval and the 95% interval widened by the between-session spread.

Recycling on the shape we confirmed. With connections recycled every 1,000 requests, the busiest worker’s share over 20 s averaged 0.304 [0.292, 0.315]: lower, and not shown to be even. Recycling does not split a heavy connection. By design, Envoy closes a connection after its 1,000th request, the client opens a new one, and the listener places that one again. At 3,120 req/s that is about 3.1 reconnects per second for the whole listener, about 2.4 per second of them on the 4 heavy connections, so each heavy connection is placed again about every 1.7 s. Per second, the busiest worker’s share read 0.423 [0.415, 0.432] with recycling, and 0.441 [0.413, 0.470] under the default. This session has no paired comparison of these two per-second figures, so we draw no conclusion from them.

Its CPU cost on this shape, −0.23% [−1.99, +1.55], includes the effect of a more even spread and is not resolved, which does not make it free: each reconnect is a new connection, and on TLS a new connection has a price of its own. This session ran plaintext.

exact_balance on the shape we confirmed. No difference resolved. By design it balances connection counts, not requests.

What does each balancing mode cost under constant reconnects?

A third load ran clients that reconnect every 10 requests: 512 connections, 5,200 req/s, 520 new connections per second, spread evenly (Envoy’s default as the reference; loopback, this CPU). Here the question is what each listener mode costs on its own when connections arrive all the time.

Setting CPU per request² Basis
exact_balance +1.19% [+0.43, +1.95] between 1% and 2%, widened interval excludes zero
Shared listen socket −0.85% [−1.60, −0.10] under about 1% from one session: not a finding by the price list’s rule
Recycle connections every 1,000 requests +0.03% [−0.70, +0.77] configured, never reached at this shape

The exact_balance row holds for this load-generator recipe: reconnect every 10 requests. It is also on the price list, in its connections section. The shared socket’s row is under the price list’s 1% line, so we make no claim that a shared socket costs less. With 10 requests per connection the 1,000-request limit never fires, so the recycling row prices a setting that did nothing here.

What should you do on your own Envoy?

1. Look per worker, not per pod. Envoy names its worker threads wrk:worker_0, wrk:worker_1 and so on, so top -H -p <envoy pid> or any per-thread CPU metric shows each worker’s CPU. If the busiest worker sits well above the average while the pod looks fine, you may be looking at this problem; a worker can also run hot from expensive requests. Envoy’s per-worker listener stats, listener.<address>.worker_<N>.downstream_cx_active and downstream_cx_total, show how many connections each worker holds. They do not show how much work those connections carry, so even connection counts can sit beside uneven CPU.

2. Find the heavy connections. Common sources are another proxy, a load balancer with a small connection pool, or a client library that reuses the connections it used last. In principle, spreading their requests evenly over many connections, so that no single connection carries a large share, addresses the cause; we did not measure it.

3. Recycle connections (max_requests_per_connection) when a few long-lived connections carry most of the load. On the HTTP connection manager:

common_http_protocol_options:
  max_requests_per_connection: 1000

On our shape, recycling brought the busiest worker’s 20 s share to 0.304 [0.292, 0.315], lower and not shown to be even; its per-second share read 0.423 [0.415, 0.432]. Even is 0.25. Your shares will differ (loopback, this CPU). Its CPU cost on our shape was not resolved; measure yours, and count the handshakes if the connections use TLS. New connections per second are at most roughly requests per second divided by the limit: 3,120 req/s at a limit of 1,000 is about 3.1 per second. We measured only 1,000; a lower limit places heavy connections again more often and costs more reconnects, and we did not measure either. downstream_cx_max_requests_reached counts the connections the limit closed, which tells you whether it fires at all.

4. Try exact_balance when the connection counts per worker differ (by design; we did not measure that case), and price it.

connection_balance_config:
  exact_balance: {}

It acts on connection counts. On our first shape it resolved no difference. On the second shape, for that shape and this load generator, it brought the load back to even, and CPU per request rose 3.15% [+1.43, +4.91] (2% and over, one session), which includes the effect of the more even spread. Under constant reconnects it cost +1.19% [+0.43, +1.95] per request at 520 new connections per second (between 1% and 2%, widened interval excludes zero). Envoy’s documentation scopes it to listeners with a small number of connections that rarely cycle; in an exploratory run with one-request connections spread over 16 listener addresses, it piled them onto one worker (connection-cost post), a case the documentation’s scope excludes.

5. Leave the shared socket alone on this evidence. It resolved no difference on either shape, and its reconnect row is not a finding by the price list’s rule.

6. Measure before and after on your traffic. The same proxy with and without the setting, at a fixed request rate, several rounds in alternating order, with the busiest worker’s share read per worker thread. The measurement loop and how to benchmark a proxy’s CPU describe how we do that.

If one worker in your fleet runs hot while the rest idle, we can replay your traffic shape against your configuration and measure what each setting changes: see Envoy performance consulting.

What should you not conclude?

  • More than “no difference resolved” from exact_balance on the shape we confirmed. That reading is about this session, not a verdict on the setting.
  • That exact_balance evens out heavy connections in general. On the second shape it did, for that shape and this load generator.
  • That recycling is free. Its CPU cost on the shape we confirmed was not resolved.
  • That the shape we confirmed is where the imbalance is largest. It is the shape the exploratory run picked, and the shares here belong to this machine over loopback.

How we measured

  • Conditions. The official Envoy v1.40.2 release binary, 4 workers, HTTP/1.1, 4 KB proxied responses, on one 2016 two-socket x86-64 server over loopback. Both lopsided shapes ran at 3,120 req/s, below the price list’s usual load; the reconnect load ran at 5,200 req/s.
  • Reference. Envoy’s default listener (no balancer, enable_reuse_port on). Most of the price list’s rows use exact_balance, so the two are not directly comparable.
  • Client. Nighthawk, built from our public fork, with each of its 16 client workers sending its own share of the rate: an open-loop schedule, one HTTP/1.1 connection per client worker (two on the second shape), one request in flight per connection. The reconnect load used the price list’s 512-connection recipe, here reconnecting every 10 requests. The fork’s changes are described in the measurement-loop post.
  • Restart-paired legs. Every leg ran in its own Envoy process: a 2 s lead-in, then a 20 s measurement window. Each comparison has 30 rounds in rotated order, and each start places the connections afresh. An identical copy of one configuration ran in the same rounds as a same-configuration check, and every such check passed.
  • What is counted. The busiest worker’s share is its on-CPU time from the kernel’s scheduler statistics, per worker thread, as a share of all four workers’ time over the window. CPU per request is user plus kernel cycles of the Envoy process divided by the responses it served, given as a percent change. The per-second figure is the average, over the window’s 20 one-second bins, of the share of whichever worker was busiest in that bin; it need not be the same worker from one second to the next.
  • Fixed in advance. The shapes, settings, comparisons and readings were fixed before the session, and the readings are mechanical. The 15 comparisons are tested together, with the significance test corrected for their number. Every row in the tables comes from this session’s paired runs and is pre-registered and measured. The busiest worker’s average shares and the count of starts above 0.53 are reported beside the rows, and the 19.2% and the expected count are arithmetic on the shape. In those readings “back to even” has a fixed meaning: the 95% interval of the busiest worker’s average share lies at or under 0.30, both over the 20 s window and per second. It does not mean exactly 0.25. “Not back to even” means the 20 s interval lies above 0.30, and “even not established” means it straddles 0.30.
  • The price list’s rule for small CPU effects: “An effect under about 1% from one run is not a finding, whatever its own interval says. An effect between 1% and 2% needs a second session, or an interval that still excludes zero once the between-session spread is added.”

What this does not cover

  • max_connection_duration. It was not measured in this session; the price list has its upstream stall rows.
  • Other listener options: cpu_locality_balance and max_connections_to_accept_per_socket_event.
  • HTTP/2, HTTP/3 and TLS. One HTTP/2 connection can carry many concurrent streams, which changes how heavy a connection can get.
  • Bursty heavy flows.
  • Other lopsided shapes. Two heavy connections out of 16, and eight heavy connections out of 16, were tried in the exploratory run and not confirmed; we make no claim about them.
  • More than 4 workers, other machines and real traffic. Every row is one Envoy version, one 2016 server, loopback and synthetic clients. With RSS, NIC queues and interrupt steering in the path the absolute shares can differ.
  • Latency. This session priced CPU and the share of worker CPU time.

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

Where are the code and the data?

The harness is public at github.com/We-Amp/envoy-price-list (code under Apache 2.0, data under CC BY 4.0). The configurations and raw records for this session are assets of the release t15-2026-11, with checksums. Corrections and your own results go to the harness’s issue tracker.

Credit

Envoy’s listeners and connection balancing are the work of the Envoy project’s contributors, and the load generator is Nighthawk. Nothing here is a defect report: each listener mode does what it is documented to do. The measurements and any error in them are ours.

← All writing