pg.ddx.io  pgdogdev/pgdog GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgdogdev/pgdog] PR #2077: fix(lb): bannable targets should not affect RR distribution
7+ messages / 4 participants
[nested] [flat]

* [pgdogdev/pgdog] PR #2077: fix(lb): bannable targets should not affect RR distribution
@ 2026-11-19 19:29 "meskill (@meskill)" <noreply+meskill@github.com>
  0 siblings, 0 replies; 7+ messages in thread

From: meskill (@meskill) @ 2026-11-19 19:29 UTC (permalink / raw)
  To: pgdogdev/pgdog <noreply+pgdogdev-pgdog@github.com>

With round-robin (and weighted-round-robin) strategy if the target is banned the next target will get twice as much load because it will handle both load of itself and banned target.

The fix creates the list of healthy replicas instead that is used to distribute the load.

inline patch 1: pgdog/src/backend/pool/lb/mod.rs, pgdog/src/backend/pool/lb/test/mod.rs, pgdog/src/backend/pool/lb/test/role_detection.rs (+366/-539 lines) download inline-1.patchdiff --git a/pgdog/src/backend/pool/lb/mod.rs b/pgdog/src/backend/pool/lb/mod.rs index e2e846e7c..7e377ba38 100644 --- a/pgdog/src/backend/pool/lb/mod.rs +++ b/pgdog/src/backend/pool/lb/mod.rs @@ -447,52 +447,61 @@ impl LoadBalancer { return Err(Error::AllReplicasDown); } - match self.lb_strategy { - Random => candidates.shuffle(&mut rand::rng()), - RoundRobin => { - let first = self.round_robin.fetch_add(1, Ordering::Relaxed) % candidates.len(); - let mut reshuffled = SmallVec::with_capacity(candidates.len()); - reshuffled.extend_from_slice(&candidates[first..]); - reshuffled.extend_from_slice(&candidates[..first]); - candidates = reshuffled; - } - LeastActiveConnections => { - candidates.sort_by_cached_key(|target| target.pool.lock().checked_out()); - } - WeightedRoundRobin => { - let total_weight: i64 = candidates - .iter() - .map(|target| target.pool.config().lb_weight as i64) - .sum(); - - if total_weight > 0 { - for target in &candidates { - target - .current_weight - .fetch_add(target.pool.config().lb_weight as i64, Ordering::Relaxed); - } + // make sure we don't use the banned targets calculations, + // since it can skew the distribution when we have banned instances + let mut healthy: SmallVec<[&Target; 32]> = candidates + .iter() + .copied() + .filter(|target| !target.ban.banned()) + .collect(); - let max_idx = candidates + if !healthy.is_empty() { + match self.lb_strategy { + Random => healthy.shuffle(&mut rand::rng()), + RoundRobin => { + let first = self.round_robin.fetch_add(1, Ordering::Relaxed) % healthy.len(); + healthy.rotate_left(first); + } + LeastActiveConnections => { + healthy.sort_by_cached_key(|target| target.pool.lock().checked_out()); + } + WeightedRoundRobin => { + let total_weight: i64 = healthy .iter() - .enumerate() - .max_by_key(|(_, t)| t.current_weight.load(Ordering::Relaxed)) - .map(|(idx, _)| idx) - .unwrap_or_default(); - - candidates[max_idx] - .current_weight - .fetch_sub(total_weight, Ordering::Relaxed); + .map(|target| target.pool.config().lb_weight as i64) + .sum(); + + if total_weight > 0 { + for target in &healthy { + target.current_weight.fetch_add( + target.pool.config().lb_weight as i64, + Ordering::Relaxed, + ); + } + + let max_idx = healthy + .iter() + .enumerate() + .max_by_key(|(_, t)| t.current_weight.load(Ordering::Relaxed)) + .map(|(idx, _)| idx) + .unwrap_or_default(); + + healthy[max_idx] + .current_weight + .fetch_sub(total_weight, Ordering::Relaxed); - candidates.swap(0, max_idx); + healthy.swap(0, max_idx); + } } } } - // Only ban a candidate pool if there are more than one - // and we have alternates. - let bannable = candidates.len() > 1; + // Only ban a candidate pool if there are other healthy alternates. + let bannable = healthy.len() > 1; - for target in &candidates { + for target in &healthy { + // we still check banned state since the candidate + // could be banned in the middle of `get` awaiting if target.ban.banned() { continue; } diff --git a/pgdog/src/backend/pool/lb/test/mod.rs b/pgdog/src/backend/pool/lb/test/mod.rs index 8bb31b1dc..9b467a416 100644 --- a/pgdog/src/backend/pool/lb/test/mod.rs +++ b/pgdog/src/backend/pool/lb/test/mod.rs @@ -62,19 +62,55 @@ fn create_auto_test_pool_config(host: &str, port: u16) -> PoolConfig { config } -fn setup_test_replicas() -> LoadBalancer { - let pool_config1 = create_test_pool_config("127.0.0.1", 5432); - let pool_config2 = create_test_pool_config("localhost", 5432); +fn replica_pool_configs(count: usize) -> Vec<PoolConfig> { + ["127.0.0.1", "localhost"] + .into_iter() + .cycle() + .take(count) + .map(|host| create_test_pool_config(host, 5432)) + .collect() +} + +#[bon::builder(finish_fn = build)] +fn test_lb<'a>( + primary: Option<Pool>, + configs: &'a [PoolConfig], + #[builder(default)] strategy: LoadBalancingStrategy, + #[builder(default)] rw_split: ReadWriteSplit, + #[builder(default)] bans: &'a [usize], +) -> LoadBalancer { + let lb = LoadBalancer::new(&primary, configs, strategy, rw_split, Default::default()); + for &idx in bans { + lb.targets[idx].ban.ban(Error::ManualBan, Duration::MAX); + } + lb +} - let replicas = LoadBalancer::new( - &None, - &[pool_config1, pool_config2], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - replicas.launch(); - replicas +impl<S: test_lb_builder::IsComplete> TestLbBuilder<'_, S> { + fn launch(self) -> LoadBalancer { + let lb = self.build(); + lb.launch(); + lb + } +} + +async fn checkout_shares(lb: &LoadBalancer, checkouts: usize) -> Vec<usize> { + let request = Request::default(); + let mut shares = vec![0; lb.targets.len()]; + for _ in 0..checkouts { + let conn = lb.get(&request).await.unwrap(); + let idx = lb + .targets + .iter() + .position(|target| target.pool.id() == conn.pool.id()) + .expect("connection comes from a load balancer target"); + shares[idx] += 1; + } + shares +} + +fn setup_test_replicas() -> LoadBalancer { + test_lb().configs(&replica_pool_configs(2)).launch() } fn set_lsn_stats(target: &Target, replica: bool, lsn: u64) { @@ -102,15 +138,11 @@ async fn test_include_primary_if_replica_banned_only_primary() { primary.address.configured_role = Role::Primary; let pool = Pool::new(&primary); - let lb = LoadBalancer::new( - &Some(pool), - &[], - LoadBalancingStrategy::default(), - ReadWriteSplit::IncludePrimaryIfReplicaBanned, - Default::default(), - ); - - lb.launch(); + let lb = test_lb() + .primary(pool) + .configs(&[]) + .rw_split(ReadWriteSplit::IncludePrimaryIfReplicaBanned) + .launch(); let conn = lb.get(&Request::default()).await.unwrap(); drop(conn); @@ -246,14 +278,10 @@ async fn test_primary_pool_banning() { let replica_configs = [create_test_pool_config("localhost", 5432)]; - let replicas = LoadBalancer::new( - &Some(primary_pool), - &replica_configs, - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb() + .primary(primary_pool) + .configs(&replica_configs) + .launch(); // Test primary ban exists assert!(replicas.primary_target().is_some()); @@ -403,14 +431,11 @@ async fn test_read_write_split_exclude_primary() { create_test_pool_config("127.0.0.1", 5432), ]; - let replicas = LoadBalancer::new( - &Some(primary_pool), - &replica_configs, - LoadBalancingStrategy::Random, - ReadWriteSplit::ExcludePrimary, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb() + .primary(primary_pool) + .configs(&replica_configs) + .rw_split(ReadWriteSplit::ExcludePrimary) + .launch(); let request = Request::default(); @@ -436,17 +461,12 @@ async fn test_read_write_split_exclude_primary() { async fn test_lsn_filtering() { let primary = Pool::new(&create_test_pool_config("127.0.0.1", 5432)); let primary_id = primary.id(); - let replicas = LoadBalancer::new( - &Some(primary), - &[ - create_test_pool_config("127.0.0.1", 5432), - create_test_pool_config("localhost", 5432), - ], - LoadBalancingStrategy::RoundRobin, - ReadWriteSplit::ExcludePrimary, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb() + .primary(primary) + .configs(&replica_pool_configs(2)) + .strategy(LoadBalancingStrategy::RoundRobin) + .rw_split(ReadWriteSplit::ExcludePrimary) + .launch(); // Include positions across the high bit of the unsigned LSN. for (behind, caught_up, ahead) in [(100, 200, 201), ((1 << 63) - 1, 1 << 63, (1 << 63) + 1)] { set_lsn_stats(&replicas.targets[0], true, behind); @@ -476,17 +496,12 @@ async fn test_lsn_filtering() { async fn test_include_primary_if_replica_lag() { let primary = Pool::new(&create_test_pool_config("127.0.0.1", 5432)); let primary_id = primary.id(); - let replicas = LoadBalancer::new( - &Some(primary), - &[ - create_test_pool_config("127.0.0.1", 5432), - create_test_pool_config("localhost", 5432), - ], - LoadBalancingStrategy::RoundRobin, - ReadWriteSplit::IncludePrimaryIfReplicaLag, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb() + .primary(primary) + .configs(&replica_pool_configs(2)) + .strategy(LoadBalancingStrategy::RoundRobin) + .rw_split(ReadWriteSplit::IncludePrimaryIfReplicaLag) + .launch(); set_lsn_stats(&replicas.targets[0], true, 100); set_lsn_stats(&replicas.targets[1], true, 200); @@ -524,15 +539,10 @@ async fn test_user_read_only_include_primary() { create_test_pool_config("127.0.0.1", 5432), ]; - // Use `IncludePrimary` - let replicas = LoadBalancer::new( - &Some(primary_pool), - &replica_configs, - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb() + .primary(primary_pool) + .configs(&replica_configs) + .launch(); // Notice that we `read` to true and `read_only` to true. let request = Request::new( @@ -570,14 +580,10 @@ async fn test_user_read_only_include_primary_no_replicas() { let replica_configs = [create_test_pool_config("localhost", 5432)]; - let replicas = LoadBalancer::new( - &Some(primary_pool), - &replica_configs, - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb() + .primary(primary_pool) + .configs(&replica_configs) + .launch(); // Ban the replica let replica_ban = &replicas.targets[0].ban; @@ -618,14 +624,10 @@ async fn test_read_write_split_include_primary() { let replica_configs = [create_test_pool_config("localhost", 5432)]; - let replicas = LoadBalancer::new( - &Some(primary_pool), - &replica_configs, - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb() + .primary(primary_pool) + .configs(&replica_configs) + .launch(); let request = Request::default(); @@ -672,14 +674,12 @@ async fn test_prefer_primary_optin_read_honors_read_write_split() { create_test_pool_config("127.0.0.1", 5432), ]; - let lb = LoadBalancer::new( - &Some(primary_pool), - &replica_configs, - LoadBalancingStrategy::RoundRobin, - split, - Default::default(), - ); - lb.launch(); + let lb = test_lb() + .primary(primary_pool) + .configs(&replica_configs) + .strategy(LoadBalancingStrategy::RoundRobin) + .rw_split(split) + .launch(); let request = Request::default(); let mut ids = HashSet::new(); @@ -718,16 +718,12 @@ async fn test_read_write_split_exclude_primary_no_replicas() { let primary_pool = Pool::new(&primary_config); primary_pool.launch(); - let replica_configs = []; - - let replicas = LoadBalancer::new( - &Some(primary_pool), - &replica_configs, - LoadBalancingStrategy::RoundRobin, - ReadWriteSplit::ExcludePrimary, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb() + .primary(primary_pool) + .configs(&[]) + .strategy(LoadBalancingStrategy::RoundRobin) + .rw_split(ReadWriteSplit::ExcludePrimary) + .launch(); let request = Request::default(); @@ -757,14 +753,10 @@ async fn test_read_write_split_exclude_primary_no_primary() { create_test_pool_config("127.0.0.1", 5432), ]; - let replicas = LoadBalancer::new( - &None, - &replica_configs, - LoadBalancingStrategy::Random, - ReadWriteSplit::ExcludePrimary, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb() + .configs(&replica_configs) + .rw_split(ReadWriteSplit::ExcludePrimary) + .launch(); let request = Request::default(); @@ -785,17 +777,14 @@ async fn test_read_write_split_exclude_primary_all_replicas_banned() { let primary_pool = Pool::new(&create_test_pool_config("127.0.0.1", 5432)); primary_pool.launch(); - let replicas = LoadBalancer::new( - &Some(primary_pool), - &[ + let replicas = test_lb() + .primary(primary_pool) + .configs(&[ create_test_pool_config("localhost", 5432), create_test_pool_config("127.0.0.1", 5432), - ], - LoadBalancingStrategy::Random, - ReadWriteSplit::ExcludePrimary, - Default::default(), - ); - replicas.launch(); + ]) + .rw_split(ReadWriteSplit::ExcludePrimary) + .launch(); replicas.targets[0] .ban @@ -818,17 +807,14 @@ async fn test_read_write_split_exclude_primary_one_replica_banned() { let primary_pool = Pool::new(&create_test_pool_config("127.0.0.1", 5432)); primary_pool.launch(); - let replicas = LoadBalancer::new( - &Some(primary_pool), - &[ + let replicas = test_lb() + .primary(primary_pool) + .configs(&[ create_test_pool_config("localhost", 5432), create_test_pool_config("127.0.0.1", 5432), - ], - LoadBalancingStrategy::Random, - ReadWriteSplit::ExcludePrimary, - Default::default(), - ); - replicas.launch(); + ]) + .rw_split(ReadWriteSplit::ExcludePrimary) + .launch(); replicas.targets[0] .ban @@ -852,14 +838,7 @@ async fn test_read_write_split_include_primary_no_primary() { create_test_pool_config("127.0.0.1", 5432), ]; - let replicas = LoadBalancer::new( - &None, - &replica_configs, - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb().configs(&replica_configs).launch(); let request = Request::default(); @@ -884,14 +863,10 @@ async fn test_read_write_split_with_banned_primary() { let replica_configs = [create_test_pool_config("localhost", 5432)]; - let replicas = LoadBalancer::new( - &Some(primary_pool), - &replica_configs, - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb() + .primary(primary_pool) + .configs(&replica_configs) + .launch(); // Ban the primary let primary_ban = &replicas.targets.last().unwrap().ban; @@ -925,14 +900,10 @@ async fn test_read_write_split_with_banned_replicas() { let replica_configs = [create_test_pool_config("localhost", 5432)]; - let replicas = LoadBalancer::new( - &Some(primary_pool), - &replica_configs, - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb() + .primary(primary_pool) + .configs(&replica_configs) + .launch(); // Ban the replica let replica_ban = &replicas.targets[0].ban; @@ -966,14 +937,11 @@ async fn test_prefer_primary_with_banned_replicas_falls_back_to_primary() { let replica_configs = [create_test_pool_config("localhost", 5432)]; - let replicas = LoadBalancer::new( - &Some(primary_pool), - &replica_configs, - LoadBalancingStrategy::Random, - ReadWriteSplit::PreferPrimary, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb() + .primary(primary_pool) + .configs(&replica_configs) + .rw_split(ReadWriteSplit::PreferPrimary) + .launch(); let replica_ban = &replicas.targets[0].ban; replica_ban.ban(Error::ServerError, Duration::from_millis(1000)); @@ -1005,14 +973,12 @@ async fn test_read_write_split_exclude_primary_with_round_robin() { create_test_pool_config("127.0.0.1", 5432), ]; - let replicas = LoadBalancer::new( - &Some(primary_pool), - &replica_configs, - LoadBalancingStrategy::RoundRobin, - ReadWriteSplit::ExcludePrimary, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb() + .primary(primary_pool) + .configs(&replica_configs) + .strategy(LoadBalancingStrategy::RoundRobin) + .rw_split(ReadWriteSplit::ExcludePrimary) + .launch(); let request = Request::default(); @@ -1048,16 +1014,7 @@ async fn test_read_write_split_exclude_primary_with_round_robin() { #[tokio::test] async fn test_monitor_shuts_down_immediately() { - let pool_config1 = create_test_pool_config("127.0.0.1", 5432); - let pool_config2 = create_test_pool_config("localhost", 5432); - - let replicas = LoadBalancer::new( - &None, - &[pool_config1, pool_config2], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); + let replicas = test_lb().configs(&replica_pool_configs(2)).build(); replicas .targets @@ -1111,14 +1068,7 @@ async fn test_monitor_clears_expired_bans() { async fn test_monitor_does_not_ban_single_target() { let pool_config = create_test_pool_config("127.0.0.1", 5432); - let replicas = LoadBalancer::new( - &None, - &[pool_config], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb().configs(&[pool_config]).launch(); replicas.targets[0].health().toggle(false); @@ -1180,14 +1130,7 @@ async fn test_monitor_does_not_ban_with_zero_ban_timeout() { }, }; - let replicas = LoadBalancer::new( - &None, - &[pool_config1, pool_config2], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb().configs(&[pool_config1, pool_config2]).launch(); replicas.targets[0].health().toggle(false); @@ -1237,14 +1180,11 @@ async fn test_include_primary_if_replica_banned_no_bans() { let replica_configs = [create_test_pool_config("localhost", 5432)]; - let replicas = LoadBalancer::new( - &Some(primary_pool), - &replica_configs, - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimaryIfReplicaBanned, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb() + .primary(primary_pool) + .configs(&replica_configs) + .rw_split(ReadWriteSplit::IncludePrimaryIfReplicaBanned) + .launch(); let request = Request::default(); @@ -1274,14 +1214,11 @@ async fn test_include_primary_if_replica_banned_with_ban() { let replica_configs = [create_test_pool_config("localhost", 5432)]; - let replicas = LoadBalancer::new( - &Some(primary_pool), - &replica_configs, - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimaryIfReplicaBanned, - Default::default(), - ); - replicas.launch(); + let replicas = test_lb() + .primary(primary_pool) + .configs(&replica_configs) + .rw_split(ReadWriteSplit::IncludePrimaryIfReplicaBanned) + .launch(); // Ban the replica let replica_ban = &replicas.targets[0].ban; @@ -1324,14 +1261,10 @@ async fn test_has_replicas_with_primary_and_replicas() { let replica_configs = [create_test_pool_config("localhost", 5432)]; - let lb = LoadBalancer::new( - &Some(primary_pool), - &replica_configs, - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - lb.launch(); + let lb = test_lb() + .primary(primary_pool) + .configs(&replica_configs) + .launch(); assert!(lb.has_replicas()); @@ -1344,14 +1277,7 @@ async fn test_has_replicas_primary_only() { let primary_pool = Pool::new(&primary_config); primary_pool.launch(); - let lb = LoadBalancer::new( - &Some(primary_pool), - &[], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - lb.launch(); + let lb = test_lb().primary(primary_pool).configs(&[]).launch(); assert!(!lb.has_replicas()); @@ -1360,13 +1286,7 @@ async fn test_has_replicas_primary_only() { #[tokio::test] async fn test_has_replicas_empty() { - let lb = LoadBalancer::new( - &None, - &[], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); + let lb = test_lb().configs(&[]).build(); assert!(!lb.has_replicas()); } @@ -1407,30 +1327,20 @@ async fn test_move_conns_to_with_removed_replica_matches_by_address() { // Old LB: three replica [127.0.0.1, 8.8.8.8, 1.1.1.1] // New LB: two replica [8.8.8.8, 1.1.1.1] (shifted backwards by 1; numbers changed) // After they move, verify [8.8.8.8, 1.1.1.1] maintains its connections. - let lb_old = LoadBalancer::new( - &None, - &[ + let lb_old = test_lb() + .configs(&[ create_test_pool_config_with_db_num("127.0.0.1", 5432, 1), create_test_pool_config_with_db_num("8.8.8.8", 5432, 2), create_test_pool_config_with_db_num("1.1.1.1", 5432, 3), - ], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - lb_old.launch(); + ]) + .launch(); - let lb_new = LoadBalancer::new( - &None, - &[ + let lb_new = test_lb() + .configs(&[ create_test_pool_config_with_db_num("8.8.8.8", 5432, 1), create_test_pool_config_with_db_num("1.1.1.1", 5432, 2), - ], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - lb_new.launch(); + ]) + .launch(); // Record the role on the old target [8.8.8.8]; verify it was persisted. lb_old.targets[1].set_role(Role::Primary); @@ -1459,23 +1369,13 @@ async fn test_move_conns_to_with_added_replica_matches_by_address() { let pool_config1 = create_test_pool_config("127.0.0.1", 5432); let pool_config2 = create_test_pool_config("localhost", 5432); - let lb_old = LoadBalancer::new( - &None, - std::slice::from_ref(&pool_config1), - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - lb_old.launch(); + let lb_old = test_lb() + .configs(std::slice::from_ref(&pool_config1)) + .launch(); - let lb_new = LoadBalancer::new( - &None, - &[pool_config1.clone(), pool_config2.clone()], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - lb_new.launch(); + let lb_new = test_lb() + .configs(&[pool_config1.clone(), pool_config2.clone()]) + .launch(); // Record the role on the old target so we can verify it was carried over. lb_old.targets[0].set_role(Role::Primary); @@ -1509,13 +1409,10 @@ async fn test_redetect_roles_marks_added_auto_target_replica_when_primary_unchan let existing_replica_config = create_auto_test_pool_config("localhost", 5432); let old_primary = Pool::new(&primary_config); - let lb_old = LoadBalancer::new( - &Some(old_primary), - std::slice::from_ref(&existing_replica_config), - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); + let lb_old = test_lb() + .primary(old_primary) + .configs(std::slice::from_ref(&existing_replica_config)) + .build(); set_lsn_stats(&lb_old.targets[0], true, 100); set_lsn_stats(&lb_old.targets[1], false, 200); @@ -1525,13 +1422,10 @@ async fn test_redetect_roles_marks_added_auto_target_replica_when_primary_unchan let added_replica_config = create_auto_test_pool_config("localhost", 5433); let new_primary = Pool::new(&primary_config); - let lb_new = LoadBalancer::new( - &Some(new_primary), - &[existing_replica_config, added_replica_config], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); + let lb_new = test_lb() + .primary(new_primary) + .configs(&[existing_replica_config, added_replica_config]) + .build(); lb_old.move_conns_to(&lb_new).unwrap(); @@ -1559,13 +1453,7 @@ async fn test_auto_targets_remain_replicas_when_stats_are_invalid() { let config1 = create_auto_test_pool_config("127.0.0.1", 5432); let config2 = create_auto_test_pool_config("localhost", 5432); - let lb = LoadBalancer::new( - &None, - &[config1, config2], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); + let lb = test_lb().configs(&[config1, config2]).build(); assert!( lb.targets @@ -1592,13 +1480,7 @@ async fn test_redetect_roles_marks_auto_targets_replicas_when_all_valid_targets_ let config1 = create_auto_test_pool_config("127.0.0.1", 5432); let config2 = create_auto_test_pool_config("localhost", 5432); - let lb = LoadBalancer::new( - &None, - &[config1, config2], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); + let lb = test_lb().configs(&[config1, config2]).build(); set_lsn_stats(&lb.targets[0], true, 100); set_lsn_stats(&lb.targets[1], true, 90); @@ -1628,13 +1510,7 @@ async fn test_auto_mode_waits_for_primary_election() { let mut config = create_auto_test_pool_config("127.0.0.1", 5432); config.config.checkout_timeout = Duration::from_millis(10); - let lb = LoadBalancer::new( - &None, - &[config], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); + let lb = test_lb().configs(&[config]).build(); assert!(matches!( lb.get_primary(&Request::default()).await, @@ -1645,13 +1521,7 @@ async fn test_auto_mode_waits_for_primary_election() { #[tokio::test] async fn test_auto_mode_primary_election_releases_writes() { let config = create_auto_test_pool_config("127.0.0.1", 5432); - let lb = LoadBalancer::new( - &None, - &[config], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); + let lb = test_lb().configs(&[config]).build(); lb.targets[0].pool.launch(); let election = lb.clone(); @@ -1674,13 +1544,7 @@ async fn test_auto_mode_waits_for_each_new_primary() { let first = create_auto_test_pool_config("127.0.0.1", 5432); let second = create_auto_test_pool_config("localhost", 5432); - let lb = LoadBalancer::new( - &None, - &[first, second], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); + let lb = test_lb().configs(&[first, second]).build(); lb.targets.iter().for_each(|target| target.pool.launch()); // primary is not defined initially @@ -1736,13 +1600,9 @@ async fn test_auto_mode_waits_for_each_new_primary() { #[tokio::test] async fn test_election_channel_no_race_condition() { - let lb = LoadBalancer::new( - &None, - &[create_auto_test_pool_config("127.0.0.1", 5432)], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); + let lb = test_lb() + .configs(&[create_auto_test_pool_config("127.0.0.1", 5432)]) + .build(); lb.targets[0].pool.launch(); // make sure there is no primary @@ -1764,13 +1624,7 @@ async fn test_election_channel_no_race_condition() { #[tokio::test] async fn test_static_replica_only_does_not_wait_for_primary() { let config = create_test_pool_config("127.0.0.1", 5432); - let lb = LoadBalancer::new( - &None, - &[config], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); + let lb = test_lb().configs(&[config]).build(); let started = Instant::now(); assert!(matches!( @@ -1839,19 +1693,21 @@ fn create_test_pool_config_weighted(host: &str, port: u16, lb_weight: u8) -> Poo } } +fn weighted_replica_pool_configs(weights: &[u8]) -> Vec<PoolConfig> { + ["127.0.0.1", "localhost"] + .into_iter() + .cycle() + .zip(weights) + .map(|(host, &lb_weight)| create_test_pool_config_weighted(host, 5432, lb_weight)) + .collect() +} + #[tokio::test] async fn test_weighted_round_robin_smooth_distribution() { - let pool_config1 = create_test_pool_config_weighted("127.0.0.1", 5432, 5); - let pool_config2 = create_test_pool_config_weighted("localhost", 5432, 1); - - let lb = LoadBalancer::new( - &None, - &[pool_config1, pool_config2], - LoadBalancingStrategy::WeightedRoundRobin, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - lb.launch(); + let lb = test_lb() + .configs(&weighted_replica_pool_configs(&[5, 1])) + .strategy(LoadBalancingStrategy::WeightedRoundRobin) + .launch(); let request = Request::default(); @@ -1876,17 +1732,10 @@ async fn test_weighted_round_robin_smooth_distribution() { #[tokio::test] async fn test_weighted_round_robin_equal_weights() { - let pool_config1 = create_test_pool_config_weighted("127.0.0.1", 5432, 1); - let pool_config2 = create_test_pool_config_weighted("localhost", 5432, 1); - - let lb = LoadBalancer::new( - &None, - &[pool_config1, pool_config2], - LoadBalancingStrategy::WeightedRoundRobin, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - lb.launch(); + let lb = test_lb() + .configs(&weighted_replica_pool_configs(&[1, 1])) + .strategy(LoadBalancingStrategy::WeightedRoundRobin) + .launch(); let request = Request::default(); @@ -1908,78 +1757,128 @@ async fn test_weighted_round_robin_equal_weights() { #[tokio::test] async fn test_weighted_round_robin_zero_weight_never_selected() { - let pool_config1 = create_test_pool_config_weighted("127.0.0.1", 5432, 0); - let pool_config2 = create_test_pool_config_weighted("localhost", 5432, 10); - - let lb = LoadBalancer::new( - &None, - &[pool_config1, pool_config2], - LoadBalancingStrategy::WeightedRoundRobin, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); - lb.launch(); + let lb = test_lb() + .configs(&weighted_replica_pool_configs(&[0, 10])) + .strategy(LoadBalancingStrategy::WeightedRoundRobin) + .launch(); - let request = Request::default(); + let shares = checkout_shares(&lb, 20).await; - let expected_id = lb.targets[1].pool.id(); - for _ in 0..20 { - let conn = lb.get(&request).await.unwrap(); - assert_eq!( - conn.pool.id(), - expected_id, - "Pool with weight 0 should never be selected first" - ); - } + assert_eq!( + shares, + vec![0, 20], + "Pool with weight 0 should never be selected first" + ); lb.shutdown(); } #[tokio::test] async fn test_weighted_round_robin_proportional_distribution() { - let pool_config1 = create_test_pool_config_weighted("127.0.0.1", 5432, 3); - let pool_config2 = create_test_pool_config_weighted("localhost", 5432, 1); + let lb = test_lb() + .configs(&weighted_replica_pool_configs(&[3, 1])) + .strategy(LoadBalancingStrategy::WeightedRoundRobin) + .launch(); - let lb = LoadBalancer::new( - &None, - &[pool_config1, pool_config2], - LoadBalancingStrategy::WeightedRoundRobin, - ReadWriteSplit::IncludePrimary, - Default::default(), + let shares = checkout_shares(&lb, 40).await; + + assert_eq!( + shares, + vec![30, 10], + "Pool A (weight 3) should get 3/4 of requests" ); - lb.launch(); - let request = Request::default(); + lb.shutdown(); +} - let pool_a = lb.targets[0].pool.id(); +#[tokio::test] +async fn test_round_robin_splits_banned_turns_evenly() { + let lb = test_lb() + .configs(&replica_pool_configs(4)) + .strategy(LoadBalancingStrategy::RoundRobin) + .bans(&[1, 2]) + .launch(); - // Over 40 rounds (10 full cycles of total_weight=4), A should get exactly 30 - let mut a_count = 0; - for _ in 0..40 { - let conn = lb.get(&request).await.unwrap(); - if conn.pool.id() == pool_a { - a_count += 1; - } - } + let shares = checkout_shares(&lb, 40).await; - assert_eq!(a_count, 30, "Pool A (weight 3) should get 3/4 of requests"); + assert_eq!( + shares, + vec![20, 0, 0, 20], + "banned turns must not all go to the next target in list order" + ); lb.shutdown(); } #[tokio::test] -async fn test_least_active_connections_prefers_pool_with_fewer_checked_out() { - let pool_config1 = create_test_pool_config("127.0.0.1", 5432); - let pool_config2 = create_test_pool_config("localhost", 5432); +async fn test_round_robin_splits_banned_turns_evenly_across_wrap() { + let lb = test_lb() + .configs(&replica_pool_configs(4)) + .strategy(LoadBalancingStrategy::RoundRobin) + .bans(&[2, 3]) + .launch(); + + let shares = checkout_shares(&lb, 40).await; + + assert_eq!( + shares, + vec![20, 20, 0, 0], + "banned turns at the end of the list must not all go to the first target" + ); + + lb.shutdown(); +} - let replicas = LoadBalancer::new( - &None, - &[pool_config1, pool_config2], +#[tokio::test] +async fn test_get_returns_all_replicas_down_when_all_targets_banned() { + for strategy in [ + LoadBalancingStrategy::Random, + LoadBalancingStrategy::RoundRobin, LoadBalancingStrategy::LeastActiveConnections, - ReadWriteSplit::IncludePrimary, - Default::default(), + LoadBalancingStrategy::WeightedRoundRobin, + ] { + let lb = test_lb() + .configs(&replica_pool_configs(2)) + .strategy(strategy) + .bans(&[0, 1]) + .launch(); + + let result = lb.get(&Request::default()).await; + + assert!( + matches!(result, Err(Error::AllReplicasDown)), + "{strategy:?}" + ); + + lb.shutdown(); + } +} + +#[tokio::test] +async fn test_weighted_round_robin_splits_banned_turns_by_weight() { + let lb = test_lb() + .configs(&weighted_replica_pool_configs(&[1, 1, 2])) + .strategy(LoadBalancingStrategy::WeightedRoundRobin) + .bans(&[2]) + .launch(); + + let shares = checkout_shares(&lb, 40).await; + + assert_eq!( + shares, + vec![20, 20, 0], + "a banned target's weight must not all go to one healthy target" ); - replicas.launch(); + + lb.shutdown(); +} + +#[tokio::test] +async fn test_least_active_connections_prefers_pool_with_fewer_checked_out() { + let replicas = test_lb() + .configs(&replica_pool_configs(2)) + .strategy(LoadBalancingStrategy::LeastActiveConnections) + .launch(); let request = Request::default(); @@ -2006,16 +1905,7 @@ async fn test_least_active_connections_prefers_pool_with_fewer_checked_out() { // ========================================== fn setup_test_replicas_no_launch() -> LoadBalancer { - let pool_config1 = create_test_pool_config("127.0.0.1", 5432); - let pool_config2 = create_test_pool_config("localhost", 5432); - - LoadBalancer::new( - &None, - &[pool_config1, pool_config2], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ) + test_lb().configs(&replica_pool_configs(2)).build() } #[test] @@ -2208,13 +2098,7 @@ fn test_ban_check_bans_with_pool_unhealthy_reason() { fn test_ban_check_does_not_ban_single_target() { let pool_config = create_test_pool_config("127.0.0.1", 5432); - let replicas = LoadBalancer::new( - &None, - &[pool_config], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); + let replicas = test_lb().configs(&[pool_config]).build(); // Don't launch - we're unit testing ban_check // Set target as unhealthy @@ -2270,13 +2154,7 @@ fn test_ban_check_does_not_ban_with_zero_ban_timeout() { }, }; - let replicas = LoadBalancer::new( - &None, - &[pool_config1, pool_config2], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); + let replicas = test_lb().configs(&[pool_config1, pool_config2]).build(); // Set target as unhealthy replicas.targets[0].health().toggle(false); @@ -2578,13 +2456,7 @@ async fn test_params_skips_banned_targets() { #[tokio::test] async fn test_params_returns_all_replicas_down_when_empty() { - let replicas = LoadBalancer::new( - &None, - &[], - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ); + let replicas = test_lb().configs(&[]).build(); let request = Request::default(); let result = replicas.params(&request).await; @@ -2605,13 +2477,7 @@ async fn ban_new_targets_until_health_check() { ..Default::default() }), }; - let new = LoadBalancer::new( - &None, - &[new_config], - Default::default(), - Default::default(), - Default::default(), - ); + let new = test_lb().configs(&[new_config]).build(); old.move_conns_to(&new).unwrap(); let banned_targets = new @@ -2655,20 +2521,10 @@ async fn existing_targets_not_banned_when_healthcheck_required_on_discovery() { ]; let discovered = pool_config("localhost", 2345); - let old = LoadBalancer::new( - &None, - &existing, - Default::default(), - Default::default(), - Default::default(), - ); - let new = LoadBalancer::new( - &None, - &[existing[0].clone(), existing[1].clone(), discovered], - Default::default(), - Default::default(), - Default::default(), - ); + let old = test_lb().configs(&existing).build(); + let new = test_lb() + .configs(&[existing[0].clone(), existing[1].clone(), discovered]) + .build(); old.move_conns_to(&new).unwrap(); let banned_target = new @@ -2695,19 +2551,8 @@ async fn existing_targets_not_banned_when_healthcheck_required_on_discovery() { #[tokio::test] async fn test_reload_preserves_only_manual_bans() { - let configs = [ - create_test_pool_config("127.0.0.1", 5432), - create_test_pool_config("localhost", 5432), - ]; - let new_lb = || { - LoadBalancer::new( - &None, - &configs, - Default::default(), - Default::default(), - Default::default(), - ) - }; + let configs = replica_pool_configs(2); + let new_lb = || test_lb().configs(&configs).build(); let old = new_lb(); let new = new_lb(); old.targets[0].ban.ban(Error::ManualBan, Duration::MAX); @@ -2721,19 +2566,10 @@ async fn test_reload_preserves_only_manual_bans() { #[tokio::test] async fn test_get_returns_offline_when_all_targets_banned_and_offline() { - let replicas = LoadBalancer::new( - &None, - &[ - create_test_pool_config("127.0.0.1", 5432), - create_test_pool_config("localhost", 5432), - ], - Default::default(), - Default::default(), - Default::default(), - ); - for target in &replicas.targets { - target.ban.ban(Error::ManualBan, Duration::MAX); - } + let replicas = test_lb() + .configs(&replica_pool_configs(2)) + .bans(&[0, 1]) + .build(); replicas.shutdown(); let result = replicas.get(&Request::default()).await; @@ -2751,20 +2587,8 @@ async fn initial_healthcheck_banned_targets_stay_banned_on_reload() { ..Default::default() }), }; - let new = LoadBalancer::new( - &None, - std::slice::from_ref(&new_config), - Default::default(), - Default::default(), - Default::default(), - ); - let new_new = LoadBalancer::new( - &None, - &[new_config], - Default::default(), - Default::default(), - Default::default(), - ); + let new = test_lb().configs(std::slice::from_ref(&new_config)).build(); + let new_new = test_lb().configs(&[new_config]).build(); old.move_conns_to(&new).unwrap(); assert_eq!( diff --git a/pgdog/src/backend/pool/lb/test/role_detection.rs b/pgdog/src/backend/pool/lb/test/role_detection.rs index f1346d839..c49963473 100644 --- a/pgdog/src/backend/pool/lb/test/role_detection.rs +++ b/pgdog/src/backend/pool/lb/test/role_detection.rs @@ -5,13 +5,7 @@ fn auto_pool(hosts: &[&str]) -> LoadBalancer { .iter() .map(|host| create_auto_test_pool_config(host, 5432)) .collect(); - LoadBalancer::new( - &None, - &configs, - LoadBalancingStrategy::Random, - ReadWriteSplit::IncludePrimary, - Default::default(), - ) + test_lb().configs(&configs).build() } #[test]
^ permalink raw [nested|flat] 7+ messages in thread

* Re: [pgdogdev/pgdog] PR #2077: fix(lb): bannable targets should not affect RR distribution
@ 2026-11-19 19:33 ` "codecov[bot] (bot) (@codecov[bot])" <noreply+codecov[bot]@github.com>
  5 siblings, 0 replies; 7+ messages in thread

From: codecov[bot] (bot) (@codecov[bot]) @ 2026-11-19 19:33 UTC (permalink / raw)
  To: pgdogdev/pgdog <noreply+pgdogdev-pgdog@github.com>

## [Codecov](https://app.codecov.io/gh/pgdogdev/pgdog/pull/2077?dropdown=coverage&src=pr&el=h1&utm_me...) Report
:x: Patch coverage is `99.68847%` with `1 line` in your changes missing coverage. Please review.
| [Files with missing lines](https://app.codecov.io/gh/pgdogdev/pgdog/pull/2077?dropdown=coverage&src=pr&el=tree&utm_...) | Patch % | Lines |
|---|---|---|
| [pgdog/src/backend/pool/lb/mod.rs](https://app.codecov.io/gh/pgdogdev/pgdog/pull/2077?src=pr&el=tree&utm_medium=referral&ut...) | 97.22% | [1 Missing :warning: ](https://app.codecov.io/gh/pgdogdev/pgdog/pull/2077?src=pr&el=tree&utm_medium=referral&ut...) |

:loudspeaker: Thoughts on this report? [Let us know!](https://github.com/codecov/feedback/issues/255)

^ permalink  raw  [nested|flat] 7+ messages in thread

* Re: [pgdogdev/pgdog] PR #2077 (approved): fix(lb): bannable targets should not affect RR distribution
@ 2026-11-19 19:38 ` "levkk (@levkk)" <noreply+levkk@github.com>
  5 siblings, 0 replies; 7+ messages in thread

From: levkk (@levkk) @ 2026-11-19 19:38 UTC (permalink / raw)
  To: pgdogdev/pgdog <noreply+pgdogdev-pgdog@github.com>



^ permalink  raw  [nested|flat] 7+ messages in thread

* Re: [pgdogdev/pgdog] PR #2077: fix(lb): bannable targets should not affect RR distribution
@ 2026-11-19 20:14 ` "github-actions[bot] (bot) (@github-actions[bot])" <noreply+github-actions[bot]@github.com>
  5 siblings, 0 replies; 7+ messages in thread

From: github-actions[bot] (bot) (@github-actions[bot]) @ 2026-11-19 20:14 UTC (permalink / raw)
  To: pgdogdev/pgdog <noreply+pgdogdev-pgdog@github.com>

<!-- metal-bench -->

**Metal bench (arm64) failed.** 5 of 520 measures outside bounds.

| suite | throughput | cpu/txn | user cycles/txn | user instr/txn | kernel cycles/txn | kernel instr/txn | ctx/txn |
|---|---|---|---|---|---|---|---|
| pooler |  | 19.63 (-0.7% ± 1.4%) | 19,361 (-0.4% ± 0.3%) | 31,417 (-0.1% ± 0.05%) | 31,237 (-0.8% ± 2.8%) | 51,035 (+0.2% ± 0.3%) |  |
| lb |  | 20.4 (+0.4% ± 0.9%) | 20,378 (+0.9% ± 0.6%) | **32,540 (+0.6% ± 0.03%), bound +0.5%** | 31,991 (+0.2% ± 1.9%) | 51,973 (-0.2% ± 0.4%) |  |
| sharding-w2 |  | 33.62 (+1.2% ± 1.6%) | 46,311 (+1.3% ± 2.0%) | 95,076 (+0.1% ± 0.00%) | 41,352 (+1.0% ± 2.9%) | 53,718 (-0.1% ± 0.5%) | 1.542 (-0.0% ± 0.1%) |
| sharding-w8 | 245,669 (+0.8% ± 1.0%) | 29.2 (-0.7% ± 0.8%) | 45,684 (+0.2% ± 1.5%) | 50,635 (+0.2% ± 0.01%) | 35,005 (-1.8% ± 1.5%) | 42,360 (-0.0% ± 0.2%) | 0.1673 (-0.3% ± 2.9%) |

<details><summary>Counters per txn</summary>

| suite | frontend stall | l1i refill | backend stall |
|---|---|---|---|
| pooler | 9,423 (-1.1% ± 0.8%) | 2,908 (-0.6% ± 0.5%) |  |
| lb | 10,166 (+1.1% ± 1.7%) | 3,006 (+0.1% ± 0.9%) |  |
| sharding-w2 | 20,882 (+2.4% ± 5.2%) | 4,594 (+1.8% ± 3.5%) |  |
| sharding-w8 | 21,558 (-0.6% ± 2.7%) | 4,366 (+0.4% ± 2.0%) |  |
</details>

| benchmark | measure | result | baseline | change | bound |
|---|---|---|---|---|---|
| extended_cached::cte | instructions | 24,235 | 23,959 | **+1.15% ± 0.00%** | +1% |
| full_extended_cached::aggregate | instructions | 146,231 | 144,115 | **+1.47% ± 0.00%** | +1% |
| full_simple::order_limit_offset | instructions | 195,476 | 193,049 | **+1.26% ± 0.00%** | +1% |
| simple_cold::select_omni | instructions | 20,673 | 20,461 | **+1.04% ± 0.00%** | +1% |

Microbench: 503 of 507 measures within bounds.

<details><summary>Hot code per txn</summary>

| path | base | head | change |
|---|---|---|---|
| pooler | 114.2 KB | 113.8 KB | **-0.4 KB** |
| sharding-w2 | 168.1 KB | 168.8 KB | **+0.7 KB** |

pooler:

| crate | base | head | change |
|---|---|---|---|
| pgdog::frontend::client::query_engine | 20.5 KB | 20.4 KB | -0.1 KB |
| tokio | 18.4 KB | 18.4 KB | +0.0 KB |
| pgdog::backend::pool | 17.5 KB | 17.5 KB | +0.0 KB |
| aws-lc (TLS crypto) | 10.1 KB | 10.2 KB | +0.1 KB |
| rustls (TLS) | 8.4 KB | 8.4 KB | -0.1 KB |
| pgdog::frontend (other) | 7.9 KB | 7.9 KB | -0.1 KB |
| pgdog::backend::server | 7.9 KB | 7.6 KB | -0.2 KB |
| other | 6.0 KB | 6.1 KB | +0.1 KB |
| everything else | 17.5 KB | 17.3 KB | -0.2 KB |

| function | head | change |
|---|---|---|
| `pgdog::frontend::client::Client::run::{{closure}}` | 5.6 KB | +0.0 KB |
| `pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine:` | 5.4 KB | +0.1 KB |
| `pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}}` | 4.2 KB | -0.1 KB |
| `pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine:` | 3.4 KB | -0.1 KB |
| `tokio::runtime::task::raw::poll` | 3.1 KB | -0.1 KB |

sharding-w2:

| crate | base | head | change |
|---|---|---|---|
| pgdog::frontend::router | 29.3 KB | 29.6 KB | +0.3 KB |
| pgdog::frontend::client::query_engine | 21.6 KB | 21.8 KB | +0.2 KB |
| tokio | 18.6 KB | 18.8 KB | +0.2 KB |
| pgdog::backend::pool | 18.0 KB | 18.6 KB | +0.6 KB |
| aws-lc (TLS crypto) | 12.7 KB | 12.8 KB | +0.1 KB |
| other | 10.0 KB | 9.7 KB | -0.3 KB |
| pgdog::frontend (other) | 8.9 KB | 8.9 KB | +0.0 KB |
| pgdog::backend::server | 8.1 KB | 8.2 KB | +0.1 KB |
| everything else | 41.1 KB | 40.5 KB | -0.6 KB |

| function | head | change |
|---|---|---|
| `pgdog::frontend::client::Client::run::{{closure}}` | 6.2 KB | -0.1 KB |
| `pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine:` | 5.4 KB | +0.1 KB |
| `pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}}` | 4.1 KB | +0.0 KB |
| `pgdog::frontend::router::parser::query::select::<impl pgdog::frontend::router::parser::que` | 3.9 KB | +0.0 KB |
| `pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine:` | 3.4 KB | +0.1 KB |

</details>

<details><summary>lb flamegraph vs 61e9a90b</summary>

![lb](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...) for hover, zoom and search.

![lb removed](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...).
</details>
<details><summary>microbench flamegraph vs 61e9a90b</summary>

![microbench](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...) for hover, zoom and search.

![microbench removed](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...).
</details>
<details><summary>pooler flamegraph vs 61e9a90b</summary>

![pooler](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...) for hover, zoom and search.

![pooler removed](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...).
</details>
<details><summary>sharding-w2 flamegraph vs 61e9a90b</summary>

![sharding-w2](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...) for hover, zoom and search.

![sharding-w2 removed](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...).
</details>
<details><summary>sharding-w8 flamegraph vs 61e9a90b</summary>

![sharding-w8](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...) for hover, zoom and search.

![sharding-w8 removed](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/meskill-2026-11-19-fix-lb---vpm/50078d0312c940e13...).
</details>

<details><summary>Logs</summary>

[lb](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results/meskill-2026-11-19-fix-...), [microbench](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results/meskill-2026-11-19-fix-...), [pooler](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results/meskill-2026-11-19-fix-...), [sharding-w2](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results/meskill-2026-11-19-fix-...), [sharding-w8](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results/meskill-2026-11-19-fix-...), [verdict.json](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results/meskill-2026-11-19-fix-...)
</details>

Compared 50078d03 with 61e9a90b on m8g.metal-24xl (spot).


^ permalink  raw  [nested|flat] 7+ messages in thread

* Re: [pgdogdev/pgdog] PR #2077: fix(lb): bannable targets should not affect RR distribution
@ 2026-11-19 20:17 ` "github-actions[bot] (bot) (@github-actions[bot])" <noreply+github-actions[bot]@github.com>
  5 siblings, 0 replies; 7+ messages in thread

