-
Notifications
You must be signed in to change notification settings - Fork 172
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
Introduce least-outstanding-connections load balancing #282
Conversation
candidates.sort_by(|a, b| { | ||
self.busy_connection_count(b) | ||
.partial_cmp(&self.busy_connection_count(a)) | ||
.unwrap() |
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 actually, the least_checked_out_connections which can be skewed by clients that are idle in transactions, I think we should be fine though.
This is really cool, can't wait. This is also called |
I created a load balancer simulator that runs in the browser. Had fun tinkering with that |
src/pool.rs
Outdated
@@ -565,6 +579,20 @@ impl ConnectionPool { | |||
pub fn server_info(&self) -> BytesMut { | |||
self.server_info.clone() | |||
} | |||
|
|||
fn busy_connection_count(&self, address: &Address) -> u32 { | |||
let state = self.databases[address.shard][address.address_index].state(); |
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.
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! 💯
Least outstanding connections load balancing can improve the load distribution between instances but for Pgcat it may also improve handling slow replicas that don't go completely down. With LoC, traffic will quickly move away from the slow replica without waiting for the replica to be banned.
If all replicas slow down equally (due to a bad query that is hitting all replicas), the algorithm will degenerate to Random Load Balancing (which is what we had in Pgcat until today).
This may also allow Pgcat to accommodate pools with differently-sized replicas.