Skip to content

Commit

Permalink
Shuffe DNS NameServers to avoid overloads to the first configured ones.
Browse files Browse the repository at this point in the history
Signed-off-by: Edu4rdSHL <[email protected]>
  • Loading branch information
Edu4rdSHL committed Feb 13, 2022
1 parent 521f2ab commit ff8e121
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/resolver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ lazy_static = "1.0"
log = "0.4"
lru-cache = "0.1.2"
parking_lot = "0.11"
rand = "0.8.4"
resolv-conf = { version = "0.7.0", optional = true, features = ["system"] }
rustls = {version = "0.19", optional = true}
serde = { version = "1.0", features = ["derive"], optional = true }
Expand Down
4 changes: 4 additions & 0 deletions crates/resolver/src/name_server/name_server_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::time::Duration;

use futures_util::stream::{FuturesUnordered, StreamExt};
use futures_util::{future::Future, future::FutureExt};
use rand::{seq::SliceRandom, thread_rng as rng};
use smallvec::SmallVec;

use proto::xfer::{DnsHandle, DnsRequest, DnsResponse};
Expand Down Expand Up @@ -304,6 +305,9 @@ where
loop {
let request_cont = request.clone();

// Shuffe DNS NameServers to avoid overloads to the first configured ones
conns.shuffle(&mut rng());

// construct the parallel requests, 2 is the default
let mut par_conns = SmallVec::<[NameServer<C, P>; 2]>::new();
let count = conns.len().min(opts.num_concurrent_reqs.max(1));
Expand Down

0 comments on commit ff8e121

Please sign in to comment.