Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(ingestion-consumer): remove binpack routing strategy (#117080)

Paweł Ledwońe7ac2007fb41
diff --git a/rust/ingestion-consumer/src/batcher/driver.rs b/rust/ingestion-consumer/src/batcher/driver.rs
index 860fe278e3b6..59aa61ce1b46 100644
--- a/rust/ingestion-consumer/src/batcher/driver.rs
+++ b/rust/ingestion-consumer/src/batcher/driver.rs
@@ -480,11 +480,9 @@ mod tests {
impl Harness {
fn new(workers: &[&str], max_requests_per_worker: usize) -> Self {
- let assigner = WorkerAssigner::new(
- Router::new(RoutingStrategy::BinPack),
- max_requests_per_worker,
- )
- .expect("valid request cap");
+ let assigner =
+ WorkerAssigner::new(Router::new(RoutingStrategy::P2c), max_requests_per_worker)
+ .expect("valid request cap");
let retry = RetryPolicy::new(FAULT_DELAY, BUSY_DELAY, NO_WORKER_DELAY)
.expect("valid retry policy");
let packer = Packer::new(PackTargets {
diff --git a/rust/ingestion-consumer/src/batcher/state_machine.rs b/rust/ingestion-consumer/src/batcher/state_machine.rs
index 78378ea3a90d..ca7b3764e1cd 100644
--- a/rust/ingestion-consumer/src/batcher/state_machine.rs
+++ b/rust/ingestion-consumer/src/batcher/state_machine.rs
@@ -13,7 +13,6 @@
//! for `stall_timeout`, the state machine fails, so a wedged batcher restarts
//! instead of growing lag.
-use std::cmp::Reverse;
use std::collections::HashMap;
use std::sync::Arc;
use std::time::{Duration, Instant};
@@ -442,12 +441,7 @@ impl ActiveState {
effects: &mut Effects,
) -> Result<(), String> {
let free_slots = self.assigner.free_slots(workers);
- let mut batch = self.packer.pack(&mut self.keys, now, free_slots, draining);
- if self.assigner.prefers_largest_first() {
- // Bin-packing places the heavy requests first, so they drive
- // the load distribution.
- batch.sort_by_key(|request| Reverse(request.message_count));
- }
+ let batch = self.packer.pack(&mut self.keys, now, free_slots, draining);
for request in batch {
let worker = self
.assigner
@@ -602,7 +596,7 @@ mod tests {
latency_budget: budget,
});
let assigner = WorkerAssigner::new(
- Router::new(RoutingStrategy::BinPack),
+ Router::with_seed(RoutingStrategy::P2c, 0),
max_requests_per_worker,
)
.expect("valid request cap");
@@ -735,24 +729,6 @@ mod tests {
assert_eq!(effects.next_wakeup, Some(late));
}
- #[test]
- fn bin_packing_places_the_largest_request_first() {
- let now = Instant::now();
- let workers = pool(&["w1", "w2"]);
- let batcher = packing_batcher(10, Duration::ZERO, 4, now);
-
- // Different epochs keep the two runs in separate requests.
- let (batcher, _) = batcher.on_groups(now, &pool(&[]), 0, vec![run("small", &[1])]);
- let (batcher, _) = batcher.on_groups(now, &pool(&[]), 1, vec![run("large", &[2, 3, 4])]);
- let (_, effects) = batcher.on_wakeup(now, &workers);
- let placed: Vec<_> = effects
- .sends
- .iter()
- .map(|send| (&*send.runs[0].routing_key, send.worker.as_ref()))
- .collect();
- assert_eq!(placed, vec![("large", "w1"), ("small", "w2")]);
- }
-
#[test]
fn a_request_without_a_worker_waits_and_is_sent_when_one_appears() {
let now = Instant::now();
@@ -840,7 +816,7 @@ mod tests {
#[test]
fn a_pack_budget_over_half_the_stall_timeout_is_rejected() {
let assigner =
- WorkerAssigner::new(Router::new(RoutingStrategy::BinPack), 1).expect("valid cap");
+ WorkerAssigner::new(Router::new(RoutingStrategy::P2c), 1).expect("valid cap");
let packer = Packer::new(PackTargets {
events: NonZeroUsize::new(1),
bytes: None,
@@ -854,7 +830,7 @@ mod tests {
#[test]
fn a_packer_without_a_target_is_rejected() {
let assigner =
- WorkerAssigner::new(Router::new(RoutingStrategy::BinPack), 1).expect("valid cap");
+ WorkerAssigner::new(Router::new(RoutingStrategy::P2c), 1).expect("valid cap");
let created = BatcherStateMachine::new(
Packer::new(PackTargets::default()),
assigner,
@@ -889,7 +865,7 @@ mod tests {
#[test]
fn a_zero_stall_timeout_is_rejected() {
let assigner =
- WorkerAssigner::new(Router::new(RoutingStrategy::BinPack), 1).expect("valid cap");
+ WorkerAssigner::new(Router::new(RoutingStrategy::P2c), 1).expect("valid cap");
let created = BatcherStateMachine::new(
Packer::new(PackTargets {
events: NonZeroUsize::new(1),
diff --git a/rust/ingestion-consumer/src/batcher/worker_assigner.rs b/rust/ingestion-consumer/src/batcher/worker_assigner.rs
index b78b150a6772..30a4a2a2bb0c 100644
--- a/rust/ingestion-consumer/src/batcher/worker_assigner.rs
+++ b/rust/ingestion-consumer/src/batcher/worker_assigner.rs
@@ -29,10 +29,6 @@ impl WorkerAssigner {
self.message_load.values().sum()
}
- pub fn prefers_largest_first(&self) -> bool {
- self.router.prefers_largest_first()
- }
-
pub fn free_slots(&self, pool: &[WorkerId]) -> usize {
pool.iter()
.map(|worker| self.max_requests_per_worker - self.requests_on(worker))
@@ -88,30 +84,38 @@ mod tests {
#[test]
fn a_zero_request_cap_is_rejected() {
- assert!(WorkerAssigner::new(Router::new(RoutingStrategy::BinPack), 0).is_err());
+ assert!(WorkerAssigner::new(Router::new(RoutingStrategy::P2c), 0).is_err());
}
#[test]
fn a_worker_at_the_request_cap_is_skipped_until_a_request_settles() {
let pool = vec![wid("a"), wid("b")];
- let mut assigner = WorkerAssigner::new(Router::new(RoutingStrategy::BinPack), 1).unwrap();
+ let mut assigner =
+ WorkerAssigner::new(Router::with_seed(RoutingStrategy::P2c, 0), 1).unwrap();
- assert_eq!(assigner.assign(&pool, 10), Some(wid("a")));
- assert_eq!(assigner.assign(&pool, 10), Some(wid("b")));
+ let first = assigner.assign(&pool, 10).unwrap();
+ let second = assigner.assign(&pool, 10).unwrap();
+ assert_ne!(first, second);
assert_eq!(assigner.assign(&pool, 10), None, "both at the cap");
assert_eq!(assigner.free_slots(&pool), 0);
- assert!(assigner.release(&wid("a"), 10));
- assert_eq!(assigner.assign(&pool, 10), Some(wid("a")));
+ assert!(assigner.release(&first, 10));
+ assert_eq!(assigner.assign(&pool, 10), Some(first));
}
#[test]
fn placement_follows_the_in_flight_message_load() {
let pool = vec![wid("a"), wid("b")];
- let mut assigner = WorkerAssigner::new(Router::new(RoutingStrategy::BinPack), 10).unwrap();
-
- assert_eq!(assigner.assign(&pool, 100), Some(wid("a")));
- assert_eq!(assigner.assign(&pool, 1), Some(wid("b")));
- assert_eq!(assigner.assign(&pool, 1), Some(wid("b")), "b is lighter");
+ let mut assigner =
+ WorkerAssigner::new(Router::with_seed(RoutingStrategy::P2c, 0), 10).unwrap();
+
+ let heavy = assigner.assign(&pool, 100).unwrap();
+ let light = assigner.assign(&pool, 1).unwrap();
+ assert_ne!(heavy, light);
+ assert_eq!(
+ assigner.assign(&pool, 1),
+ Some(light),
+ "the other worker is lighter"
+ );
}
}
diff --git a/rust/ingestion-consumer/src/config.rs b/rust/ingestion-consumer/src/config.rs
index 988aac3f8e76..665d1aa3b20b 100644
--- a/rust/ingestion-consumer/src/config.rs
+++ b/rust/ingestion-consumer/src/config.rs
@@ -307,10 +307,10 @@ pub struct Config {
#[envconfig(from = "WORKER_DRAIN_TIMEOUT_MS", default = "30000")]
pub worker_drain_timeout_ms: u64,
- /// How unpinned routing keys are assigned to workers: `binpack` (default,
- /// least-loaded — accurate for the co-located sidecar) or `p2c`
- /// (power-of-two-choices — herd-resistant for a shared worker pool).
- #[envconfig(from = "INGESTION_ROUTING_STRATEGY", default = "binpack")]
+ /// How unpinned routing keys are assigned to workers: `p2c` (default,
+ /// power-of-two-choices — herd-resistant for a shared worker pool) or
+ /// `aperture` (P2C within this consumer's slice of the worker ring).
+ #[envconfig(from = "INGESTION_ROUTING_STRATEGY", default = "p2c")]
pub routing_strategy: RoutingStrategy,
/// Which scheduler orders and places runs: `pin_stash` (default, sticky
diff --git a/rust/ingestion-consumer/src/debug_recorder.rs b/rust/ingestion-consumer/src/debug_recorder.rs
index 01cd23ceb4cf..f0751cdcb5d8 100644
--- a/rust/ingestion-consumer/src/debug_recorder.rs
+++ b/rust/ingestion-consumer/src/debug_recorder.rs
@@ -155,7 +155,7 @@ pub struct DispatcherLoad {
/// this reports is what the next batch would route with.
#[derive(Serialize)]
pub struct RoutingDebug {
- /// Configured strategy (`binpack`, `p2c`, `aperture`).
+ /// Configured strategy (`p2c`, `aperture`).
pub strategy: String,
/// Configured minimum aperture width; `None` when aperture is not wired.
pub min_aperture: Option<usize>,
diff --git a/rust/ingestion-consumer/src/dispatcher.rs b/rust/ingestion-consumer/src/dispatcher.rs
index 799589009ae2..5628894a2f12 100644
--- a/rust/ingestion-consumer/src/dispatcher.rs
+++ b/rust/ingestion-consumer/src/dispatcher.rs
@@ -1083,7 +1083,7 @@ mod tests {
let registry = healthy_registry(2);
let dispatcher = Dispatcher::new(registry);
- // With 2 workers, bin-packing should spread 2 fresh keys across them.
+ // With 2 workers, P2C spreads 2 fresh keys across them.
let sub_batches = dispatcher.assign("b", make_msgs(&["t:user-1", "t:user-2"]));
let total_msgs: usize = sub_batches.iter().map(|b| b.messages.len()).sum();
@@ -1201,28 +1201,14 @@ mod tests {
assert_eq!(in_flight_of(&dispatcher, &wid(0)), 3);
}
- // ---- bin-packing ----
+ // ---- load balancing ----
#[test]
- fn test_bin_packing_targets_least_loaded_worker() {
- let registry = healthy_registry(2);
- let dispatcher = Dispatcher::new(registry);
-
- // Artificially load worker 0 with 3 outstanding messages.
- dispatcher.inner.lock().unwrap().in_flight.insert(wid(0), 3);
-
- // A fresh key should go to worker 1 (load = 0).
- let b = dispatcher.assign("b", make_msgs(&["t:fresh"]));
- assert_eq!(b.len(), 1);
- assert_eq!(b[0].worker, wid(1));
- }
-
- #[test]
- fn test_bin_packing_balances_by_message_volume_not_group_count() {
+ fn test_routing_balances_by_message_volume_not_group_count() {
// Regression: load is tracked by message count, not sub-batch presence.
// One heavy key (10 msgs) plus five small keys (1 msg each) must not all
- // pile onto one worker — the small keys bin-pack onto the other worker
- // until load is balanced.
+ // pile onto one worker — the small keys go to the other worker until
+ // load is balanced.
let registry = healthy_registry(2);
let dispatcher = Dispatcher::new(registry);
@@ -1668,7 +1654,7 @@ mod tests {
let pinned = b0[0].worker.clone();
// Load the OTHER worker so the next 600-message key lands on the
- // pinned one (bin-packing places on the least-loaded worker).
+ // pinned one (with 2 workers, P2C places on the lighter one).
let b1 = dispatcher.assign("b1", make_msgs(&vec!["t:b"; 500]));
let other = b1[0].worker.clone();
assert_ne!(other, pinned);
@@ -2148,7 +2134,7 @@ mod tests {
// Flush oldest-first. batch-2 re-homes user-1 onto a survivor; batch-3 must
// land on the SAME survivor. Without the fix, batch-2's flush bumps that
- // survivor's load, so batch-3's least-loaded pick scatters to the other one.
+ // survivor's load, so batch-3's P2C pick scatters to the lighter other one.
let f2 = dispatcher.flush_deferred("batch-2");
let f3 = dispatcher.flush_deferred("batch-3");
assert_eq!(f2.len(), 1);
diff --git a/rust/ingestion-consumer/src/routing.rs b/rust/ingestion-consumer/src/routing.rs
index f07a7234a4d9..0c527102868d 100644
--- a/rust/ingestion-consumer/src/routing.rs
+++ b/rust/ingestion-consumer/src/routing.rs
@@ -19,14 +19,10 @@ use crate::worker_registry::WorkerId;
/// their existing worker regardless of strategy.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum RoutingStrategy {
- /// Largest-first bin-packing onto the least-loaded worker. Accurate when one
- /// consumer exclusively owns its workers (the co-located sidecar), because
- /// then this consumer's in-flight counts are the ground truth.
- #[default]
- BinPack,
/// Power-of-two-choices: sample two random workers, pick the lighter. Herd
/// resistant when many consumers share a worker pool, because each consumer
/// samples a different random pair instead of converging on one global best.
+ #[default]
P2c,
/// Deterministic aperture: each dispatcher routes unpinned keys only within
/// its slice of the worker ring (see [`crate::aperture`]), with P2C
@@ -42,11 +38,10 @@ impl FromStr for RoutingStrategy {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.trim().to_lowercase().as_str() {
- "binpack" | "bin_pack" | "bin-pack" => Ok(RoutingStrategy::BinPack),
"p2c" | "power_of_two" | "power-of-two" => Ok(RoutingStrategy::P2c),
"aperture" => Ok(RoutingStrategy::Aperture),
other => Err(format!(
- "unknown routing strategy '{other}' (expected 'binpack', 'p2c', or 'aperture')"
+ "unknown routing strategy '{other}' (expected 'p2c' or 'aperture')"
)),
}
}
@@ -56,7 +51,6 @@ impl RoutingStrategy {
/// Canonical config-string form, as accepted by [`FromStr`].
pub fn as_str(&self) -> &'static str {
match self {
- RoutingStrategy::BinPack => "binpack",
RoutingStrategy::P2c => "p2c",
RoutingStrategy::Aperture => "aperture",
}
@@ -101,35 +95,17 @@ impl Router {
self.strategy
}
- /// Whether the caller should present groups largest-first before selecting.
- /// Bin-packing wants the heavy hitters placed first so they drive the load
- /// distribution; P2C is per-group and order-independent.
- pub fn prefers_largest_first(&self) -> bool {
- matches!(self.strategy, RoutingStrategy::BinPack)
- }
-
/// Select a worker for one group. `healthy` lists candidate worker ids;
/// `load` is the current per-worker load (outstanding messages plus what has
/// been provisionally assigned earlier in this round). Returns `None` when
/// no workers are healthy.
pub fn select(&mut self, healthy: &[WorkerId], load: &WorkerLoad) -> Option<WorkerId> {
- match self.strategy {
- RoutingStrategy::BinPack => select_least_loaded(healthy, load),
- // Aperture narrows the candidate slice upstream (in the
- // dispatcher); within the slice it selects exactly like P2C.
- RoutingStrategy::P2c | RoutingStrategy::Aperture => {
- select_p2c(healthy, load, &mut self.rng)
- }
- }
+ // Aperture narrows the candidate slice upstream (in the dispatcher);
+ // within the slice it selects exactly like P2C.
+ select_p2c(healthy, load, &mut self.rng)
}
}
-/// Pick the least-loaded healthy worker. Ties resolve to the first such worker
-/// in `healthy`.
-fn select_least_loaded(healthy: &[WorkerId], load: &WorkerLoad) -> Option<WorkerId> {
- healthy.iter().min_by_key(|w| load_of(load, w)).cloned()
-}
-
/// Pick the lighter of two distinct random healthy workers. Degenerates to the
/// single worker when the pool has one, and to `None` when it is empty.
fn select_p2c(healthy: &[WorkerId], load: &WorkerLoad, rng: &mut impl Rng) -> Option<WorkerId> {
@@ -173,8 +149,6 @@ mod tests {
#[test]
fn test_routing_strategy_parses_known_values() {
- assert_eq!("binpack".parse(), Ok(RoutingStrategy::BinPack));
- assert_eq!("bin-pack".parse(), Ok(RoutingStrategy::BinPack));
assert_eq!("p2c".parse(), Ok(RoutingStrategy::P2c));
assert_eq!("power-of-two".parse(), Ok(RoutingStrategy::P2c));
assert_eq!("aperture".parse(), Ok(RoutingStrategy::Aperture));
@@ -183,46 +157,18 @@ mod tests {
#[test]
fn test_routing_strategy_is_case_and_whitespace_insensitive() {
assert_eq!(" P2C ".parse(), Ok(RoutingStrategy::P2c));
- assert_eq!("BinPack".parse(), Ok(RoutingStrategy::BinPack));
+ assert_eq!("Aperture".parse(), Ok(RoutingStrategy::Aperture));
}
#[test]
fn test_routing_strategy_rejects_unknown_value() {
assert!("round-robin".parse::<RoutingStrategy>().is_err());
+ assert!("binpack".parse::<RoutingStrategy>().is_err());
}
#[test]
- fn test_routing_strategy_defaults_to_binpack() {
- assert_eq!(RoutingStrategy::default(), RoutingStrategy::BinPack);
- }
-
- // ---- least-loaded ----
-
- #[test]
- fn test_least_loaded_picks_minimum_load() {
- let healthy = [wid(A), wid(B), wid(C)];
- let l = load(&[(A, 5), (B, 1), (C, 3)]);
- assert_eq!(select_least_loaded(&healthy, &l), Some(wid(B)));
- }
-
- #[test]
- fn test_least_loaded_treats_missing_as_zero() {
- let healthy = [wid(A), wid(B)];
- // B has no entry → load 0 → lighter than A.
- let l = load(&[(A, 2)]);
- assert_eq!(select_least_loaded(&healthy, &l), Some(wid(B)));
- }
-
- #[test]
- fn test_least_loaded_breaks_ties_to_first_in_slice() {
- let healthy = [wid(A), wid(B), wid(C)];
- let l = load(&[(A, 2), (B, 2), (C, 2)]);
- assert_eq!(select_least_loaded(&healthy, &l), Some(wid(A)));
- }
-
- #[test]
- fn test_least_loaded_empty_pool_returns_none() {
- assert_eq!(select_least_loaded(&[], &WorkerLoad::new()), None);
+ fn test_routing_strategy_defaults_to_p2c() {
+ assert_eq!(RoutingStrategy::default(), RoutingStrategy::P2c);
}
// ---- p2c ----
@@ -293,22 +239,4 @@ mod tests {
}
assert_eq!(seen.len(), 3, "every worker should be reachable");
}
-
- // ---- router dispatch ----
-
- #[test]
- fn test_router_binpack_selects_least_loaded() {
- let mut router = Router::new(RoutingStrategy::BinPack);
- assert!(router.prefers_largest_first());
- let healthy = [wid(A), wid(B), wid(C)];
- let l = load(&[(A, 4), (B, 1), (C, 2)]);
- assert_eq!(router.select(&healthy, &l), Some(wid(B)));
- }
-
- #[test]
- fn test_router_p2c_does_not_prefer_largest_first() {
- let router = Router::with_seed(RoutingStrategy::P2c, 1);
- assert!(!router.prefers_largest_first());
- assert_eq!(router.strategy(), RoutingStrategy::P2c);
- }
}
diff --git a/rust/ingestion-consumer/src/scheduler.rs b/rust/ingestion-consumer/src/scheduler.rs
index 5aba691dcf98..11d9eebe3c82 100644
--- a/rust/ingestion-consumer/src/scheduler.rs
+++ b/rust/ingestion-consumer/src/scheduler.rs
@@ -385,13 +385,6 @@ impl Scheduler for PinStashScheduler {
}
}
- // Route the unpinned groups via the configured strategy. Bin-packing
- // wants the biggest groups placed first so heavy hitters drive the load
- // distribution; P2C is per-group and order-independent.
- if self.router.prefers_largest_first() {
- unpinned_groups.sort_unstable_by(|a, b| b.messages.len().cmp(&a.messages.len()));
- }
-
for group in unpinned_groups {
let Some(worker) = self.router.select(&snapshot.candidates, &working_load) else {
// No routable worker right now (e.g. the whole pool is draining
@@ -705,7 +698,7 @@ mod tests {
}
fn scheduler() -> PinStashScheduler {
- PinStashScheduler::new(Router::with_seed(RoutingStrategy::BinPack, 0))
+ PinStashScheduler::new(Router::with_seed(RoutingStrategy::P2c, 0))
}
fn delivered(worker: &str, keys: &[&str], from_flush: bool) -> Settlement {
@@ -785,24 +778,6 @@ mod tests {
assert_ne!(effects.dispatches[0].worker, effects.dispatches[1].worker);
}
- #[test]
- fn test_binpack_places_largest_group_first() {
- let mut sched = scheduler();
- sched.register_batch("b1");
-
- let effects = sched.on_groups(
- &snapshot(&[A, B], &[], &[]),
- "b1",
- 0,
- vec![run("t:small", 1), run("t:big", 5)],
- );
-
- assert_eq!(
- effects.dispatches[0].routing_key, "t:big",
- "heavy hitters drive the load distribution"
- );
- }
-
#[test]
fn test_unroutable_group_is_stashed_not_dropped() {
let mut sched = scheduler();
diff --git a/rust/ingestion-consumer/tests/dispatcher_integration_test.rs b/rust/ingestion-consumer/tests/dispatcher_integration_test.rs
index c2de61391c4e..abccaac7d0f4 100644
--- a/rust/ingestion-consumer/tests/dispatcher_integration_test.rs
+++ b/rust/ingestion-consumer/tests/dispatcher_integration_test.rs
@@ -286,23 +286,22 @@ async fn test_worker_recovery_detected_by_probe() {
/// With 3 workers, one dying mid-flight:
/// - Keys pinned to the dead worker are evicted and re-routed to the survivors.
-/// - Keys pinned to the two live workers are unaffected.
/// - No new keys reach the dead worker.
#[tokio::test]
async fn test_three_workers_one_dies_and_load_rebalances() {
- let w0 = FakeWorker::start().await;
- let w1 = FakeWorker::start().await;
- let w2 = FakeWorker::start().await;
+ let workers = [
+ FakeWorker::start().await,
+ FakeWorker::start().await,
+ FakeWorker::start().await,
+ ];
- let urls = vec![w0.url.clone(), w1.url.clone(), w2.url.clone()];
+ let urls: Vec<String> = workers.iter().map(|w| w.url.clone()).collect();
let registry = Arc::new(WorkerRegistry::new(&urls, fast_config()));
let dispatcher = Dispatcher::new(Arc::clone(&registry));
let token = CancellationToken::new();
Arc::clone(&registry).start_probing(token.clone());
- // 3 distinct keys of equal size: bin-packing spreads exactly one key per
- // worker (provisional load increases by 1 for each pick, breaking all ties).
let first = dispatcher.assign(
"b",
vec![
@@ -311,30 +310,20 @@ async fn test_three_workers_one_dies_and_load_rebalances() {
make_msg("t:key-c"),
],
);
- assert_eq!(
- first.len(),
- 3,
- "3 keys across 3 workers must yield 3 sub-batches"
- );
- let workers_covered: std::collections::HashSet<String> =
- first.iter().map(|b| b.worker.to_string()).collect();
- assert_eq!(workers_covered.len(), 3, "all 3 workers must receive a pin");
- // Remember which routing key was pinned to w1 — we'll re-assign it later
- // to verify it migrates to a live worker.
- let w1_key = first
+ // Kill the worker that holds the first sub-batch and wait for dead
+ // declaration (first batch stays open throughout).
+ let dead_sub = &first[0];
+ let dead = workers
.iter()
- .find(|b| b.worker.as_ref() == w1.url)
- .unwrap()
- .routing_keys[0]
- .clone();
-
- // Kill w1 and wait for dead declaration (first batch stays open throughout).
- w1.set_healthy(false);
- wait_for_state(&registry, &w1.url, WorkerState::Unhealthy).await;
- wait_for_dead(&registry, &w1.url).await;
-
- // Fresh keys must only land on w0 or w2.
+ .find(|w| w.url == dead_sub.worker.as_ref())
+ .unwrap();
+ let dead_key = dead_sub.routing_keys[0].clone();
+ dead.set_healthy(false);
+ wait_for_state(&registry, &dead.url, WorkerState::Unhealthy).await;
+ wait_for_dead(&registry, &dead.url).await;
+
+ // Fresh keys must only land on the survivors.
let fresh = dispatcher.assign(
"b",
vec![
@@ -344,27 +333,27 @@ async fn test_three_workers_one_dies_and_load_rebalances() {
],
);
assert!(
- fresh.iter().all(|b| b.worker.as_ref() != w1.url),
- "fresh keys must not route to dead w1; workers used: {:?}",
+ fresh.iter().all(|b| b.worker.as_ref() != dead.url),
+ "fresh keys must not route to the dead worker; workers used: {:?}",
fresh
.iter()
.map(|b| b.worker.to_string())
.collect::<Vec<_>>()
);
- // Resolve w1's in-flight sub-batch (max_in_flight=1: the prior batch
- // completes before the next assigns), evicting its now zero-ref pin.
- let w1_sub = first.iter().find(|b| b.worker.as_ref() == w1.url).unwrap();
+ // Resolve the dead worker's in-flight sub-batch (max_in_flight=1: the
+ // prior batch completes before the next assigns), evicting its now
+ // zero-ref pins.
dispatcher.on_sub_batch_resolved(
- &w1_sub.worker,
- w1_sub.messages.len(),
- &w1_sub.routing_keys,
+ &dead_sub.worker,
+ dead_sub.messages.len(),
+ &dead_sub.routing_keys,
false,
false,
);
- // The key that was pinned to w1 must re-route to w0 or w2 on its next assign.
- let rerouted = dispatcher.assign("b", vec![make_msg(&w1_key)]);
+ // The key that was pinned to the dead worker must re-route to a survivor.
+ let rerouted = dispatcher.assign("b", vec![make_msg(&dead_key)]);
assert_eq!(
rerouted.len(),
1,
@@ -372,8 +361,8 @@ async fn test_three_workers_one_dies_and_load_rebalances() {
);
assert_ne!(
rerouted[0].worker.as_ref(),
- w1.url,
- "key previously pinned to w1 must reroute to a live worker, not w1"
+ dead.url,
+ "key previously pinned to the dead worker must reroute to a live worker"
);
token.cancel();
@@ -478,10 +467,7 @@ async fn test_draining_worker_defers_then_flushes_to_survivor() {
#[tokio::test(flavor = "current_thread")]
async fn purging_a_just_submitted_key_table_batch_is_not_fatal() {
let registry = Arc::new(WorkerRegistry::new(&[], fast_config()));
- let dispatcher = Arc::new(Dispatcher::with_strategy(
- registry,
- RoutingStrategy::BinPack,
- ));
+ let dispatcher = Arc::new(Dispatcher::with_strategy(registry, RoutingStrategy::P2c));
let transport = Arc::new(GrpcTransport::new(
GrpcPort::OffsetFromHttp(0),
1,
@@ -511,10 +497,7 @@ async fn purging_a_just_submitted_key_table_batch_is_not_fatal() {
#[tokio::test]
async fn dropping_an_idle_key_table_batcher_closes_its_outputs() {
let registry = Arc::new(WorkerRegistry::new(&[], fast_config()));
- let dispatcher = Arc::new(Dispatcher::with_strategy(
- registry,
- RoutingStrategy::BinPack,
- ));
+ let dispatcher = Arc::new(Dispatcher::with_strategy(registry, RoutingStrategy::P2c));
let transport = Arc::new(GrpcTransport::new(
GrpcPort::OffsetFromHttp(0),
1,
diff --git a/rust/ingestion-consumer/tests/e2e_integration_test.rs b/rust/ingestion-consumer/tests/e2e_integration_test.rs
index 60b567fd2f3b..6e2bacb0bed5 100644
--- a/rust/ingestion-consumer/tests/e2e_integration_test.rs
+++ b/rust/ingestion-consumer/tests/e2e_integration_test.rs
@@ -1424,7 +1424,7 @@ async fn partial_send_failure_replays_only_the_failed_subbatch(#[case] kind: Sch
guards.push(Some(w.block().await));
}
- // Two equal-size keys → bin-packed one per worker: one batch, two
+ // Two keys over two workers → P2C places one per worker: one batch, two
// sub-batches, one per worker. The keys must share one Kafka batch: at
// max_in_flight=1 a Kafka batch with only one key blocks the next batch,
// so the second worker would never receive a sub-batch.
@@ -2538,7 +2538,7 @@ async fn full_pool_send_failure_with_multiple_keys_recovers_in_order(
produce(&producer, &topic, 1, "tok", "user-2", seq).await;
}
// One message per request splits the keys into two requests, and
- // bin-packing places them one per worker. At the production target
+ // P2C places them one per worker. At the production target
// both keys fit in one request.
let split = pack_targets == common::ONE_MESSAGE_PER_REQUEST;
wait_until(Duration::from_secs(10), "work to be in flight", || {
diff --git a/rust/ingestion-consumer/tests/grpc_transport_test.rs b/rust/ingestion-consumer/tests/grpc_transport_test.rs
index 84e0318d7825..904eb731450c 100644
--- a/rust/ingestion-consumer/tests/grpc_transport_test.rs
+++ b/rust/ingestion-consumer/tests/grpc_transport_test.rs
@@ -902,10 +902,7 @@ async fn key_table_watchdog_bounds_overlapping_busy_retries() {
format!("http://{second_addr}"),
];
let registry = Arc::new(WorkerRegistry::new(&worker_urls, registry_config()));
- let dispatcher = Arc::new(Dispatcher::with_strategy(
- registry,
- RoutingStrategy::BinPack,
- ));
+ let dispatcher = Arc::new(Dispatcher::with_strategy(registry, RoutingStrategy::P2c));
let transport = Arc::new(GrpcTransport::new(
GrpcPort::OffsetFromHttp(0),
1,
@@ -989,10 +986,7 @@ async fn key_table_retries_a_busy_send_until_it_completes() {
let addr = start_controlled_busy_worker(0, attempts_tx).await;
let worker_urls = vec![format!("http://{addr}")];
let registry = Arc::new(WorkerRegistry::new(&worker_urls, registry_config()));
- let dispatcher = Arc::new(Dispatcher::with_strategy(
- registry,
- RoutingStrategy::BinPack,
- ));
+ let dispatcher = Arc::new(Dispatcher::with_strategy(registry, RoutingStrategy::P2c));
let transport = Arc::new(GrpcTransport::new(
GrpcPort::OffsetFromHttp(0),
1,
@@ -1038,10 +1032,7 @@ async fn key_table_watchdog_allows_in_flight_success_after_the_deadline() {
let addr = start_controlled_busy_worker(0, attempts_tx).await;
let worker_urls = vec![format!("http://{addr}")];
let registry = Arc::new(WorkerRegistry::new(&worker_urls, registry_config()));
- let dispatcher = Arc::new(Dispatcher::with_strategy(
- registry,
- RoutingStrategy::BinPack,
- ));
+ let dispatcher = Arc::new(Dispatcher::with_strategy(registry, RoutingStrategy::P2c));
let transport = Arc::new(GrpcTransport::new(
GrpcPort::OffsetFromHttp(0),
1,