Skip to content

Commit 97bf6f3

Browse files
committed
feat(infra): enable configuring min & max cockroach pool conns
1 parent e44897d commit 97bf6f3

File tree

15 files changed

+204
-447
lines changed

15 files changed

+204
-447
lines changed

lib/bolt/config/src/ns.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ pub struct Turnstile {
286286
pub struct Service {
287287
pub count: usize,
288288
pub resources: ServiceResources,
289+
pub crdb_min_connections: Option<u64>,
290+
pub crdb_max_connections: Option<u64>,
289291
}
290292

291293
#[derive(Serialize, Deserialize, Clone, Debug)]

lib/bolt/config/src/service.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ pub struct ServiceConfig {
3636

3737
#[serde(default)]
3838
pub resources: ServiceResourcesMap,
39-
40-
#[serde(default)]
41-
pub cockroachdb: CockroachDB,
4239
}
4340

4441
#[derive(Deserialize, Clone, Debug)]
@@ -240,24 +237,6 @@ impl Default for ServiceResourcesMap {
240237
}
241238
}
242239

243-
#[derive(Deserialize, Clone, Debug)]
244-
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
245-
pub struct CockroachDB {
246-
// Sets a minimum number of connections to the database. This is important to ensure that
247-
// the initial queries are not delayed by a large surge of TCP connections immediately
248-
// after startup.
249-
//
250-
// To figure out a healthy number for this value, see the `rivet_crdb_pool_conn_size`
251-
// metric to see how many connections are being used for a given service.
252-
pub min_connections: usize,
253-
}
254-
255-
impl Default for CockroachDB {
256-
fn default() -> Self {
257-
Self { min_connections: 1 }
258-
}
259-
}
260-
261240
mod defaults {
262241
pub fn singleton() -> bool {
263242
false

lib/bolt/core/src/context/service.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -923,10 +923,12 @@ impl ServiceContextData {
923923
);
924924
}
925925

926-
env.insert(
927-
"CRDB_MIN_CONNECTIONS".into(),
928-
self.config().cockroachdb.min_connections.to_string(),
929-
);
926+
if let Some(x) = ns_service_config.crdb_min_connections {
927+
env.insert("CRDB_MIN_CONNECTIONS".into(), x.to_string());
928+
}
929+
if let Some(x) = ns_service_config.crdb_max_connections {
930+
env.insert("CRDB_MAX_CONNECTIONS".into(), x.to_string());
931+
}
930932

931933
if project_ctx.ns().prometheus.is_some() && self.depends_on_prometheus_api() {
932934
env.insert(
@@ -1374,10 +1376,14 @@ impl ServiceContextData {
13741376
config::ns::ClusterKind::SingleNode { .. } => config::ns::Service {
13751377
count: 1,
13761378
resources: self.config().resources.single_node.clone(),
1379+
crdb_min_connections: None,
1380+
crdb_max_connections: None,
13771381
},
13781382
config::ns::ClusterKind::Distributed { .. } => config::ns::Service {
13791383
count: 2,
13801384
resources: self.config().resources.distributed.clone(),
1385+
crdb_min_connections: None,
1386+
crdb_max_connections: None,
13811387
},
13821388
});
13831389

0 commit comments

Comments
 (0)