From: github-actions[bot] (bot) (@github-actions[bot]) @ 2026-11-19 20:17 UTC (permalink / raw)
  To: pgdogdev/pgdog <noreply+pgdogdev-pgdog@github.com>

<!-- metal-bench-x86 -->

**Metal bench (x86) failed.** 6 of 520 measures outside bounds.

| suite | throughput | cpu/txn | user cycles/txn | user instr/txn | kernel cycles/txn | kernel instr/txn | ctx/txn |
|---|---|---|---|---|---|---|---|
| pooler |  | 35.11 (-0.0% ± 0.2%) | 23,756 (-0.1% ± 0.7%) | 32,749 (-0.1% ± 0.01%) | 58,100 (-0.0% ± 0.3%) | 38,515 (-0.0% ± 0.1%) |  |
| lb |  | 36.04 (+0.0% ± 0.5%) | 24,756 (-0.2% ± 0.8%) | **33,944 (+1.0% ± 0.9%), bound +0.5%** | 58,989 (+0.2% ± 0.4%) | 39,171 (-0.0% ± 0.1%) |  |
| sharding-w2 |  | 56.52 (-0.1% ± 0.5%) | 53,358 (-0.2% ± 1.5%) | 98,829 (+0.1% ± 0.07%) | 72,789 (+0.2% ± 0.7%) | 43,072 (-0.0% ± 0.1%) | 1.392 (-0.0% ± 0.04%) |
| sharding-w8 | 147,927 (-0.3% ± 2.2%) | 48.27 (+0.7% ± 0.7%) | 57,967 (+0.9% ± 2.7%) | 54,263 (+0.2% ± 0.10%) | 64,550 (+0.5% ± 1.5%) | 34,221 (+0.0% ± 0.2%) | 0.1696 (-1.0% ± 4.4%) |

