diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/BoundedByteBufferPool.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/BoundedByteBufferPool.java index c685a92..a8ff598 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/BoundedByteBufferPool.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/BoundedByteBufferPool.java @@ -67,16 +67,20 @@ public class BoundedByteBufferPool { private ReentrantLock lock = new ReentrantLock(); + private boolean createDirectByteBuffer; + /** * @param maxByteBufferSizeToCache * @param initialByteBufferSize * @param maxToCache + * @param createDirectByteBuffer whether the buffers created by this pool to be off heap */ public BoundedByteBufferPool(final int maxByteBufferSizeToCache, final int initialByteBufferSize, - final int maxToCache) { + final int maxToCache, final boolean createDirectByteBuffer) { this.maxByteBufferSizeToCache = maxByteBufferSizeToCache; this.runningAverage = initialByteBufferSize; this.buffers = new BoundedArrayQueue(maxToCache); + this.createDirectByteBuffer = createDirectByteBuffer; } public ByteBuffer getBuffer() { @@ -94,7 +98,8 @@ public class BoundedByteBufferPool { // Clear sets limit == capacity. Postion == 0. bb.clear(); } else { - bb = ByteBuffer.allocate(this.runningAverage); + bb = this.createDirectByteBuffer ? ByteBuffer.allocateDirect(this.runningAverage) + : ByteBuffer.allocate(this.runningAverage); this.allocations.incrementAndGet(); } if (LOG.isTraceEnabled()) { diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestBoundedByteBufferPool.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestBoundedByteBufferPool.java index 5074b4c..987a2ff 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestBoundedByteBufferPool.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestBoundedByteBufferPool.java @@ -37,8 +37,8 @@ public class TestBoundedByteBufferPool { @Before public void before() { - this.reservoir = - new BoundedByteBufferPool(maxByteBufferSizeToCache, initialByteBufferSize, maxToCache); + this.reservoir = new BoundedByteBufferPool(maxByteBufferSizeToCache, initialByteBufferSize, + maxToCache, false); } @After diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java index 0ee93eb..888e8f8 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java @@ -1964,7 +1964,9 @@ public class RpcServer implements RpcServerInterface { // Make the max twice the number of handlers to be safe. conf.getInt("hbase.ipc.server.reservoir.initial.max", conf.getInt(HConstants.REGION_SERVER_HANDLER_COUNT, - HConstants.DEFAULT_REGION_SERVER_HANDLER_COUNT) * 2)); + HConstants.DEFAULT_REGION_SERVER_HANDLER_COUNT) * 2), + // By default make direct byte buffers from the buffer pool. + conf.getBoolean("hbase.ipc.server.reservoir.direct.buffer", true)); this.server = server; this.services = services; this.bindAddress = bindAddress;