Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/conn/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ impl Pool {
.metrics
.create_failed
.fetch_add(1, atomic::Ordering::Relaxed);
self.inner
.metrics
.connection_count
.store(exchange.exist, atomic::Ordering::Relaxed);
// we just enabled the creation of a new connection!
if let Some(w) = exchange.waiting.pop() {
w.wake();
Expand Down Expand Up @@ -347,11 +351,6 @@ impl Pool {

#[allow(unused_variables)] // `since` is only used when `hdrhistogram` is enabled
while let Some(IdlingConn { mut conn, since }) = exchange.available.pop_back() {
self.inner
.metrics
.connections_in_pool
.fetch_sub(1, atomic::Ordering::Relaxed);

if !conn.expired() {
#[cfg(feature = "hdrhistogram")]
self.inner
Expand Down Expand Up @@ -383,6 +382,11 @@ impl Pool {
}
}

self.inner
.metrics
.connections_in_pool
.store(exchange.available.len(), atomic::Ordering::Relaxed);

// we didn't _immediately_ get one -- try to make one
// we first try to just do a load so we don't do an unnecessary add then sub
if exchange.exist < self.opts.pool_opts().constraints().max() {
Expand All @@ -392,7 +396,7 @@ impl Pool {
self.inner
.metrics
.connection_count
.fetch_add(1, atomic::Ordering::Relaxed);
.store(exchange.exist, atomic::Ordering::Relaxed);

let opts = self.opts.clone();
#[cfg(feature = "hdrhistogram")]
Expand Down
19 changes: 9 additions & 10 deletions src/conn/pool/recycler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ impl Future for Recycler {
.metrics
.connection_returned_to_pool
.fetch_add(1, Ordering::Relaxed);
$self
.inner
.metrics
.connections_in_pool
.fetch_add(1, Ordering::Relaxed);
#[cfg(feature = "hdrhistogram")]
$self
.inner
Expand All @@ -93,6 +88,11 @@ impl Future for Recycler {
.unwrap()
.saturating_record($conn.inner.active_since.elapsed().as_micros() as u64);
exchange.available.push_back($conn.into());
$self
.inner
.metrics
.connections_in_pool
.store(exchange.available.len(), Ordering::Relaxed);
if let Some(w) = exchange.waiting.pop() {
w.wake();
}
Expand Down Expand Up @@ -239,14 +239,13 @@ impl Future for Recycler {
}

if self.discarded != 0 {
self.inner
.metrics
.connection_count
.fetch_sub(self.discarded, Ordering::Relaxed);

// we need to open up slots for new connctions to be established!
let mut exchange = self.inner.exchange.lock().unwrap();
exchange.exist -= self.discarded;
self.inner
.metrics
.connection_count
.store(exchange.exist, Ordering::Relaxed);
for _ in 0..self.discarded {
if let Some(w) = exchange.waiting.pop() {
w.wake();
Expand Down
8 changes: 8 additions & 0 deletions src/conn/pool/ttl_check_inerval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ impl TtlCheckInterval {
}
}
exchange.available = kept_available;
self.inner
.metrics
.connections_in_pool
.store(exchange.available.len(), Ordering::Relaxed);
to_be_dropped
};

Expand All @@ -79,6 +83,10 @@ impl TtlCheckInterval {
tokio::spawn(idling_conn.conn.disconnect().then(move |_| {
let mut exchange = inner.exchange.lock().unwrap();
exchange.exist -= 1;
inner
.metrics
.connection_count
.store(exchange.exist, Ordering::Relaxed);
ok::<_, ()>(())
}));
}
Expand Down