sfackler / r2d2

A generic connection pool for Rust
Apache License 2.0
1.51k stars 82 forks source link

Will r2d2 create more connections than max_size when using builder()? #111

Closed RKochenderfer closed 3 years ago

RKochenderfer commented 4 years ago

My question is the title. The database I'm using has a very small number of connections allowed and I would like to make sure that the active connections does not exceed 4.

 let tmm10_pool = r2d2::Pool::builder()
            .max_size(4)
            .build(ODBCConnectionManager::new(&config.tmm_conn_string))?;

Will the code above ever allow a 5th connection to be created?

sfackler commented 4 years ago

The maximum size is the maximum number of connections the pool will maintain concurrently.

RKochenderfer commented 4 years ago

So just to clarify for myself as I'm relatively inexperienced with connection pooling, if there are currently 4 connections being used and a 5th one needs to be made, will r2d2 make the 5th connection wait till another connection is dropped or will it make a 5th connection that isn't maintained by the pool?

sfackler commented 4 years ago

If the number of active connections is at the max_size, the pool will not make more connections.