Skip to content

Commit 6a9b348

Browse files
committed
When first request fails, try alternative peers in staggered parallel.
1 parent 9a4c985 commit 6a9b348

File tree

5 files changed

+422
-61
lines changed

5 files changed

+422
-61
lines changed

linera-client/src/client_options.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ pub struct ClientContextOptions {
230230
env = "LINERA_REQUESTS_SCHEDULER_ALPHA"
231231
)]
232232
pub alpha: f64,
233+
234+
/// Delay in milliseconds between starting requests to different peers.
235+
/// This helps to stagger requests and avoid overwhelming the network.
236+
#[arg(
237+
long,
238+
default_value_t = linera_core::client::requests_scheduler::STAGGERED_DELAY_MS,
239+
env = "LINERA_REQUESTS_SCHEDULER_ALTERNATIVE_PEERS_RETRY_DELAY_MS"
240+
)]
241+
pub alternative_peers_retry_delay_ms: u64,
233242
}
234243

235244
impl ClientContextOptions {
@@ -273,6 +282,7 @@ impl ClientContextOptions {
273282
cache_max_size: self.cache_max_size,
274283
max_request_ttl_ms: self.max_request_ttl_ms,
275284
alpha: self.alpha,
285+
retry_delay_ms: self.alternative_peers_retry_delay_ms,
276286
}
277287
}
278288
}

linera-core/src/client/requests_scheduler/in_flight_tracker.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ impl<N: Clone> InFlightTracker<N> {
173173
let peers = entry.alternative_peers.read().await;
174174
Some(peers.clone())
175175
}
176+
177+
/// Removes a specific peer from the alternative peers list.
178+
///
179+
/// # Arguments
180+
/// - `key`: The request key to look up
181+
/// - `peer`: The peer to remove from alternatives
182+
pub(super) async fn remove_alternative_peer(&self, key: &RequestKey, peer: &N)
183+
where
184+
N: PartialEq + Eq,
185+
{
186+
if let Some(entry) = self.entries.read().await.get(key) {
187+
let mut alt_peers = entry.alternative_peers.write().await;
188+
alt_peers.retain(|p| p != peer);
189+
}
190+
}
176191
}
177192

178193
/// Type of in-flight request match found.

linera-core/src/client/requests_scheduler/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub const CACHE_TTL_MS: u64 = 2000;
2121
pub const CACHE_MAX_SIZE: usize = 1000;
2222
pub const MAX_REQUEST_TTL_MS: u64 = 200;
2323
pub const ALPHA_SMOOTHING_FACTOR: f64 = 0.1;
24+
pub const STAGGERED_DELAY_MS: u64 = 75;
2425

2526
/// Configuration for the `RequestsScheduler`.
2627
#[derive(Debug, Clone)]
@@ -35,6 +36,8 @@ pub struct RequestsSchedulerConfig {
3536
pub max_request_ttl_ms: u64,
3637
/// Smoothing factor for Exponential Moving Averages (0 < alpha < 1)
3738
pub alpha: f64,
39+
/// Delay in milliseconds between starting requests to different peers.
40+
pub retry_delay_ms: u64,
3841
}
3942

4043
impl Default for RequestsSchedulerConfig {
@@ -45,6 +48,7 @@ impl Default for RequestsSchedulerConfig {
4548
cache_max_size: CACHE_MAX_SIZE,
4649
max_request_ttl_ms: MAX_REQUEST_TTL_MS,
4750
alpha: ALPHA_SMOOTHING_FACTOR,
51+
retry_delay_ms: STAGGERED_DELAY_MS,
4852
}
4953
}
5054
}

0 commit comments

Comments
 (0)