<details><summary>Counters per txn</summary>

| suite | frontend stall | l1i refill | backend stall |
|---|---|---|---|
| pooler | 79,268 (-1.3% ± 0.7%) | 3,835 (-0.5% ± 0.5%) |  |
| lb | 81,498 (-1.2% ± 1.0%) | 3,963 (+0.5% ± 0.2%) |  |
| sharding-w2 | 163,672 (-1.2% ± 3.3%) | 6,229 (-0.4% ± 0.7%) |  |
| sharding-w8 | 124,873 (-1.9% ± 3.0%) | 5,088 (-0.1% ± 0.6%) |  |
</details>

| benchmark | measure | result | baseline | change | bound |
|---|---|---|---|---|---|
| extended_cached::aggregate | instructions | 17,705 | 17,437 | **+1.54% ± 0.00%** | +1% |
| extended_evicting::set | instructions | 15,325 | 15,051 | **+1.82% ± 0.00%** | +1% |
| full_named_cached::aggregate | instructions | 142,964 | 141,385 | **+1.12% ± 0.00%** | +1% |
| full_named_cached::update_by_key | instructions | 65,027 | 63,734 | **+2.03% ± 0.00%** | +1% |
| simple_cold::set | instructions | 13,664 | 13,387 | **+2.07% ± 0.00%** | +1% |

