Skip to content

Commit

Permalink
do not reallocate waiters
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Jul 20, 2018
1 parent 0925a76 commit 2043bb5
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/client/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,28 +509,30 @@ impl ClientConnector {
}
}

// TODO: waiters should be sorted by deadline. maybe timewheel?
fn collect_waiters(&mut self) {
let now = Instant::now();
let mut next = None;

for waiters in self.waiters.as_mut().unwrap().values_mut() {
let mut new_waiters = VecDeque::new();
while let Some(waiter) = waiters.pop_front() {
if waiter.wait <= now {
let mut idx = 0;
while idx < waiters.len() {
let wait = waiters[idx].wait;
if wait <= now {
self.stats.timeouts += 1;
let waiter = waiters.swap_remove_back(idx).unwrap();
let _ = waiter.tx.send(Err(ClientConnectorError::Timeout));
} else {
if let Some(n) = next {
if waiter.wait < n {
next = Some(waiter.wait);
if wait < n {
next = Some(wait);
}
} else {
next = Some(waiter.wait);
next = Some(wait);
}
new_waiters.push_back(waiter);
idx += 1;
}
}
*waiters = new_waiters;
}

if next.is_some() {
Expand Down

0 comments on commit 2043bb5

Please sign in to comment.