Giter Club home page Giter Club logo

Comments (8)

sfackler avatar sfackler commented on July 19, 2024 1

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.

sfackler avatar sfackler commented on July 19, 2024

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.

hoangtranwork avatar hoangtranwork commented on July 19, 2024

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.

sfackler avatar sfackler commented on July 19, 2024

Why would min_idle have to be max_size almost all the time?

from r2d2.

hoangtranwork avatar hoangtranwork commented on July 19, 2024

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.

sfackler avatar sfackler commented on July 19, 2024

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.

hoangtranwork avatar hoangtranwork commented on July 19, 2024

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.

hoangtranwork avatar hoangtranwork commented on July 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.