Microbench: 502 of 507 measures within bounds.

<details><summary>Microbench latency: 33 benches changed more than 3%</summary>

| benchmark | latency | baseline | change | instructions change |
|---|---|---|---|---|
| extended_evicting::begin | 2,233 ns | 2,123 ns | +5.18% ± 0.40% | +0.00% ± 0.00% |
| extended_cold::update_all_shards | 3,639 ns | 3,461 ns | +5.14% ± 0.63% | +0.00% ± 0.00% |
| simple_cold::begin | 1,955 ns | 1,861 ns | +5.05% ± 0.76% | +0.00% ± 0.00% |
| simple_cold::set | 2,523 ns | 2,404 ns | +4.97% ± 1.50% | +2.07% ± 0.00% |
| extended_cold::delete_by_key | 3,916 ns | 3,742 ns | +4.65% ± 1.24% | +0.00% ± 0.00% |
| extended_evicting::delete_by_key | 4,074 ns | 3,896 ns | +4.56% ± 0.51% | +0.00% ± 0.00% |
| extended_evicting::insert | 6,552 ns | 6,270 ns | +4.50% ± 0.38% | +0.00% ± 0.00% |
| extended_evicting::select_all_shards | 4,285 ns | 4,105 ns | +4.39% ± 1.18% | +0.00% ± 0.00% |
| extended_evicting::update_all_shards | 3,779 ns | 3,623 ns | +4.30% ± 0.92% | +0.00% ± 0.00% |
| extended_cold::select_by_key | 4,947 ns | 4,743 ns | +4.30% ± 0.50% | +0.00% ± 0.00% |
| extended_cold::set | 2,642 ns | 2,534 ns | +4.27% ± 1.29% | +0.00% ± 0.00% |
| extended_cold::begin | 2,083 ns | 1,999 ns | +4.21% ± 0.75% | +0.00% ± 0.00% |
| extended_cold::select_omni | 3,689 ns | 3,541 ns | +4.18% ± 1.14% | +0.00% ± 0.00% |
| extended_evicting::update_by_key | 4,686 ns | 4,500 ns | +4.13% ± 0.57% | +0.01% ± 0.00% |
| extended_cold::update_by_key | 4,522 ns | 4,343 ns | +4.13% ± 0.55% | +0.00% ± 0.00% |
| extended_evicting::delete_all_shards | 3,101 ns | 2,979 ns | +4.10% ± 0.58% | +0.00% ± 0.00% |
| extended_cold::distinct | 4,362 ns | 4,194 ns | +4.00% ± 0.73% | +0.00% ± 0.00% |
| extended_evicting::set | 2,792 ns | 2,685 ns | +3.98% ± 1.01% | +1.82% ± 0.00% |
| extended_evicting::select_omni | 3,895 ns | 3,749 ns | +3.90% ± 0.88% | +0.00% ± 0.00% |
| extended_cold::select_all_shards | 4,068 ns | 3,916 ns | +3.89% ± 1.16% | +0.00% ± 0.00% |
| simple_cold::update_all_shards | 3,497 ns | 3,367 ns | +3.87% ± 1.40% | +0.00% ± 0.00% |
| simple_cold::delete_all_shards | 2,807 ns | 2,707 ns | +3.69% ± 0.57% | +0.00% ± 0.00% |
| extended_cold::delete_all_shards | 2,929 ns | 2,826 ns | +3.64% ± 0.30% | +0.00% ± 0.00% |
| extended_cold::select_in_list | 5,901 ns | 5,695 ns | +3.62% ± 0.66% | +0.00% ± 0.00% |
| simple_cold::delete_by_key | 3,750 ns | 3,620 ns | +3.59% ± 0.67% | +0.00% ± 0.00% |
| extended_evicting::lookup | 5,622 ns | 5,430 ns | +3.54% ± 0.97% | +0.93% ± 0.00% |
| extended_evicting::select_by_key | 5,133 ns | 4,962 ns | +3.45% ± 1.01% | +0.00% ± 0.00% |
| extended_evicting::insert_returning | 7,386 ns | 7,140 ns | +3.45% ± 0.85% | +0.00% ± 0.00% |
| extended_evicting::distinct | 4,517 ns | 4,367 ns | +3.44% ± 0.89% | +0.00% ± 0.00% |
| extended_cold::subquery | 6,050 ns | 5,855 ns | +3.33% ± 0.46% | +0.66% ± 0.00% |
| extended_cold::insert | 6,307 ns | 6,109 ns | +3.24% ± 0.72% | +0.00% ± 0.00% |
| extended_cold::insert_returning | 7,165 ns | 6,947 ns | +3.14% ± 0.78% | +0.33% ± 0.00% |
| pooler_simple::select_1 | 7,461 ns | 7,697 ns | -3.05% ± 2.00% | -0.78% ± 0.00% |
</details>

