Skip to content

Commit

Permalink
update spawn_sweeper and configs
Browse files Browse the repository at this point in the history
  • Loading branch information
taddes committed Dec 5, 2024
1 parent a81275a commit c347572
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions syncserver/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ impl Server {
&Metrics::from(&metrics),
blocking_threadpool.clone(),
)?;
// Spawns sweeper that calls Deadpool `retain` method, clearing unused connections.
db_pool.spawn_sweeper(Duration::from_secs(
settings
.syncstorage
.database_pool_sweeper_task_interval
.unwrap()
.into(),
));
let glean_logger = Arc::new(GleanEventsLogger {
// app_id corresponds to probe-scraper entry.
// https://github.com/mozilla/probe-scraper/blob/main/repositories.yaml
Expand Down
4 changes: 2 additions & 2 deletions syncstorage-spanner/src/manager/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub struct SpannerSessionSettings {
/// Max idle time of a Session
pub max_idle: Option<u32>,
/// Interval for sweeper task releasing unused connections.
pub pool_sweeper_task_interval: Option<u32>,
pub pool_max_idle: Option<u32>,

/// For tests: disables transactions from committing
pub(crate) use_test_transactions: bool,
Expand Down Expand Up @@ -96,7 +96,7 @@ impl SpannerSessionSettings {
route_to_leader: settings.database_spanner_route_to_leader,
max_lifespan: settings.database_pool_connection_lifespan,
max_idle: settings.database_pool_connection_max_idle,
pool_sweeper_task_interval: settings.database_pool_sweeper_task_interval,
pool_max_idle: settings.database_pool_connection_max_idle,
use_test_transactions,
emulator_host: settings.spanner_emulator_host.clone(),
})
Expand Down
4 changes: 2 additions & 2 deletions syncstorage-spanner/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl SpannerDbPool {
/// 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 {
let Some(max_idle) = self.pool.manager().settings.pool_max_idle else {
return;
};
let pool = self.pool.clone();
Expand All @@ -105,7 +105,7 @@ impl SpannerDbPool {

/// Sweeper to retain only the objects specified within the closure.
/// In this context, if a Spanner connection is unutilized, we want it
/// to release the given connections.
/// to release the given connection.
/// See: https://docs.rs/deadpool/latest/deadpool/managed/struct.Pool.html#method.retain
fn sweeper(pool: &deadpool::managed::Pool<SpannerSessionManager>, max_idle: Duration) {
pool.retain(|_, metrics| metrics.last_used() < max_idle);
Expand Down

0 comments on commit c347572

Please sign in to comment.