Skip to content

Commit 0fad665

Browse files
authored
Merge pull request #922 from jwilm/configurable-dns-worker-count
feat(client): DNS worker count is configurable
2 parents 37daf1a + 138e164 commit 0fad665

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/client/connect.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ pub trait Connect {
2424
/// Returns a connected socket and associated host.
2525
fn connected(&mut self) -> Option<(Self::Key, io::Result<Self::Output>)>;
2626
#[doc(hidden)]
27+
/// Configure number of dns workers to use.
28+
fn dns_workers(&mut self, usize);
29+
#[doc(hidden)]
2730
fn register(&mut self, Registration);
2831
}
2932

@@ -71,6 +74,10 @@ impl Connect for HttpConnector {
7174
type Output = HttpStream;
7275
type Key = (&'static str, String, u16);
7376

77+
fn dns_workers(&mut self, count: usize) {
78+
self.threads = count;
79+
}
80+
7481
fn key(&self, url: &Url) -> Option<Self::Key> {
7582
if url.scheme() == "http" {
7683
Some((
@@ -119,7 +126,7 @@ impl Connect for HttpConnector {
119126
}
120127

121128
fn register(&mut self, reg: Registration) {
122-
self.dns = Some(Dns::new(reg.notify, 4));
129+
self.dns = Some(Dns::new(reg.notify, self.threads));
123130
}
124131
}
125132

@@ -144,6 +151,10 @@ impl<S: SslClient> Connect for HttpsConnector<S> {
144151
type Output = HttpsStream<S::Stream>;
145152
type Key = (&'static str, String, u16);
146153

154+
fn dns_workers(&mut self, count: usize) {
155+
self.http.dns_workers(count)
156+
}
157+
147158
fn key(&self, url: &Url) -> Option<Self::Key> {
148159
let scheme = match url.scheme() {
149160
"http" => "http",

src/client/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ impl<H: Send> Client<H> {
8787
let mut loop_ = try!(rotor::Loop::new(&rotor_config));
8888
let mut notifier = None;
8989
let mut connector = config.connector;
90+
connector.dns_workers(config.dns_workers);
9091
{
9192
let not = &mut notifier;
9293
loop_.add_machine_with(move |scope| {
@@ -150,6 +151,7 @@ pub struct Config<C> {
150151
//TODO: make use of max_idle config
151152
max_idle: usize,
152153
max_sockets: usize,
154+
dns_workers: usize,
153155
}
154156

155157
impl<C> Config<C> where C: Connect + Send + 'static {
@@ -163,6 +165,7 @@ impl<C> Config<C> where C: Connect + Send + 'static {
163165
keep_alive_timeout: Some(Duration::from_secs(60 * 2)),
164166
max_idle: self.max_idle,
165167
max_sockets: self.max_sockets,
168+
dns_workers: self.dns_workers,
166169
}
167170
}
168171

@@ -204,6 +207,15 @@ impl<C> Config<C> where C: Connect + Send + 'static {
204207
self
205208
}
206209

210+
/// Set number of Dns workers to use for this client
211+
///
212+
/// Default is 4
213+
#[inline]
214+
pub fn dns_workers(mut self, workers: usize) -> Config<C> {
215+
self.dns_workers = workers;
216+
self
217+
}
218+
207219
/// Construct the Client with this configuration.
208220
#[inline]
209221
pub fn build<H: Handler<C::Output>>(self) -> ::Result<Client<H>> {
@@ -220,6 +232,7 @@ impl Default for Config<DefaultConnector> {
220232
keep_alive_timeout: Some(Duration::from_secs(60 * 2)),
221233
max_idle: 5,
222234
max_sockets: 1024,
235+
dns_workers: 4,
223236
}
224237
}
225238
}

0 commit comments

Comments
 (0)