Set database connection pool size in mitra::main
This commit is contained in:
parent
08d7482f32
commit
ac6491d030
2 changed files with 4 additions and 4 deletions
|
@ -50,13 +50,11 @@ pub async fn create_database_client(db_config: &DatabaseConfig)
|
||||||
client
|
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(
|
let manager = deadpool_postgres::Manager::new(
|
||||||
database_url.parse().expect("invalid database URL"),
|
database_url.parse().expect("invalid database URL"),
|
||||||
tokio_postgres::NoTls,
|
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()
|
DbPool::builder(manager).max_size(pool_size).build().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,9 @@ async fn main() -> std::io::Result<()> {
|
||||||
log::warn!("{}", warning);
|
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();
|
let mut db_client = get_database_client(&db_pool).await.unwrap();
|
||||||
apply_migrations(&mut db_client).await;
|
apply_migrations(&mut db_client).await;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue