-
Notifications
You must be signed in to change notification settings - Fork 14
[295] Make maxIdle and minIdle configurable #296
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
63a4755
Make maxIdle and minIdle configurable
suddendust 4ee6c09
Added test case
suddendust 3fde4e8
Update log
suddendust a38fbd7
Fix key
suddendust f1f4d9d
Get rid of transactional connection pool
suddendust 139e4db
Added integration tests
suddendust e1faef3
Change minIdle and maxIdle defaults to 10% and 20% respectively
suddendust 85bb374
Merge branch 'main' into feat/295
suddendust File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,13 +84,18 @@ private void setPoolProperties( | |
| final AbandonedConfig abandonedConfig = getAbandonedConfig(poolConfig); | ||
| final int maxConnections = poolConfig.maxConnections(); | ||
| connectionPool.setMaxTotal(maxConnections); | ||
| // max idle connections are 20% of max connections | ||
| connectionPool.setMaxIdle(getPercentOf(20, maxConnections)); | ||
| // min idle connections are 10% of max connections | ||
| connectionPool.setMinIdle(getPercentOf(10, maxConnections)); | ||
| connectionPool.setMaxIdle(getIdleCount(poolConfig.maxIdlePercent(), maxConnections)); | ||
| connectionPool.setMinIdle(getIdleCount(poolConfig.minIdlePercent(), maxConnections)); | ||
| connectionPool.setBlockWhenExhausted(true); | ||
| connectionPool.setMaxWaitMillis(poolConfig.connectionAccessTimeout().toMillis()); | ||
| connectionPool.setAbandonedConfig(abandonedConfig); | ||
| log.debug( | ||
| "Postgres connection pool properties - maxTotal: {}, maxIdle: {}, minIdle: {}, maxWaitMillis: {}, connectionSurrenderTimeout: {}", | ||
| connectionPool.getMaxTotal(), | ||
| connectionPool.getMaxIdle(), | ||
| connectionPool.getMinIdle(), | ||
| connectionPool.getMaxWaitMillis(), | ||
| poolConfig.connectionSurrenderTimeout()); | ||
| } | ||
|
|
||
| private void setFactoryProperties( | ||
|
|
@@ -115,7 +120,10 @@ private AbandonedConfig getAbandonedConfig(final ConnectionPoolConfig poolConfig | |
| return abandonedConfig; | ||
| } | ||
|
|
||
| private int getPercentOf(final int percent, final int maxConnections) { | ||
| private int getIdleCount(final int percent, final int maxConnections) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If nothing's specified, then we pin both to |
||
| if (percent < 0) { | ||
| return maxConnections; | ||
| } | ||
| final int value = (maxConnections * percent) / 100; | ||
| return Math.max(value, 1); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would you keep idle connections equal to max connections?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the default, in case nothing's specified.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did some cusory digging on this, static pools seem to be the preferred way almost everywhere:
Oracle DB: https://docs.oracle.com/en/database/oracle/oracle-database/26/adfns/connection_strategies.html#GUID-82AE88EA-B3C8-4416-99AF-7342FE700BD5
Hikari: https://github.com/brettwooldridge/hikaricp
" However, for maximum performance and responsiveness to spike demands, we recommend not setting this value and instead allowing HikariCP to act as a fixed size connection pool. Default: same as maximumPoolSize"
mergeAndUpsert10 connections, static size:
10 connections,
minIdle= 10%,maxIdle= 20% (existing values):Also, anyway this is just a configuration change and users can still set whatever they desire. Just that the fallback pins everything, which seems like the way to go..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, the defaults are now 10% and 20%.