mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 09:42:40 +01:00
do not reallocate waiters
This commit is contained in:
parent
0925a7691a
commit
2043bb5ece
@ -509,28 +509,30 @@ impl ClientConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: waiters should be sorted by deadline. maybe timewheel?
|
||||||
fn collect_waiters(&mut self) {
|
fn collect_waiters(&mut self) {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let mut next = None;
|
let mut next = None;
|
||||||
|
|
||||||
for waiters in self.waiters.as_mut().unwrap().values_mut() {
|
for waiters in self.waiters.as_mut().unwrap().values_mut() {
|
||||||
let mut new_waiters = VecDeque::new();
|
let mut idx = 0;
|
||||||
while let Some(waiter) = waiters.pop_front() {
|
while idx < waiters.len() {
|
||||||
if waiter.wait <= now {
|
let wait = waiters[idx].wait;
|
||||||
|
if wait <= now {
|
||||||
self.stats.timeouts += 1;
|
self.stats.timeouts += 1;
|
||||||
|
let waiter = waiters.swap_remove_back(idx).unwrap();
|
||||||
let _ = waiter.tx.send(Err(ClientConnectorError::Timeout));
|
let _ = waiter.tx.send(Err(ClientConnectorError::Timeout));
|
||||||
} else {
|
} else {
|
||||||
if let Some(n) = next {
|
if let Some(n) = next {
|
||||||
if waiter.wait < n {
|
if wait < n {
|
||||||
next = Some(waiter.wait);
|
next = Some(wait);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
next = Some(waiter.wait);
|
next = Some(wait);
|
||||||
}
|
}
|
||||||
new_waiters.push_back(waiter);
|
idx += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*waiters = new_waiters;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if next.is_some() {
|
if next.is_some() {
|
||||||
|
Loading…
Reference in New Issue
Block a user