Skip to content

Add least-connections load balancing across resolved addresses - #2400

Merged
hyperxpro merged 1 commit into
mainfrom
feature/least-connections-load-balance
Nov 22, 2026
Merged

hyperxpro merged 1 commit into
mainfrom
feature/least-connections-load-balance

Conversation

@hyperxpro

Copy link
Copy Markdown
Member

Motivation:

A host that resolves to several IPs gets its connections on the first address in DEFAULT mode, and ROUND_ROBIN rotates per request without regard to how many connections each address already holds.

Modification:

Add LoadBalance.LEAST_CONNECTIONS. When a new direct connection is opened to a multi-address host, LeastConnectionsAddressSelector picks the address with the fewest connections open or opening from this client. The failed-IP cooldown outranks the count, and ties keep resolver order. Failover picks the same way among the addresses not tried yet, preferring the address family with fewer failed attempts.

NettyChannelConnector counts each attempt and releases it once, on connect failure or channel close. Pooling and the HTTP/2 registry stay per host.

Result:

Concurrent HTTP/1.1 requests spread their connections evenly across a host's addresses. HTTP/2 keeps one connection per host, so the mode only chooses where a replacement or racing connection goes. DEFAULT and ROUND_ROBIN are unchanged.

Fixes #2397

@hyperxpro
hyperxpro merged commit 351e4ea into main Nov 22, 2026
17 checks passed
@hyperxpro
hyperxpro deleted the feature/least-connections-load-balance branch November 22, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add least-connections load balancing across resolved addresses

1 participant