<details><summary>Hot code per txn</summary>

| path | base | head | change |
|---|---|---|---|
| pooler | 111.9 KB | 113.5 KB | **+1.6 KB** |
| sharding-w2 | 168.5 KB | 168.2 KB | **-0.2 KB** |

pooler:

| crate | base | head | change |
|---|---|---|---|
| pgdog::frontend::client::query_engine | 21.2 KB | 22.1 KB | +0.9 KB |
| tokio | 17.4 KB | 18.0 KB | +0.6 KB |
| pgdog::backend::pool | 17.4 KB | 16.9 KB | -0.5 KB |
| pgdog::frontend (other) | 9.4 KB | 9.4 KB | +0.0 KB |
| rustls (TLS) | 7.1 KB | 7.8 KB | +0.7 KB |
| pgdog::backend::server | 7.4 KB | 7.6 KB | +0.2 KB |
| aws-lc (TLS crypto) | 6.6 KB | 7.1 KB | +0.5 KB |
| jemalloc | 7.2 KB | 6.8 KB | -0.4 KB |
| everything else | 18.1 KB | 17.8 KB | -0.3 KB |

| function | head | change |
|---|---|---|
| `pgdog::frontend::client::Client::run::{{closure}}` | 7.1 KB | +0.0 KB |
| `pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine:` | 6.4 KB | +0.1 KB |
| `pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}}` | 4.6 KB | +0.4 KB |
| `pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine:` | 3.8 KB | +0.2 KB |
| `tokio::runtime::task::raw::poll` | 3.7 KB | +0.1 KB |

