Skip to content

Commit

Permalink
🏓 Ping balancer: treat ping timeouts as failures
Browse files Browse the repository at this point in the history
- Treat timeouts as failures, so requests that receive no response count as failures.
- Increase check timeout from 2s to 5s to avoid penalties on slow servers.
- Increase check interval from 6s to 10s.
  • Loading branch information
database64128 authored and zonyitoo committed Jan 22, 2021
1 parent 3094ec6 commit c2adae9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ impl PingChecker {
Err(err)
}
Err(..) => {
use std::io::{Error, ErrorKind};

// Timeout
trace!(
"checked remote {} server {} latency timeout, elapsed {} ms",
Expand All @@ -488,8 +490,9 @@ impl PingChecker {
elapsed
);

// NOTE: timeout is still available, but server is too slow
Ok(elapsed)
// NOTE: timeout exceeded. Count as error.
let err = Error::new(ErrorKind::TimedOut, "Request timed out");
Err(err)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
use std::collections::VecDeque;

/// Interval of active probing
pub const DEFAULT_CHECK_INTERVAL_SEC: u64 = 6;
/// Timeout of each probing
pub const DEFAULT_CHECK_TIMEOUT_SEC: u64 = 2; // Latency shouldn't greater than 2 secs, that's too long
/// Interval between each check
pub const DEFAULT_CHECK_INTERVAL_SEC: u64 = 10;
/// Timeout of each check
pub const DEFAULT_CHECK_TIMEOUT_SEC: u64 = 5; // A common connection timeout of 5 seconds.

const MAX_SERVER_RTT: u32 = DEFAULT_CHECK_TIMEOUT_SEC as u32 * 1000;
const MAX_LATENCY_QUEUE_SIZE: usize = 99;
const MAX_LATENCY_QUEUE_SIZE: usize = 59; // Account for the last 10 minutes.

/// Statistic score
#[derive(Debug, Copy, Clone)]
Expand Down

0 comments on commit c2adae9

Please sign in to comment.