-
Notifications
You must be signed in to change notification settings - Fork 1.1k
GH-3826: Fix SimplePool for resizing from MAX #3829
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
Conversation
Fixes spring-projects#3826 By default, the `SimplePool` is used with an `Integer.MAX_VALUE` pool size. There is a performance degradation in the `setPoolSize()` when we try to decrease the pool size: the `while` for `permits.tryAcquire()` is too long close to the current `Integer.MAX_VALUE` pool size * Revise the logic in the `setPoolSize()` to use `Semaphore.reducePermits()` instead of the loop. * Change the calculation for a new pool size for the current pool state: or it is a size of a new request, or iti s equal to the `inUse.size()`. It will be reduced on subsequent `releaseItem()` calls * Reduce the number of `available` according a new pool size based on the `inUse`. So, if `inUse > newPoolSize`, the `available` is cleared. Otherewise, it is reduced to the number which would give `newPoolSize` together with the `inUse` size **Cherry-pick to `5.5.x`**
here is some possible fix for the problem. Thanks /CC @garyrussell |
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.
LGTM, with change.
@@ -266,6 +272,19 @@ public synchronized void close() { | |||
removeAllIdleItems(); | |||
} | |||
|
|||
private static class PoolSemaphore extends Semaphore { | |||
|
|||
public PoolSemaphore(int permits) { |
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.
Should be package protected (will solve checkstyle too).
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.
Yeah... Saw that. Trying to fix the main
for latest SF compatibility...
Thank you if you are going to fix this!
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.
Sure, will do.
Merged as 6fe59a7 and cherry-picked. |
T item = this.available.poll(); | ||
if (item != null) { | ||
doRemoveItem(item); | ||
} | ||
this.poolSize.decrementAndGet(); | ||
delta++; | ||
else { |
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.
Guess this should help in the default init case we had
This has been merged as 6fe59a7. |
Fixes #3826
By default, the
SimplePool
is used with anInteger.MAX_VALUE
pool size.There is a performance degradation in the
setPoolSize()
when we try todecrease the pool size: the
while
forpermits.tryAcquire()
is too longclose to the current
Integer.MAX_VALUE
pool sizesetPoolSize()
to useSemaphore.reducePermits()
instead of the loop.
or it is a size of a new request, or iti s equal to the
inUse.size()
.It will be reduced on subsequent
releaseItem()
callsavailable
according a new pool size based on theinUse
.So, if
inUse > newPoolSize
, theavailable
is cleared.Otherewise, it is reduced to the number which would give
newPoolSize
togetherwith the
inUse
sizeCherry-pick to
5.5.x