-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: database/sql: make free connection strategy configurable #68539
Comments
CC @kardianos |
@kishoresenji I'm skeptical. However, if you provide a proof of concept or sketch that shows this could be reasonably extracted from the current code base, I'd be game to re-evaluate. If the connection use strategy was able to be extracted to some internal interface, and the type is used cleanly throughout, then perhaps this could clean up existing code. However, if any implementation resulted in more complicated or harder to understand logic surrounding this, that would be an instant no. |
@kardianos As the We can have a new enum which models which strategy to be used.
and LeastRecentlyUsed strategy can be enabled with an option on the DB. By default, it will be MostRecentlyUsed strategy.
The
where
|
I have put the above code in a commit in my fork: 7f5dd3c?diff=split&w=1 |
@kardianos gentle ping to know if there is a chance on getting this proposal accepted or I should look at other alternatives. We are seeing imbalance in our clusters and that is why I started this proposal. Another approach is to have pooling outside of database/sql by setting maxIdleConns to -1 and supplying a Connector, which does the pooling, to OpenDB function. The connector will return a Connection which just returns the Connection back to the pool on Close from database/sql package. |
Proposal Details
The current strategy of lookup of a free connection is based on "most recently used" and this helps in closing connections as soon as they become idle. But this strategy creates traffic imbalance between multiple replicas of a cluster (behind haproxy) as it prefers recently used connections, some read replicas in a cluster get much higher qps than other replicas.
Proposal is to add a configurable option to DB type using which the free connection strategy will be using "least recently used" and picks connections from the beginning of the
freeConn
slice. Although this does not let idle connections to be cleaned up as connections won't be idle compared to the current strategy, this new strategy can be coupled withSetConnMaxLifetime
to ensure that after ConnMaxLifetime, the optimal resources are being used.The text was updated successfully, but these errors were encountered: