pub struct TailCutLayerBuilder { /* private fields */ }Expand description
Builder for TailCutLayer.
Use this to configure the layer, then call build() to create a layer
that can be cloned and shared across multiple operators.
§Examples
use opendal::layers::TailCutLayer;
use std::time::Duration;
let layer = TailCutLayer::builder()
.percentile(95)
.window(Duration::from_secs(60))
.build();
let op = Operator::new(services::Memory::default())?
.layer(layer)
.finish();Implementations§
Source§impl TailCutLayerBuilder
impl TailCutLayerBuilder
Sourcepub fn percentile(self, percentile: u8) -> Self
pub fn percentile(self, percentile: u8) -> Self
Set the percentile threshold (e.g., 95 for P95, 99 for P99).
Requests slower than this percentile × safety_factor will be cancelled.
Default: 95
§Panics
Panics if percentile is not between 50 and 99.
Sourcepub fn safety_factor(self, factor: f64) -> Self
pub fn safety_factor(self, factor: f64) -> Self
Set the safety factor multiplier.
The actual deadline is calculated as: P{percentile} × safety_factor. A higher value reduces false positives but may miss some long tails.
Default: 1.3 (30% buffer)
§Panics
Panics if factor is not between 1.0 and 5.0.
Sourcepub fn window(self, window: Duration) -> Self
pub fn window(self, window: Duration) -> Self
Set the sliding window duration for statistics collection.
Longer windows provide more stable statistics but react slower to changes. Shorter windows adapt faster but may be more noisy.
Default: 60 seconds
§Panics
Panics if window is greater than 120 seconds.
Sourcepub fn min_samples(self, min_samples: usize) -> Self
pub fn min_samples(self, min_samples: usize) -> Self
Set the minimum number of samples required before enabling adaptive cancellation.
During cold start (when sample count < min_samples), the layer will not cancel any requests to avoid false positives.
Default: 200
Sourcepub fn min_deadline(self, deadline: Duration) -> Self
pub fn min_deadline(self, deadline: Duration) -> Self
Set the minimum deadline (floor).
Even if calculated deadline is shorter, it will be clamped to this value. This prevents overly aggressive cancellation on very fast backends.
Default: 500ms
Sourcepub fn max_deadline(self, deadline: Duration) -> Self
pub fn max_deadline(self, deadline: Duration) -> Self
Set the maximum deadline (ceiling).
Even if calculated deadline is longer, it will be clamped to this value. This acts as a safety fallback timeout.
Default: 30s
Sourcepub fn build(self) -> TailCutLayer
pub fn build(self) -> TailCutLayer
Build the layer.
The returned layer can be cloned to share statistics across operators.
§Examples
use opendal::layers::TailCutLayer;
use std::time::Duration;
let layer = TailCutLayer::builder()
.percentile(95)
.window(Duration::from_secs(60))
.build();
// Share the layer across operators
let op1 = Operator::new(services::Memory::default())?
.layer(layer.clone())
.finish();
let op2 = Operator::new(services::Memory::default())?
.layer(layer.clone())
.finish();
// op1 and op2 share the same statisticsTrait Implementations§
Source§impl Clone for TailCutLayerBuilder
impl Clone for TailCutLayerBuilder
Source§fn clone(&self) -> TailCutLayerBuilder
fn clone(&self) -> TailCutLayerBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more