Skip to content

Commit

Permalink
perf(client): dont keep Pool mutex locked during getaddrinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Apr 25, 2016
1 parent 4828437 commit 5fcc04a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/client/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,21 @@ impl<C: NetworkConnector<Stream=S>, S: NetworkStream + Send> NetworkConnector fo
type Stream = PooledStream<S>;
fn connect(&self, host: &str, port: u16, scheme: &str) -> ::Result<PooledStream<S>> {
let key = key(host, port, scheme);
let mut locked = self.inner.lock().unwrap();
let mut should_remove = false;
let inner = match locked.conns.get_mut(&key) {
let inner = match self.inner.lock().unwrap().conns.get_mut(&key) {
Some(ref mut vec) => {
trace!("Pool had connection, using");
should_remove = vec.len() == 1;
vec.pop().unwrap()
}
_ => PooledStreamInner {
None => PooledStreamInner {
key: key.clone(),
stream: try!(self.connector.connect(host, port, scheme)),
previous_response_expected_no_content: false,
}
};
if should_remove {
locked.conns.remove(&key);
self.inner.lock().unwrap().conns.remove(&key);
}
Ok(PooledStream {
inner: Some(inner),
Expand Down

0 comments on commit 5fcc04a

Please sign in to comment.