Skip to content

Commit

Permalink
Fixes #11371 - Review ArrayByteBufferPool eviction. (#11400)
Browse files Browse the repository at this point in the history
* Fixes #11371 - Review ArrayByteBufferPool eviction.

* Eviction is now performed on release(), rather than acquire().
* Memory accounting is done on release(), rather than acquire().
This is because we were always exceeding the memory usage on acquire(), by returning a non-pooled buffer.
We only need to account for what is idle in the pool, and that is done more efficiently on release(), and it is leak-resistant (i.e. if the buffer is not returned, the memory is already non accounted for, keeping the pool consistent).
* Released entries now give precedence to Concurrent.Entry, rather than Queued.Entry, so the queued pool is always kept at minimum size.
* Changed eviction algorithm to be simpler: one pass through the buckets excluding the current, trying to remove idle buffers until enough memory is recovered.
If successful, the buffer being released is pooled, otherwise it is also discarded.
* Added detailed statistics to ArrayByteBufferPool.RetainedBuckets.
* Added statisticsEnabled property in Jetty module bytebufferpool.mod.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet authored Feb 20, 2024
1 parent 624ee58 commit d02406c
Show file tree
Hide file tree
Showing 8 changed files with 623 additions and 236 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public CompoundPool(Pool<P> primaryPool, Pool<P> secondaryPool)
this.secondaryPool = secondaryPool;
}

public Pool<P> getPrimaryPool()
{
return primaryPool;
}

public Pool<P> getSecondaryPool()
{
return secondaryPool;
}

@Override
public Entry<P> reserve()
{
Expand Down Expand Up @@ -81,4 +91,28 @@ public Stream<Entry<P>> stream()
{
return Stream.concat(primaryPool.stream(), secondaryPool.stream());
}

@Override
public int getReservedCount()
{
return primaryPool.getReservedCount() + secondaryPool.getReservedCount();
}

@Override
public int getIdleCount()
{
return primaryPool.getIdleCount() + secondaryPool.getIdleCount();
}

@Override
public int getInUseCount()
{
return primaryPool.getInUseCount() + secondaryPool.getInUseCount();
}

@Override
public int getTerminatedCount()
{
return primaryPool.getTerminatedCount() + secondaryPool.getTerminatedCount();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,30 @@ public Stream<Entry<P>> stream()
return queue.stream();
}

@Override
public int getReservedCount()
{
return 0;
}

@Override
public int getIdleCount()
{
return size();
}

@Override
public int getInUseCount()
{
return 0;
}

@Override
public int getTerminatedCount()
{
return 0;
}

private static class QueuedEntry<P> implements Entry<P>
{
private final QueuedPool<P> pool;
Expand Down
Loading

0 comments on commit d02406c

Please sign in to comment.