sharding-w2:

| crate | base | head | change |
|---|---|---|---|
| pgdog::frontend::router | 27.8 KB | 27.1 KB | -0.8 KB |
| pgdog::frontend::client::query_engine | 23.9 KB | 23.4 KB | -0.5 KB |
| pgdog::backend::pool | 17.8 KB | 17.9 KB | +0.1 KB |
| tokio | 18.1 KB | 17.6 KB | -0.5 KB |
| other | 10.8 KB | 11.2 KB | +0.5 KB |
| jemalloc | 9.8 KB | 10.4 KB | +0.6 KB |
| aws-lc (TLS crypto) | 10.2 KB | 10.1 KB | -0.1 KB |
| pgdog::frontend (other) | 10.5 KB | 10.1 KB | -0.4 KB |
| everything else | 39.6 KB | 40.4 KB | +0.8 KB |

| function | head | change |
|---|---|---|
| `pgdog::frontend::client::Client::run::{{closure}}` | 7.6 KB | -0.2 KB |
| `pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine:` | 6.1 KB | -0.2 KB |
| `pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}}` | 4.6 KB | -0.1 KB |
| `pgdog::frontend::router::parser::query::select::<impl pgdog::frontend::router::parser::que` | 4.5 KB | +0.1 KB |
| `tokio::runtime::task::raw::poll` | 3.8 KB | -0.1 KB |

