Skip to content

Commit c854037

Browse files
committed
More doc comments on algorithm
1 parent ffb2dc0 commit c854037

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

core/src/pollers/poll_buffer.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,12 @@ where
420420
}
421421
}
422422

423+
/// The PollScaler is responsible for managing the number of pollers based on the current load.
424+
///
425+
/// It does so by receiving suggestions from the server about whether to scale up or down. It will
426+
/// always respect scale down decisions (until the number of pollers reaches the minimum), but may
427+
/// choose to ignore scale up decisions if it appears that adding more pollers is not contributing
428+
/// to increased task throughput. See more detailed comments in the implementation.
423429
struct PollScaler<F> {
424430
report_handle: Arc<PollScalerReportHandle>,
425431
active_tx: watch::Sender<usize>,
@@ -459,6 +465,12 @@ where
459465
});
460466
let rhc = report_handle.clone();
461467
let ingestor_task = if behavior.is_autoscaling() {
468+
// Here we spawn a task to periodically check if we should permit increasing the
469+
// poller count further. We do this by comparing the number of ingested items in the
470+
// current period with the number of ingested items in the previous period. If we
471+
// are successfully ingesting more items, then it makes sense to allow scaling up.
472+
// If we aren't, then we're probably limited by how fast we can process the tasks
473+
// and it's not worth increasing the poller count further.
462474
Some(tokio::task::spawn(async move {
463475
let mut interval = tokio::time::interval(Duration::from_millis(100));
464476
loop {
@@ -558,9 +570,6 @@ impl PollScalerReportHandle {
558570
// We should only see (and react to) errors in autoscaling mode
559571
if matches!(self.behavior, PollerBehavior::Autoscaling { .. }) {
560572
debug!("Got error from server while polling: {:?}", e);
561-
// TODO (REVIEW): A concern here is we can bounce off of ratelimiter
562-
// because server keeps telling us "scale up!" and then we hit ratelimit
563-
// and halve again. Not necessarily a huge issue, but open to ideas to fix.
564573
if e.code() == Code::ResourceExhausted {
565574
// Scale down significantly for resource exhaustion
566575
self.change_target(usize::saturating_div, 2);

0 commit comments

Comments
 (0)