Add debug logs for stream pooling.

This commit is contained in:
Jacob Hoffman-Andrews
2020-11-29 00:53:12 -08:00
committed by Martin Algesten
parent 37f991fa50
commit 35c03521b9
3 changed files with 42 additions and 25 deletions

View File

@@ -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();
}