Commit 9ffeac79 authored by Szymon Zimnowoda's avatar Szymon Zimnowoda
Browse files

Merge branch 'sz/increase_db_pool' into 'dev'

increased number of connections in the pool

See merge request memri/pod!395
parents 2b156f79 4e6e8645
Showing with 29 additions and 9 deletions
+29 -9
......@@ -155,20 +155,14 @@ where
)
};
let cpus = num_cpus::get() as u32;
let num_connections = u32::max(num_cpus::get() as u32 * 4, 8);
info!(cpus, "creating a database pool");
info!(num_connections, "creating a database pool");
let pool =
// Builder blocks until reaches requested number of connections
r2d2::Pool::builder()
// Create a pool of connections equal to number of logic cores on the machine.
// Tokio creates the same amount of worker tasks, and since current database access
// is blocking, there is no point ot create more.
// Might be beneficial to increase this limit when DB queries will be offloaded
// to blocking threads.
.max_size(cpus)
.max_size(num_connections)
// Calls to Pool::get will wait this long for a connection to become available before returning an error.
.connection_timeout(Duration::from_secs(5))
.build(manager)?;
......@@ -860,4 +854,30 @@ pub mod tests {
));
assert!(Path::new(&owner_database_path(owner)).exists());
}
#[tokio::test]
async fn test_number_of_connections() {
let owner = "test_number_of_connections";
let _temp_db = TempDb::new(owner);
let database_key = DatabaseKey::from(
"dbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdb".to_string(),
)
.unwrap();
let init_db = RwLock::new(HashMap::new());
initialize_db(owner, &init_db, &database_key).await.unwrap();
let pool = get_pool(owner, &init_db, &database_key).await.unwrap();
let num_connections = u32::max(num_cpus::get() as u32 * 4, 8);
let _conns: Vec<PooledConnection> = (0..num_connections)
.map(|_| get_connection_from_pool(&pool, &database_key).unwrap())
.collect();
// Pool is empty, expect error
assert!(get_connection_from_pool(&pool, &database_key).is_err());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment