From a344cd98b78a8b3e0e533789911178c62e4d6016 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Thu, 24 Mar 2011 22:28:26 +0000 Subject: [PATCH] HBASE-3673 Reduce HTable Pool Contention Using Concurrent Collections git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1085169 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 + .../hadoop/hbase/client/HTablePool.java | 41 ++++++++----------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 48490438eba..7352d75eb94 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -95,6 +95,8 @@ Release 0.91.0 - Unreleased HBASE-3468 Enhance checkAndPut and checkAndDelete with comparators HBASE-3683 NMapInputFormat should use a different config param for number of maps + HBASE-3673 Reduce HTable Pool Contention Using Concurrent Collections + (Karthick Sankarachary via Stack) TASK HBASE-3559 Move report of split to master OFF the heartbeat channel diff --git a/src/main/java/org/apache/hadoop/hbase/client/HTablePool.java b/src/main/java/org/apache/hadoop/hbase/client/HTablePool.java index 953144b1f51..62aae4c6df6 100755 --- a/src/main/java/org/apache/hadoop/hbase/client/HTablePool.java +++ b/src/main/java/org/apache/hadoop/hbase/client/HTablePool.java @@ -21,8 +21,10 @@ package org.apache.hadoop.hbase.client; import java.util.LinkedList; import java.util.Queue; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ConcurrentLinkedQueue; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; @@ -42,8 +44,8 @@ import org.apache.hadoop.hbase.util.Bytes; *

Pool will manage its own cluster to the cluster. See {@link HConnectionManager}. */ public class HTablePool { - private final ConcurrentMap> tables = - new ConcurrentHashMap>(); + private final Map> tables = + new ConcurrentHashMap>(); private final Configuration config; private final int maxSize; private final HTableInterfaceFactory tableFactory; @@ -82,16 +84,13 @@ public class HTablePool { * @throws RuntimeException if there is a problem instantiating the HTable */ public HTableInterface getTable(String tableName) { - LinkedList queue = tables.get(tableName); + Queue queue = tables.get(tableName); if(queue == null) { - queue = new LinkedList(); - tables.putIfAbsent(tableName, queue); + queue = new ConcurrentLinkedQueue(); + tables.put(tableName, queue); return createHTable(tableName); } - HTableInterface table; - synchronized(queue) { - table = queue.poll(); - } + HTableInterface table = queue.poll(); if(table == null) { return createHTable(tableName); } @@ -118,11 +117,9 @@ public class HTablePool { * @param table table */ public void putTable(HTableInterface table) { - LinkedList queue = tables.get(Bytes.toString(table.getTableName())); - synchronized(queue) { - if(queue.size() >= maxSize) return; - queue.add(table); - } + Queue queue = tables.get(Bytes.toString(table.getTableName())); + if(queue.size() >= maxSize) return; + queue.add(table); } protected HTableInterface createHTable(String tableName) { @@ -140,12 +137,10 @@ public class HTablePool { */ public void closeTablePool(final String tableName) { Queue queue = tables.get(tableName); - synchronized (queue) { - HTableInterface table = queue.poll(); - while (table != null) { - this.tableFactory.releaseHTableInterface(table); - table = queue.poll(); - } + HTableInterface table = queue.poll(); + while (table != null) { + this.tableFactory.releaseHTableInterface(table); + table = queue.poll(); } HConnectionManager.deleteConnection(this.config, true); } @@ -161,8 +156,6 @@ public class HTablePool { int getCurrentPoolSize(String tableName) { Queue queue = tables.get(tableName); - synchronized(queue) { - return queue.size(); - } + return queue.size(); } -} \ No newline at end of file +}