Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 09E3917AB4 for ; Wed, 11 Mar 2015 05:20:58 +0000 (UTC) Received: (qmail 12193 invoked by uid 500); 11 Mar 2015 05:20:54 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 12147 invoked by uid 500); 11 Mar 2015 05:20:54 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 12138 invoked by uid 99); 11 Mar 2015 05:20:54 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Mar 2015 05:20:54 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7F166E10C9; Wed, 11 Mar 2015 05:20:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: stack@apache.org To: commits@hbase.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: hbase git commit: HBASE-13142 [PERF] Reuse the IPCUtil#buildCellBlock buffer; ADDENDUM Date: Wed, 11 Mar 2015 05:20:54 +0000 (UTC) Repository: hbase Updated Branches: refs/heads/branch-1 05aef46d9 -> 0fb1ad7db HBASE-13142 [PERF] Reuse the IPCUtil#buildCellBlock buffer; ADDENDUM Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/0fb1ad7d Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/0fb1ad7d Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/0fb1ad7d Branch: refs/heads/branch-1 Commit: 0fb1ad7db46b12b6489d57e048f3baab147f78ec Parents: 05aef46 Author: stack Authored: Tue Mar 10 22:16:51 2015 -0700 Committer: stack Committed: Tue Mar 10 22:21:01 2015 -0700 ---------------------------------------------------------------------- .../java/org/apache/hadoop/hbase/ipc/IPCUtil.java | 15 +++++++++------ .../java/org/apache/hadoop/hbase/ipc/RpcServer.java | 10 ++++------ 2 files changed, 13 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/0fb1ad7d/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/IPCUtil.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/IPCUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/IPCUtil.java index 414abee..7c6c9ba 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/IPCUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/IPCUtil.java @@ -33,6 +33,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.CellScanner; import org.apache.hadoop.hbase.HBaseIOException; import org.apache.hadoop.hbase.codec.Codec; +import org.apache.hadoop.hbase.io.BoundedByteBufferPool; import org.apache.hadoop.hbase.io.ByteBufferOutputStream; import org.apache.hadoop.hbase.io.HeapSize; import org.apache.hadoop.hbase.util.Bytes; @@ -101,23 +102,25 @@ public class IPCUtil { * @param codec * @param compressor * @param cellScanner - * @param bb ByteBuffer to use. Can be null. You'd pass in a ByteBuffer if you want to practice - * recycling. If the passed in ByteBuffer is too small, it is discarded and a new one allotted - * so you will get back the passed-in ByteBuffer or a new, right-sized one. SIDE EFFECT!!!!! + * @param pool Pool of ByteBuffers to make use of. Can be null and then we'll allocate + * our own ByteBuffer. * @return Null or byte buffer filled with a cellblock filled with passed-in Cells encoded using * passed in codec and/or compressor; the returned buffer has been - * flipped and is ready for reading. Use limit to find total size. + * flipped and is ready for reading. Use limit to find total size. If pool was not + * null, then this returned ByteBuffer came from there and should be returned to the pool when + * done. * @throws IOException */ @SuppressWarnings("resource") public ByteBuffer buildCellBlock(final Codec codec, final CompressionCodec compressor, - final CellScanner cellScanner, final ByteBuffer bb) + final CellScanner cellScanner, final BoundedByteBufferPool pool) throws IOException { if (cellScanner == null) return null; if (codec == null) throw new CellScannerButNoCodecException(); int bufferSize = this.cellBlockBuildingInitialBufferSize; ByteBufferOutputStream baos = null; - if (bb != null) { + if (pool != null) { + ByteBuffer bb = pool.getBuffer(); bufferSize = bb.capacity(); baos = new ByteBufferOutputStream(bb); } else { http://git-wip-us.apache.org/repos/asf/hbase/blob/0fb1ad7d/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java ---------------------------------------------------------------------- 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 982815d..31afcc7 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 @@ -392,13 +392,11 @@ public class RpcServer implements RpcServerInterface { // Set the exception as the result of the method invocation. headerBuilder.setException(exceptionBuilder.build()); } - // Get a bb from the reservoir and pass it to buildCellBlock. What comes back will be the - // passed in reservoir bb or a resized one that we should instead add back to the reservoir - // when done. Keep reference so can add it back to the reservoir when finished. This is - // hacky and the hack is not contained but benefits are high when we can avoid a big buffer - // allocation on each rpc. + // Pass reservoir to buildCellBlock. Keep reference to returne so can add it back to the + // reservoir when finished. This is hacky and the hack is not contained but benefits are + // high when we can avoid a big buffer allocation on each rpc. this.cellBlock = ipcUtil.buildCellBlock(this.connection.codec, - this.connection.compressionCodec, cells, reservoir.getBuffer()); + this.connection.compressionCodec, cells, reservoir); if (this.cellBlock != null) { CellBlockMeta.Builder cellBlockBuilder = CellBlockMeta.newBuilder(); // Presumes the cellBlock bytebuffer has been flipped so limit has total size in it.