Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

artembilan
Copy link
Member

Fixes #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

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`**
@artembilan
Copy link
Member Author

@gauravbrills,

here is some possible fix for the problem.
I'm not sure that is perfect, but still would like to share to start some discussion and gather other options.

Thanks

/CC @garyrussell

Copy link
Contributor

@garyrussell garyrussell left a 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) {
Copy link
Contributor

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).

Copy link
Member Author

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!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do.

@garyrussell
Copy link
Contributor

Merged as 6fe59a7 and cherry-picked.

T item = this.available.poll();
if (item != null) {
doRemoveItem(item);
}
this.poolSize.decrementAndGet();
delta++;
else {

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

@artembilan
Copy link
Member Author

This has been merged as 6fe59a7.
Thank you!

@artembilan artembilan closed this Jun 28, 2022
@artembilan artembilan deleted the GH-3826 branch June 28, 2022 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CachingSessionFactory slowness if setPoolSize is called without initializing initial sessionCacheSize
3 participants