Add debug logs for stream pooling.
This commit is contained in:
committed by
Martin Algesten
parent
37f991fa50
commit
35c03521b9
14
src/pool.rs
14
src/pool.rs
@@ -7,6 +7,7 @@ use crate::stream::Stream;
|
||||
use crate::unit::Unit;
|
||||
use crate::Proxy;
|
||||
|
||||
use log::debug;
|
||||
use url::Url;
|
||||
|
||||
/// Holder of recycled connections.
|
||||
@@ -115,6 +116,7 @@ impl ConnectionPool {
|
||||
remove_last_match(&mut inner.lru, &key)
|
||||
.expect("invariant failed: key in recycle but not in lru");
|
||||
|
||||
debug!("pulling stream from pool: {:?} -> {:?}", key, stream);
|
||||
Some(stream)
|
||||
}
|
||||
Entry::Vacant(_) => None,
|
||||
@@ -125,6 +127,7 @@ impl ConnectionPool {
|
||||
if self.noop() {
|
||||
return;
|
||||
}
|
||||
debug!("adding stream to pool: {:?} -> {:?}", key, stream);
|
||||
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
match inner.recycle.entry(key.clone()) {
|
||||
@@ -133,7 +136,13 @@ impl ConnectionPool {
|
||||
streams.push_back(stream);
|
||||
if streams.len() > self.max_idle_connections_per_host {
|
||||
// Remove the oldest entry
|
||||
streams.pop_front();
|
||||
let stream = streams.pop_front().expect("empty streams list");
|
||||
debug!(
|
||||
"host {:?} has {} conns, dropping oldest: {:?}",
|
||||
key,
|
||||
streams.len(),
|
||||
stream
|
||||
);
|
||||
remove_first_match(&mut inner.lru, &key)
|
||||
.expect("invariant failed: key in recycle but not in lru");
|
||||
}
|
||||
@@ -159,9 +168,10 @@ impl ConnectionPool {
|
||||
match inner.recycle.entry(key) {
|
||||
Entry::Occupied(mut occupied_entry) => {
|
||||
let streams = occupied_entry.get_mut();
|
||||
streams
|
||||
let stream = streams
|
||||
.pop_front()
|
||||
.expect("invariant failed: key existed in recycle but no streams available");
|
||||
debug!("dropping oldest stream in pool: {:?}", stream);
|
||||
if streams.len() == 0 {
|
||||
occupied_entry.remove();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user