backend: reduce number of concurrent db connections
This commit is contained in:
@@ -14,7 +14,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
init_tracing();
|
||||
|
||||
let config = AppConfig::from_env()?;
|
||||
let pool = db::init_pool(&config.database_url)?;
|
||||
let pool = db::init_pool_with_size(&config.database_url, 1)?;
|
||||
let s3_client = build_client(&config).await?;
|
||||
let storage = Arc::new(S3Storage::new(s3_client, config.s3_bucket.clone()));
|
||||
let jwt = JwtService::from_config(&config)?;
|
||||
|
||||
+8
-1
@@ -5,10 +5,17 @@ use diesel::r2d2::{ConnectionManager, Pool};
|
||||
|
||||
pub type PgPool = Pool<ConnectionManager<PgConnection>>;
|
||||
|
||||
const DEFAULT_MAX_POOL_SIZE: u32 = 2;
|
||||
|
||||
pub fn init_pool(database_url: &str) -> anyhow::Result<PgPool> {
|
||||
init_pool_with_size(database_url, DEFAULT_MAX_POOL_SIZE)
|
||||
}
|
||||
|
||||
pub fn init_pool_with_size(database_url: &str, max_size: u32) -> anyhow::Result<PgPool> {
|
||||
let manager = ConnectionManager::<PgConnection>::new(database_url);
|
||||
let pool_size = max_size.max(1);
|
||||
let pool = Pool::builder()
|
||||
.max_size(16)
|
||||
.max_size(pool_size)
|
||||
.connection_timeout(Duration::from_secs(10))
|
||||
.build(manager)?;
|
||||
Ok(pool)
|
||||
|
||||
Reference in New Issue
Block a user