-
Notifications
You must be signed in to change notification settings - Fork 98
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
Add client proxy load balancing support #56
Conversation
This commit adds RoundRobin and Random load balancing support to a proxy as well as config support for multiple addresses and load balancer policy on the client proxy config. The default behavior if no policy is set or is a server proxy sends packets to all endpoints. This also introduces the `rand` crate as a dependency, used by the random load balancing implementation. Resolves #3
485cce8
to
17b3998
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks awesome. The only nit I could find was to make a change the client proxy example in /examples
. 🙌
pub enum LoadBalancerPolicy { | ||
/// Send all traffic to all endpoints. | ||
#[serde(rename = "BROADCAST")] | ||
Broadcast, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BROADCAST! Nice!
@@ -69,8 +64,9 @@ pub enum ConnectionConfig { | |||
/// Client is the configuration for a client proxy, for sitting behind a game client. | |||
#[serde(rename = "client")] | |||
Client { | |||
address: SocketAddr, | |||
addresses: Vec<SocketAddr>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to also update https://github.com/googleforgames/quilkin/blob/master/examples/client-proxy.yaml, since that is the closest thing we have to docs right now.
(We should really write some docs 😃 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the examples config!
/// EndpointChooser chooses from a set of endpoints that a proxy is connected to. | ||
trait EndpointChooser: Send + Sync { | ||
/// choose_endpoints asks for the next endpoint(s) to use. | ||
fn choose_endpoints(&self) -> Vec<EndPoint>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super elegant 🔥
.choose_endpoints() | ||
.iter() | ||
.map(|e| e.address) | ||
.collect::<Vec<_>>()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about Vec<_>!
src/load_balancer_policy.rs
Outdated
} | ||
} | ||
|
||
/// RandomEndpointChooser chooses endpoints in round-robin order. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// RandomEndpointChooser chooses endpoints in round-robin order. | |
/// RandomEndpointChooser chooses endpoints in a random order. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome.
This commit adds RoundRobin and Random load balancing
support to a proxy as well as config support for multiple
addresses and load balancer policy on the client proxy config.
The default behavior if no policy is set or is a server proxy
sends packets to all endpoints.
This also introduces the
rand
crate as a dependency, used bythe random load balancing implementation.
Resolves #3