Expand description
Peer Latency Predictor
Predicts future peer latency using exponentially-weighted moving average (EWMA) and trend detection. Tracks per-peer RTT samples, computes jitter via EWMA of squared deviations, and provides conservative predicted RTT estimates.
§Features
- EWMA-based latency smoothing with configurable alpha factor
- EWMA-based variance (jitter) tracking with configurable beta factor
- Trend detection (Improving / Stable / Degrading) from rolling EWMA history
- Stale peer eviction based on configurable timeout
- Best-peer ranking by predicted RTT
§Example
use ipfrs_network::latency_predictor::{
LatencySample, PeerLatencyPredictor, PredictorConfig,
};
let config = PredictorConfig::default();
let mut predictor = PeerLatencyPredictor::new(config);
predictor.record_sample(LatencySample {
peer_id: "peer-a".to_string(),
rtt_ms: 42.0,
timestamp_secs: 1_000,
});
let predicted = predictor.predict("peer-a");
assert!(predicted.is_some());Structs§
- Latency
Sample - A single RTT measurement for a peer.
- Peer
Latency Predictor - Tracks per-peer RTT samples and provides latency predictions.
- Peer
Latency State - Per-peer latency tracking state.
- Predictor
Config - Configuration for
PeerLatencyPredictor. - Predictor
Stats - Aggregated statistics snapshot for a
PeerLatencyPredictor.
Enums§
- Trend
Direction - Direction of latency trend inferred from recent EWMA history.