@@ -333,6 +333,19 @@ struct BackpressureConfig {
333
333
}
334
334
335
335
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
+
336
349
fn get_backpressure_us ( & self , bytes : u64 , jobs : u64 ) -> u64 {
337
350
// Saturate at 1 hour per job, which is basically infinite
338
351
if bytes >= self . bytes_max || jobs >= self . queue_max {
@@ -347,16 +360,10 @@ impl BackpressureConfig {
347
360
/ ( self . bytes_max - self . bytes_start ) as f64 ;
348
361
349
362
// 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 ;
360
367
361
368
delay_bytes. max ( delay_jobs)
362
369
}
@@ -424,7 +431,7 @@ impl Guest {
424
431
// Byte-based backpressure
425
432
bytes_start : 50 * 1024u64 . pow ( 2 ) , // 50 MiB
426
433
bytes_max : IO_OUTSTANDING_MAX_BYTES * 2 ,
427
- bytes_scale : Duration :: from_millis ( 25 ) ,
434
+ bytes_scale : Duration :: from_millis ( 100 ) ,
428
435
429
436
// Queue-based backpressure
430
437
queue_start : 500 ,
@@ -1509,9 +1516,9 @@ mod test {
1509
1516
humantime:: format_duration( timeout)
1510
1517
) ;
1511
1518
assert ! (
1512
- timeout < Duration :: from_secs( 120 ) ,
1519
+ timeout < Duration :: from_secs( 180 ) ,
1513
1520
"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 {}",
1515
1522
humantime:: format_duration( timeout)
1516
1523
) ;
1517
1524
0 commit comments