Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Min Pool is not respected #22

Open
SergeyCherman opened this issue Jun 7, 2020 · 16 comments
Open

Min Pool is not respected #22

SergeyCherman opened this issue Jun 7, 2020 · 16 comments
Labels
enhancement New feature or request

Comments

@SergeyCherman
Copy link

Issue Description
In the sequelize configuration, I've set

pool: {
min: 10,
max: 30
}

When the connection is acquired it does not check if additional connections need to be made and hence only 1 connection is made instead of 10.

What do you expect to happen?
I expect the min setting to be respected and 10 connections to be made.

Issue is a copy of: sequelize/sequelize#11440 however I believe the issue is in sequelize-pool lib and not in the main sequelize project.

@sushantdhiman
Copy link
Collaborator

Sequelize pool will keep on increasing available resources to given min config, and will keep them at that level after pool saturation.

If application does not issue enough acquire calls, then pool will not grow to given min config. This is technically a bug, but I don't think this affects performance in any way. This means application is able to satisfy traffic with subset of resources.

What is the real motivation behind this change @SergeyCherman? Are you facing any performance issues?

@SergeyCherman
Copy link
Author

@sushantdhiman Thank you for the quick reply! There were a couple reasons for this PR attempt:

  1. I noticed perf degradations for the initial batch of queries being done as creating the connection took a little time. Since the connections will also expire after some time, it caused random cases where perf was worse then expected. I could be wrong but I assume it was due to connections being re-created.

  2. I ran into an issue where my service was unable to make additional connections due to postgres max_connections config, which then caused other issues, perhaps the pool isn't handling that gracefully as I encountered errors (however I haven't tried that scenario with seq 5.x yet, only 4.x)

  3. In my environment there are many apps creating database connections and it was possible that another app ate more then expected. I wanted to ensure my app would not start up (if available connections were below min) and be in an invalid state (from 2 above.) Due to this I was trying to set min/max to the same number and expected my service to either start and have all connections required, or not start and hence the deployment error out.

You said that application should issue acquire do you mean the users of sequelize should call acquire up to the min or the Sequelize library itself (currently Sequelize doesn't.) Also what would happen if connections expire and then drop below the min?

@sushantdhiman
Copy link
Collaborator

One point to keep in mind, this pool is not used with sequelize@4.x. It was introduced with sequelize@5.x

@SergeyCherman
Copy link
Author

SergeyCherman commented Jun 9, 2020

Sorry for the miscommunication, I meant that in 4.x (pre pool) min was respected and Sequelize would make the min configured connections on app start, in 5.x it looked like a regression as min connections weren't made.

Is there a different area where the fix should be made? I attempted to do it via: #23

@marcogrcr
Copy link

If this behavior is not going to be changed, I believe the documentation should be updated:

/**
* Minimum number of items in pool (including in-use).
* When the pool is created, or a resource destroyed, this minimum will
* be checked. If the pool resource count is below the minimum, a new
* resource will be created and added to the pool.<Paste>
*/
min: number;

Particularly,

When the pool is created, or a resource destroyed, this minimum will be checked.

@SergeyCherman
Copy link
Author

@marcogrcr I'm sure this was a regression. I know @sushantdhiman had to depart the project, not sure how to get the discussion going with the new maintainers.

@bploetz
Copy link

bploetz commented Jun 4, 2021

Any update on this? Who's maintaining this repo now?

@sushantdhiman
Copy link
Collaborator

I have thought about this and #23, I think a new method to fill pool like fill | enrich etc can be introduced without breaking compatibility with current behavior. This method may be called when application starts, thus solving issue #23 is trying to solve.

I'll accept such PR if this idea sounds ok

@SergeyCherman
Copy link
Author

@sushantdhiman yes I think that makes sense, I will add a new public method for fill to the pool class. Once I do that I will add an issue and a PR for updating the docs of the main sequelize branch.

I'll try and get it done this weekend.

@azai91
Copy link

azai91 commented Oct 19, 2021

Any update on this issue?

@SergeyCherman
Copy link
Author

Sorry, I got tied up and forgot. I'll try and get a PR out this week.

@Shahor
Copy link

Shahor commented Dec 15, 2021

Any news? Or help we can provide?

@WikiRik
Copy link
Member

WikiRik commented Jan 15, 2022

Hi @SergeyCherman
Not sure if you ever got to making a PR, but feel free to let us know if you can't anymore of require assistance with it 🙂

@ShaunB-SQ
Copy link

Was this ever done, as I feel I am experiencing a similar issue in sequelize 6.19.2.
As connections error out or disconnect new ones are not established, and I finally get a message

SequelizeConnectionError: Failed to connect to xxxx.xxxx.com:1433 in 15000ms
    at ConnectionManager.connect (/usr/src/app/server/node_modules/sequelize/lib/dialects/mssql/connection-manager.js:116:17)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async ConnectionManager._connect (/usr/src/app/server/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:216:24)

even though in mssql and in ssms I am able to connect to the db just fine.

@sushantdhiman sushantdhiman added the enhancement New feature or request label Jul 25, 2022
@vshubhansh
Copy link

Did we go around fixing this? I see that PR by @SergeyCherman was closed. I'm on v6.20 and getting same issue. This is impacting the performance of the first batch of queries that the application receives, which i'm hypothesising is due to new connections being opened.
Is there any workaround to open a minimum number of connections when the application first comes up, rather than waiting for the load and then acquiring new connections for the pool?

@WikiRik
Copy link
Member

WikiRik commented Jun 28, 2023

I have thought about this and #23, I think a new method to fill pool like fill | enrich etc can be introduced without breaking compatibility with current behavior. This method may be called when application starts, thus solving issue #23 is trying to solve.

I'll accept such PR if this idea sounds ok

I believe that this message is still what the current sequelize maintainers can review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants