feat(client): DNS worker count is configurable
When loading up a client suddenly with thousands of connections, the default DNS worker count of four cannot keep up and many requests timeout as a result. Most people don't need a large pool, so making this configurable is a natural choice.
This commit is contained in:
@@ -24,6 +24,9 @@ pub trait Connect {
|
||||
/// Returns a connected socket and associated host.
|
||||
fn connected(&mut self) -> Option<(Self::Key, io::Result<Self::Output>)>;
|
||||
#[doc(hidden)]
|
||||
/// Configure number of dns workers to use.
|
||||
fn dns_workers(&mut self, usize);
|
||||
#[doc(hidden)]
|
||||
fn register(&mut self, Registration);
|
||||
}
|
||||
|
||||
@@ -71,6 +74,10 @@ impl Connect for HttpConnector {
|
||||
type Output = HttpStream;
|
||||
type Key = (&'static str, String, u16);
|
||||
|
||||
fn dns_workers(&mut self, count: usize) {
|
||||
self.threads = count;
|
||||
}
|
||||
|
||||
fn key(&self, url: &Url) -> Option<Self::Key> {
|
||||
if url.scheme() == "http" {
|
||||
Some((
|
||||
@@ -119,7 +126,7 @@ impl Connect for HttpConnector {
|
||||
}
|
||||
|
||||
fn register(&mut self, reg: Registration) {
|
||||
self.dns = Some(Dns::new(reg.notify, 4));
|
||||
self.dns = Some(Dns::new(reg.notify, self.threads));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +151,10 @@ impl<S: SslClient> Connect for HttpsConnector<S> {
|
||||
type Output = HttpsStream<S::Stream>;
|
||||
type Key = (&'static str, String, u16);
|
||||
|
||||
fn dns_workers(&mut self, count: usize) {
|
||||
self.http.dns_workers(count)
|
||||
}
|
||||
|
||||
fn key(&self, url: &Url) -> Option<Self::Key> {
|
||||
let scheme = match url.scheme() {
|
||||
"http" => "http",
|
||||
|
||||
Reference in New Issue
Block a user