Comments (8)
establish_idle_connections only adds connections up to min_idle. If the pool is already larger than min_idle, establish_idle_connections does not create new connections.
from r2d2.
The minimum number of connections in the pool is controlled by https://docs.rs/r2d2/0.8.9/r2d2/struct.Builder.html#method.min_idle.
Generally speaking, the entire point of a connection pool is to keep connections around between uses so they're immediately available next time a request comes in.
from r2d2.
Thank you.
min_idle
is fine for "keeping x
number of connections around". It'd be nice though that x
doesn't have to be max_size
almost all the time. It'd help in an environment where the DB is shared and prefer clients to play nice instead of keeping too many connections at all time (many of which are idle).
from r2d2.
Why would min_idle have to be max_size almost all the time?
from r2d2.
Sorry I didn't make it clear. I was just describing what r2d2 is doing currently.
Let use an example: if we set min_idle=1
and max_size=10
, then r2d2 will not only maintain at minimum 1 idle connection (which is great) but it also try to maintain exactly 10 connections at almost all time (which is not very flexible).
I think with this config, the behavior should be:
A. keep at least 1 idle connection, and
B. open at max 10 connections, and
C. do not pro-actively try to open more idle connections than min_idle
Please correct me if my observation is wrong. Thank you.
from r2d2.
What specific conditions do you mean when you refer to "at almost all time"? If there is no usage of the pool, it will tend towards having exactly min_idle connections in it. If a single thread is using the pool, that will result in min_idle + 1 connections existing.
from r2d2.
From what I have tried, one case is: when a connection reaches idle_timeout, it is dropped, but a new idle connection is created right away filling the place.
From what I understand from the code, it does that in every case (during drop_conn
, establish_idle_connection
is called - as referenced in the opening post above)
from r2d2.
ohhhhhhh yes, I see why, the default value for min_idle
is equal to max_size
. I'm sorry I missed this. I thought default value is 0 :D
It seems to be a weird default choice though.
Anyway I think we can close this issue. Thank you very much.
from r2d2.
Related Issues (20)
- `get_timeout` exceeds timeout HOT 11
- Can be used in the future such as tokio, async_std? HOT 1
- Use `compare_exchange` or `compare_exchange_weak` instead
- Is there a way to drop or close an actual connection when I'm using PooldConnection? HOT 4
- "Named" connections HOT 3
- Why example use `let pool = pool.clone()` in a for loop ? HOT 2
- Document relationship between `min_idle`, `idle_timeout` and `max_lifetime` HOT 1
- How to set timezone when linking HOT 1
- Release? HOT 1
- Allow hooking on connection get-from-pool and release-to-pool HOT 8
- Using behind proxychains HOT 1
- Seg fault with Postgres HOT 14
- Remove parking_lot dependency now that std's Mutex is faster than before HOT 3
- [Bug] CI test failure on arm HOT 4
- r2d2::Error should derive PartialEq and Clone HOT 4
- Pool building freezes when connections drop during initial setup HOT 4
- Does it support ssh2 sessions?
- Add a PooledConnection::pool() method HOT 3
- Fail Fast for Certain Errors
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from r2d2.