Skip to content
Merged
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
24 changes: 22 additions & 2 deletions src/core/client/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,19 @@ impl<T: Poolable, K: Key> PoolInner<T, K> {
return;
};

// While someone might want a shorter duration, and it will be respected
// at checkout time, there's no need to wake up and proactively evict
// faster than this.
Comment thread
0x676e67 marked this conversation as resolved.
//
// The value of 90ms was chosen as a balance between responsiveness and
// efficiency. A shorter interval could lead to unnecessary wake-ups and
// increased CPU usage, while a longer interval might delay the eviction
// of idle connections. This value has been empirically determined to
// work well in typical use cases.
const MIN_CHECK: Duration = Duration::from_millis(90);

let dur = dur.max(MIN_CHECK);

let (tx, rx) = oneshot::channel();
self.idle_interval_ref = Some(tx);

Expand Down Expand Up @@ -982,8 +995,15 @@ mod tests {

// Let the timer tick passed the expiration...
tokio::time::sleep(Duration::from_millis(30)).await;
// Yield so the Interval can reap...
tokio::task::yield_now().await;

// But minimum interval is higher, so nothing should have been reaped
assert_eq!(
pool.locked().idle.get(&key).map(|entries| entries.len()),
Some(3)
);

// Now wait passed the minimum interval more
tokio::time::sleep(Duration::from_millis(70)).await;
Comment thread
0x676e67 marked this conversation as resolved.

assert!(pool.locked().idle.get(&key).is_none());
}
Expand Down
Loading