</details>

<details><summary>lb flamegraph vs 61e9a90b</summary>

![lb](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...) for hover, zoom and search.

![lb removed](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...).
</details>
<details><summary>microbench flamegraph vs 61e9a90b</summary>

![microbench](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...) for hover, zoom and search.

![microbench removed](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...).
</details>
<details><summary>pooler flamegraph vs 61e9a90b</summary>

![pooler](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...) for hover, zoom and search.

![pooler removed](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...).
</details>
<details><summary>sharding-w2 flamegraph vs 61e9a90b</summary>

![sharding-w2](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...) for hover, zoom and search.

![sharding-w2 removed](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...).
</details>
<details><summary>sharding-w8 flamegraph vs 61e9a90b</summary>

![sharding-w8](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...) for hover, zoom and search.

![sharding-w8 removed](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/meskill-2026-11-19-fix-lb---vpm/50078d0312c94...).
</details>

<details><summary>Logs</summary>

[lb](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results-x86/meskill-2026-11-19-...), [microbench](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results-x86/meskill-2026-11-19-...), [pooler](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results-x86/meskill-2026-11-19-...), [sharding-w2](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results-x86/meskill-2026-11-19-...), [sharding-w8](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results-x86/meskill-2026-11-19-...), [verdict.json](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results-x86/meskill-2026-11-19-...)
</details>

