Skip to content

Commit

Permalink
Only create one pool in the unified case
Browse files Browse the repository at this point in the history
  • Loading branch information
loewenheim committed Jul 24, 2024
1 parent 0b4c65f commit 7a0bb81
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 27 deletions.
32 changes: 16 additions & 16 deletions relay-config/src/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,20 @@ pub enum RedisConfigs {

/// Helper struct bundling connections and options for the various Redis pools.
#[derive(Clone, Debug)]
pub struct RedisPoolConfigs<'a> {
/// Configuration for the `project_configs` pool.
pub project_configs: (&'a RedisConnection, RedisConfigOptions),
/// Configuration for the `cardinality` pool.
pub cardinality: (&'a RedisConnection, RedisConfigOptions),
/// Configuration for the `quotas` pool.
pub quotas: (&'a RedisConnection, RedisConfigOptions),
/// Configuration for the `misc` pool.
pub misc: (&'a RedisConnection, RedisConfigOptions),
pub enum RedisPoolConfigs<'a> {
/// Use one pool for everything.
Unified((&'a RedisConnection, RedisConfigOptions)),
/// Use an individual pool for each use case.
Individual {
/// Configuration for the `project_configs` pool.
project_configs: (&'a RedisConnection, RedisConfigOptions),
/// Configuration for the `cardinality` pool.
cardinality: (&'a RedisConnection, RedisConfigOptions),
/// Configuration for the `quotas` pool.
quotas: (&'a RedisConnection, RedisConfigOptions),
/// Configuration for the `misc` pool.
misc: (&'a RedisConnection, RedisConfigOptions),
},
}

pub(super) fn create_redis_pool(
Expand Down Expand Up @@ -191,12 +196,7 @@ pub(super) fn create_redis_pools(configs: &RedisConfigs, cpu_concurrency: u32) -
match configs {
RedisConfigs::Unified(cfg) => {
let pool = create_redis_pool(cfg, project_configs_default_connections);
RedisPoolConfigs {
project_configs: pool.clone(),
cardinality: pool.clone(),
quotas: pool.clone(),
misc: pool,
}
RedisPoolConfigs::Unified(pool)
}
RedisConfigs::Individual {
project_configs,
Expand All @@ -209,7 +209,7 @@ pub(super) fn create_redis_pools(configs: &RedisConfigs, cpu_concurrency: u32) -
let cardinality = create_redis_pool(cardinality, cpu_concurrency);
let quotas = create_redis_pool(quotas, cpu_concurrency);
let misc = create_redis_pool(misc, cpu_concurrency);
RedisPoolConfigs {
RedisPoolConfigs::Individual {
project_configs,
cardinality,
quotas,
Expand Down
46 changes: 35 additions & 11 deletions relay-server/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,18 +373,42 @@ fn create_redis_pool(
}
}

/// Creates Redis pools from the given `configs`.
///
/// If `configs` is [`Unified`](RedisPoolConfigs::Unified), one pool is created and then cloned
/// for each use case, meaning that all use cases really use the same pool. If it is
/// [`Individual`](RedisPoolConfigs::Individual), an actual separate pool is created for each
/// use case.
pub fn create_redis_pools(configs: RedisPoolConfigs) -> Result<RedisPools, RedisError> {
let project_configs = create_redis_pool(configs.project_configs)?;
let cardinality = create_redis_pool(configs.cardinality)?;
let quotas = create_redis_pool(configs.quotas)?;
let misc = create_redis_pool(configs.misc)?;

Ok(RedisPools {
project_configs,
cardinality,
quotas,
misc,
})
match configs {
RedisPoolConfigs::Unified(pool) => {
let pool = create_redis_pool(pool)?;
Ok(RedisPools {
project_configs: pool.clone(),
cardinality: pool.clone(),
quotas: pool.clone(),
misc: pool,
})
}
RedisPoolConfigs::Individual {
project_configs,
cardinality,
quotas,
misc,
} => {
let project_configs = create_redis_pool(project_configs)?;
let cardinality = create_redis_pool(cardinality)?;
let quotas = create_redis_pool(quotas)?;
let misc = create_redis_pool(misc)?;

Ok(RedisPools {
project_configs,
cardinality,
quotas,
misc,
})
}
}
}

#[axum::async_trait]
Expand Down

0 comments on commit 7a0bb81

Please sign in to comment.