Set database connection pool size in mitra::main

This commit is contained in:
silverpill 2023-03-25 17:31:30 +00:00
parent 08d7482f32
commit ac6491d030
2 changed files with 4 additions and 4 deletions

View file

@ -50,13 +50,11 @@ pub async fn create_database_client(db_config: &DatabaseConfig)
client
}
pub fn create_pool(database_url: &str) -> DbPool {
pub fn create_pool(database_url: &str, pool_size: usize) -> DbPool {
let manager = deadpool_postgres::Manager::new(
database_url.parse().expect("invalid database URL"),
tokio_postgres::NoTls,
);
// https://wiki.postgresql.org/wiki/Number_Of_Database_Connections
let pool_size = num_cpus::get() * 2;
DbPool::builder(manager).max_size(pool_size).build().unwrap()
}

View file

@ -50,7 +50,9 @@ async fn main() -> std::io::Result<()> {
log::warn!("{}", warning);
};
let db_pool = create_pool(&config.database_url);
// https://wiki.postgresql.org/wiki/Number_Of_Database_Connections
let db_pool_size = num_cpus::get() * 2;
let db_pool = create_pool(&config.database_url, db_pool_size);
let mut db_client = get_database_client(&db_pool).await.unwrap();
apply_migrations(&mut db_client).await;