Compared 50078d03 with 61e9a90b on c7a.metal-48xl (spot).


^ permalink  raw  [nested|flat] 7+ messages in thread

* Re: [pgdogdev/pgdog] PR #2077: fix(lb): bannable targets should not affect RR distribution
@ 2026-11-19 20:54 ` "meskill (@meskill)" <noreply+meskill@github.com>
  5 siblings, 0 replies; 7+ messages in thread

From: meskill (@meskill) @ 2026-11-19 20:54 UTC (permalink / raw)
  To: pgdogdev/pgdog <noreply+pgdogdev-pgdog@github.com>

@meskill merged this (commit 5bc4e1c2d432).

^ permalink  raw  [nested|flat] 7+ messages in thread

* Re: [pgdogdev/pgdog] PR #2077: fix(lb): bannable targets should not affect RR distribution
@ 2026-11-19 20:54 ` "meskill (@meskill)" <noreply+meskill@github.com>
  5 siblings, 0 replies; 7+ messages in thread

From: meskill (@meskill) @ 2026-11-19 20:54 UTC (permalink / raw)
  To: pgdogdev/pgdog <noreply+pgdogdev-pgdog@github.com>

@meskill closed this.

^ permalink  raw  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2026-11-19 20:54 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 19:29 [pgdogdev/pgdog] PR #2077: fix(lb): bannable targets should not affect RR distribution "meskill (@meskill)" <noreply+meskill@github.com>
2026-11-19 19:33 ` "codecov[bot] (bot) (@codecov[bot])" <noreply+codecov[bot]@github.com>
2026-11-19 19:38 ` Re: [pgdogdev/pgdog] PR #2077 (approved): fix(lb): bannable targets should not affect RR distribution "levkk (@levkk)" <noreply+levkk@github.com>
2026-11-19 20:14 ` "github-actions[bot] (bot) (@github-actions[bot])" <noreply+github-actions[bot]@github.com>
2026-11-19 20:17 ` "github-actions[bot] (bot) (@github-actions[bot])" <noreply+github-actions[bot]@github.com>
2026-11-19 20:54 ` "meskill (@meskill)" <noreply+meskill@github.com>
2026-11-19 20:54 ` "meskill (@meskill)" <noreply+meskill@github.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox