Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: add upstream connection rebalancing #221

Merged
merged 1 commit into from
Feb 8, 2025
Merged

Conversation

andydunstall
Copy link
Owner

Adds support for rebalancing upstream connections across the cluster.

Every second each node calculates it's connection "balance", which is the ratio of the number of connections the node has locally to the cluster average. If a node finds it's balance exceeds the configured threshold, it will shed connections.

Since the Piko cluster is typically hosted behind a load balancer, when connections are shed, clients will automatically reconnect to random node in the cluster, so eventually the nodes connections will be balanced.

This does mean rebalancing isn't perfect, as an upstream may be disconnected and reconnect to the node that's already shedding connections, but it's the best we can do. It will cause minor disruption while upstreams reconnect, though the alternative is to overload Piko nodes with no way to rebalance load.

By default rebalancing is disabled.

Fixes #176.

@andydunstall andydunstall force-pushed the conn-rebalancing branch 7 times, most recently from 78e696c to fd1bf4b Compare February 8, 2025 10:51
Adds support for rebalancing upstream connections across the cluster.

Every second each node calculates it's connection "balance", which is
the ratio of the number of connections the node has locally to the
cluster average. If a node finds it's balance exceeds the configured
threshold, it will shed connections.

Since the Piko cluster is typically hosted behind a load balancer, when
connections are shed, clients will automatically reconnect to random
node in the cluster, so eventually the nodes connections will be
balanced.

This does mean rebalancing isn't perfect, as an upstream may be
disconnected and reconnect to the node that's already shedding
connections, but it's the best we can do. It will cause minor disruption
while upstreams reconnect, though the alternative is to overload Piko
nodes with no way to rebalance load.

By default rebalancing is disabled.

Fixes #176.
@andydunstall andydunstall marked this pull request as ready for review February 8, 2025 13:36
@andydunstall andydunstall merged commit 5bcbb18 into main Feb 8, 2025
3 checks passed
@andydunstall andydunstall deleted the conn-rebalancing branch February 8, 2025 13:37
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.

Upstream Connection Rebalancing
1 participant