Skip to content

Commit

Permalink
add pool sweeper task
Browse files Browse the repository at this point in the history
  • Loading branch information
taddes committed Dec 5, 2024
1 parent 381078a commit cb9ceb5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions syncstorage-spanner/src/pool.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{collections::HashMap, fmt, sync::Arc, time::Duration};

use actix_web::rt;
use async_trait::async_trait;
use syncserver_common::{BlockingThreadpool, Metrics};
use syncserver_db_common::{GetPoolState, PoolState};
Expand Down Expand Up @@ -84,6 +85,22 @@ impl SpannerDbPool {
self.quota,
))
}

/// Spawn a task to periodically evict idle connections. Calls wrapper sweeper fn
/// to use pool.retain, retaining objects only if they are shorter in duration than
/// defined max_idle.
pub fn spawn_sweeper(&self, interval: Duration) {
let Some(max_idle) = self.pool.manager().settings.max_lifespan else {
return;
};
let pool = self.pool.clone();
rt::spawn(async move {
loop {
sweeper(&pool, max_idle);
rt::time::sleep(interval).await;
}
});
}
}

/// Sweeper to retain only the objects specified within the closure.
Expand Down

0 comments on commit cb9ceb5

Please sign in to comment.