Skip to content

Commit

Permalink
Issue #6974 - Changes from review.
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Oct 22, 2021
1 parent 82adbc7 commit 3b91124
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected void releaseMemory(boolean direct)
for (int i = 0; i < buckets.length; ++i)
{
Bucket bucket = buckets[i];
if (bucket == null || bucket.isEmpty())
if (bucket.isEmpty())
continue;
long lastUpdate = bucket.getLastUpdate();
if (lastUpdate < oldest)
Expand Down Expand Up @@ -266,7 +266,7 @@ public void dump(Appendable out, String indent) throws IOException

List<Bucket> indirect = Arrays.stream(_indirect).filter(b -> !b.isEmpty()).collect(Collectors.toList());
List<Bucket> direct = Arrays.stream(_direct).filter(b -> !b.isEmpty()).collect(Collectors.toList());
if (_detailedDump)
if (isDetailedDump())
{
dump.add(new DumpableCollection("Indirect Buckets", indirect));
dump.add(new DumpableCollection("Direct Buckets", direct));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,17 @@ void resetUpdateTime()

public void clear()
{
while (true)
int size = _size == null ? 0 : _size.get() - 1;
while (size >= 0)
{
ByteBuffer buffer = queuePoll();
if (buffer == null)
break;
if (_size != null)
{
_size.decrementAndGet();
--size;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
* which can lower total memory usage if buffers are often being acquired of different sizes. However as there are
* fewer buckets this will also increase the contention on each bucket.
*/
public class LogArrayByteBufferPool extends ArrayByteBufferPool
public class LogarithmicArrayByteBufferPool extends ArrayByteBufferPool
{
/**
* Creates a new ByteBufferPool with a default configuration.
*/
public LogArrayByteBufferPool()
public LogarithmicArrayByteBufferPool()
{
this(-1, -1, -1);
}
Expand All @@ -40,7 +40,7 @@ public LogArrayByteBufferPool()
* @param minCapacity the minimum ByteBuffer capacity
* @param maxCapacity the maximum ByteBuffer capacity
*/
public LogArrayByteBufferPool(int minCapacity, int maxCapacity)
public LogarithmicArrayByteBufferPool(int minCapacity, int maxCapacity)
{
this(minCapacity, maxCapacity, -1, -1, -1);
}
Expand All @@ -52,7 +52,7 @@ public LogArrayByteBufferPool(int minCapacity, int maxCapacity)
* @param maxCapacity the maximum ByteBuffer capacity
* @param maxQueueLength the maximum ByteBuffer queue length
*/
public LogArrayByteBufferPool(int minCapacity, int maxCapacity, int maxQueueLength)
public LogarithmicArrayByteBufferPool(int minCapacity, int maxCapacity, int maxQueueLength)
{
this(minCapacity, maxCapacity, maxQueueLength, -1, -1);
}
Expand All @@ -66,7 +66,7 @@ public LogArrayByteBufferPool(int minCapacity, int maxCapacity, int maxQueueLeng
* @param maxHeapMemory the max heap memory in bytes
* @param maxDirectMemory the max direct memory in bytes
*/
public LogArrayByteBufferPool(int minCapacity, int maxCapacity, int maxQueueLength, long maxHeapMemory, long maxDirectMemory)
public LogarithmicArrayByteBufferPool(int minCapacity, int maxCapacity, int maxQueueLength, long maxHeapMemory, long maxDirectMemory)
{
super(minCapacity, 1, maxCapacity, maxQueueLength, maxHeapMemory, maxDirectMemory);
}
Expand All @@ -92,7 +92,7 @@ protected void releaseMemory(boolean direct)
for (int i = 0; i < buckets.length; ++i)
{
Bucket bucket = buckets[i];
if (bucket == null || bucket.isEmpty())
if (bucket.isEmpty())
continue;
long lastUpdate = bucket.getLastUpdate();
if (lastUpdate < oldest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void dump(Appendable out, String indent) throws IOException
dump.add(String.format("HeapMemory: %d/%d", getHeapMemory(), getMaxHeapMemory()));
dump.add(String.format("DirectMemory: %d/%d", getDirectMemory(), getMaxDirectMemory()));

if (_detailedDump)
if (isDetailedDump())
{
dump.add(new DumpableCollection("Indirect Buckets", _heapBuffers.values()));
dump.add(new DumpableCollection("Direct Buckets", _directBuffers.values()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.io.LogArrayByteBufferPool;
import org.eclipse.jetty.io.LogarithmicArrayByteBufferPool;
import org.eclipse.jetty.io.NullByteBufferPool;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.server.Server;
Expand Down Expand Up @@ -133,7 +133,7 @@ public void before() throws Exception

_server = new Server(threadPool);
int maxMemory = 1024 * 1024 * 16;
LogArrayByteBufferPool bufferPool = new LogArrayByteBufferPool(-1, -1, -1, maxMemory, maxMemory);
LogarithmicArrayByteBufferPool bufferPool = new LogarithmicArrayByteBufferPool(-1, -1, -1, maxMemory, maxMemory);
bufferPool.setDetailedDump(true);
_server.addBean(bufferPool);

Expand Down

0 comments on commit 3b91124

Please sign in to comment.