sequelize / sequelize-pool

Resource pool implementation. It can be used to throttle expensive resources.
Other
38 stars 17 forks source link

Add maxUses option to the pooler #18

Closed chriskchew closed 4 years ago

chriskchew commented 4 years ago

My team has encountered a situation where new read replicas are not used when they have been added after the node process has already started and filled the connection pool with healthy connections. This change offers a way to rebalance the load across a cluster by limiting the lifetime of a resource in the pool.

Once a resource has been used and released maxUses times, upon release the resource is destroyed rather than recycled. Over a period of minutes or hours, depending on load volume and the maxUses config, connections will be "end-of-lifed" and replaced with new ones based on the balancing strategy used by the system (e.g. load balancer reverse proxy, DNS round-robin, etc.).

In essence, the change extends the pre-existing pattern of wrapping the resource with metadata when adding it to the availables list: First it adds a useCount counter next to timeout, then it repeats the pattern for the in-use list so that the useCount metadata can be preserved across acquisitions and releases.

I appreciate your help reviewing this PR and hopefully adopting it, as it will greatly increase our ability to continue to grow with Sequelize. Thank you!

papb commented 4 years ago

Hello! I see you are a first-time contributor, thank you for taking the time to help Sequelize! I hope to see more PRs from you in the future!

I will now review your PR!

chriskchew commented 4 years ago

Hello! I see you are a first-time contributor, thank you for taking the time to help Sequelize! I hope to see more PRs from you in the future!

I will now review your PR!

Yes, "long time listener first time caller". :)

Thank you for reviewing and considering the change.

papb commented 4 years ago

@sushantdhiman Do you have any idea why travis tests did not execute?

sushantdhiman commented 4 years ago

@papb Travis failed to report build status for last commit. After restarting build is green

papb commented 4 years ago

Awesome! Thanks for the great work! Hope to see more PRs from you in the future :)