web search done right
limit exponential backoff
Mikkel Denkerc9f938d434f2
diff --git a/core/src/exponential_backoff.rs b/core/src/exponential_backoff.rsindex ff98216c..04d9ea9e 100644--- a/core/src/exponential_backoff.rs+++ b/core/src/exponential_backoff.rs@@ -31,6 +31,11 @@ impl ExponentialBackoff {max_delay: None,}}++ pub fn with_limit(mut self, limit: Duration) -> Self {+ self.max_delay = Some(limit);+ self+ }}impl Iterator for ExponentialBackoff {@@ -91,4 +96,14 @@ mod tests {assert_eq!(s.next(), Some(Duration::from_millis(U64_MAX)));assert_eq!(s.next(), Some(Duration::from_millis(U64_MAX)));}++ #[test]+ fn limits_backoff() {+ let mut s = ExponentialBackoff::from_millis(10).with_limit(Duration::from_millis(100));++ assert_eq!(s.next(), Some(Duration::from_millis(10)));+ assert_eq!(s.next(), Some(Duration::from_millis(100)));+ assert_eq!(s.next(), Some(Duration::from_millis(100)));+ assert_eq!(s.next(), Some(Duration::from_millis(100)));+ }}diff --git a/core/src/mapreduce/manager.rs b/core/src/mapreduce/manager.rsindex d2f81d67..f62767de 100644--- a/core/src/mapreduce/manager.rs+++ b/core/src/mapreduce/manager.rs@@ -23,7 +23,9 @@ struct RemoteWorker {impl RemoteWorker {fn retry_strategy() -> impl Iterator<Item = Duration> {- ExponentialBackoff::from_millis(10).take(5)+ ExponentialBackoff::from_millis(10)+ .with_limit(Duration::from_secs(100))+ .take(15)}async fn connect(&self) -> Result<sonic::Connection> {diff --git a/core/src/searcher/distributed.rs b/core/src/searcher/distributed.rsindex 786d545b..01ae6857 100644--- a/core/src/searcher/distributed.rs+++ b/core/src/searcher/distributed.rs@@ -26,7 +26,11 @@ use crate::{searcher::PrettifiedWebsitesResult,};-use std::{net::SocketAddr, sync::Arc, time::Instant};+use std::{+ net::SocketAddr,+ sync::Arc,+ time::{Duration, Instant},+};use futures::stream::FuturesUnordered;use futures::StreamExt;@@ -57,7 +61,10 @@ pub enum Error {impl RemoteSearcher {async fn search(&self, query: &SearchQuery) -> Result<InitialPrettifiedSearchResult> {- for timeout in ExponentialBackoff::from_millis(30).take(5) {+ for timeout in ExponentialBackoff::from_millis(30)+ .with_limit(Duration::from_millis(200))+ .take(5)+ {if let Ok(connection) = sonic::Connection::create_with_timeout(self.addr, timeout).await{if let Ok(sonic::Response::Content(body)) = connection@@ -77,7 +84,10 @@ impl RemoteSearcher {pointers: &[inverted_index::WebsitePointer],original_query: &str,) -> Result<Vec<DisplayedWebpage>> {- for timeout in ExponentialBackoff::from_millis(30).take(5) {+ for timeout in ExponentialBackoff::from_millis(30)+ .with_limit(Duration::from_millis(200))+ .take(5)+ {if let Ok(connection) = sonic::Connection::create_with_timeout(self.addr, timeout).await{if let Ok(sonic::Response::Content(body)) = connectiondiff --git a/core/src/warc.rs b/core/src/warc.rsindex db4e4d49..c3a96ead 100644--- a/core/src/warc.rs+++ b/core/src/warc.rs@@ -96,7 +96,10 @@ impl WarcFile {warc_path: &str,buf: &mut W,) -> Result<()> {- for dur in ExponentialBackoff::from_millis(10).take(5) {+ for dur in ExponentialBackoff::from_millis(10)+ .with_limit(Duration::from_secs(100))+ .take(15)+ {let res = match source.clone() {WarcSource::HTTP(config) => {WarcFile::download_from_http(warc_path, config.base_url, buf).await