Skip to content

Commit 77faa50

Browse files
committed
Tweak backpressure curve to match master
1 parent 9760bad commit 77faa50

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

upstairs/src/guest.rs

+20-13
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,19 @@ struct BackpressureConfig {
333333
}
334334

335335
impl BackpressureConfig {
336+
// Our chosen backpressure curve is quadratic for 1/2 of its range, then
337+
// goes to infinity in the second half. This gives C0 + C1 continuity.
338+
fn curve(frac: f64, scale: Duration) -> Duration {
339+
// Remap from 0-1 to 0-1.5 for ease of calculation
340+
let frac = frac * 2.0;
341+
let v = if frac < 1.0 {
342+
frac
343+
} else {
344+
1.0 / (1.0 - (frac - 1.0))
345+
};
346+
scale.mul_f64(v.powi(2))
347+
}
348+
336349
fn get_backpressure_us(&self, bytes: u64, jobs: u64) -> u64 {
337350
// Saturate at 1 hour per job, which is basically infinite
338351
if bytes >= self.bytes_max || jobs >= self.queue_max {
@@ -347,16 +360,10 @@ impl BackpressureConfig {
347360
/ (self.bytes_max - self.bytes_start) as f64;
348361

349362
// Delay should be 0 at frac = 0, and infinite at frac = 1
350-
let delay_bytes = self
351-
.bytes_scale
352-
.mul_f64(1.0 / (1.0 - bytes_frac).powi(2) - 1.0)
353-
.as_micros() as u64;
354-
355-
// Compute an alternate delay based on queue length
356-
let delay_jobs = self
357-
.queue_scale
358-
.mul_f64(1.0 / (1.0 - jobs_frac).powi(2) - 1.0)
359-
.as_micros() as u64;
363+
let delay_bytes =
364+
Self::curve(bytes_frac, self.bytes_scale).as_micros() as u64;
365+
let delay_jobs =
366+
Self::curve(jobs_frac, self.queue_scale).as_micros() as u64;
360367

361368
delay_bytes.max(delay_jobs)
362369
}
@@ -424,7 +431,7 @@ impl Guest {
424431
// Byte-based backpressure
425432
bytes_start: 50 * 1024u64.pow(2), // 50 MiB
426433
bytes_max: IO_OUTSTANDING_MAX_BYTES * 2,
427-
bytes_scale: Duration::from_millis(25),
434+
bytes_scale: Duration::from_millis(100),
428435

429436
// Queue-based backpressure
430437
queue_start: 500,
@@ -1509,9 +1516,9 @@ mod test {
15091516
humantime::format_duration(timeout)
15101517
);
15111518
assert!(
1512-
timeout < Duration::from_secs(120),
1519+
timeout < Duration::from_secs(180),
15131520
"offline -> faulted transition happens too slowly \
1514-
with job size {job_size}; expected < 2 mins, got {}",
1521+
with job size {job_size}; expected < 3 mins, got {}",
15151522
humantime::format_duration(timeout)
15161523
);
15171524

0 commit comments

Comments
 (0)