You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by li...@apache.org on 2013/06/05 20:18:26 UTC

svn commit: r1489991 - in /hbase/branches/0.89-fb/src: main/java/org/apache/hadoop/hbase/ main/java/org/apache/hadoop/hbase/ipc/ main/java/org/apache/hadoop/hbase/util/ main/java/org/apache/hadoop/hbase/util/throttles/ test/java/org/apache/hadoop/hbase...

Author: liyin
Date: Wed Jun  5 18:18:26 2013
New Revision: 1489991

URL: http://svn.apache.org/r1489991
Log:
[HBASE-8688] [89-fb] Adding a choice of single/multiple throttler for callqueue

Author: adela

Summary: I am adding two throttles such that we will throttle the larger and smaller responses differently. Looking at the charts, in a normal state we are not returning responses bigger than 25MB, so I am adding throttler which will throttle the responses <= 25MB and the size of that throttler would be 256MB (10 threads could be writing in the same time). The other throttler would be 768MB and would be for the larger requests. This would potentially help in a case when the client is requesting large responses: the smaller ones would not be blocked. Note that previously we had only 1 throttle of size 1GB so now we are basically dividing the space between 2 of them.

Test Plan: to be defined

Reviewers: aaiyer, liyintang, rshroff

Reviewed By: rshroff

CC: hbase-eng@, rshroff

Differential Revision: https://phabricator.fb.com/D778501

Added:
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/SizeBasedMultiThrottler.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/SizeBasedThrottler.java
      - copied, changed from r1489990, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/SizeBasedThrottler.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/SizeBasedThrottlerInterface.java
Modified:
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/HConstants.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/HBaseServer.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/SizeBasedThrottler.java
    hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/util/TestSizeBasedThrottler.java

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/HConstants.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/HConstants.java?rev=1489991&r1=1489990&r2=1489991&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/HConstants.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/HConstants.java Wed Jun  5 18:18:26 2013
@@ -696,6 +696,27 @@ public final class HConstants {
   public static final String CLIENT_SOCKED_CLOSED_EXC_MSG = "Interrupting the read request";
   public static final String SERVER_INTERRUPTED_CALLS_KEY = "serverInterruptedCalls";
 
+  /**
+   * Controls whether we use one or two throttles to control the insert in the queue
+   */
+  public static final String USE_MULTIPLE_THROTTLES = "hbase.server.multithrottler";
+
+  /**
+   * How much memory do we want for the blocking callqueue, used in HBaseServer
+   */
+   public static final long MAX_CALL_QUEUE_MEMORY_SIZE = 1024*1024*1024;
+   public static final String MAX_CALL_QUEUE_MEMORY_SIZE_STRING = "max.callqueue.memory.size";
+
+   /**
+    * Used in HBase Server, when we use the multithrottler for the callQueue
+    */
+   public static final long MAX_SMALLER_CALL_QUEUE_MEMORY_SIZE = 256*1024*1024;
+   public static final String MAX_SMALLER_CALL_QUEUE_MEMORY_SIZE_STRING = "max.smaller.callqueue.memory.size";
+   public static final long MAX_LARGER_CALL_QUEUE_MEMORY_SIZE = 768*1024*1024;
+   public static final String MAX_LARGER_CALL_QUEUE_MEMORY_SIZE_STRING = "max.larger.callqueue.memory.size";
+   public static final int SMALL_QUEUE_REQUEST_LIMIT = 25*1024*1024;
+   public static final String SMALL_QUEUE_REQUEST_LIMIT_STRING = "small.queue.request.limit";
+
   private HConstants() {
     // Can't be instantiated with this constructor.
   }

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/HBaseServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/HBaseServer.java?rev=1489991&r1=1489990&r2=1489991&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/HBaseServer.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/HBaseServer.java Wed Jun  5 18:18:26 2013
@@ -50,7 +50,7 @@ import java.util.concurrent.LinkedBlocki
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.util.SizeBasedThrottler;
+import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.io.WritableWithSize;
 import org.apache.hadoop.hbase.io.hfile.Compression;
 import org.apache.hadoop.hbase.io.hfile.Compression.Algorithm;
@@ -67,6 +67,9 @@ import org.apache.hadoop.security.UserGr
 import org.apache.hadoop.util.ReflectionUtils;
 import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.hbase.util.HasThread;
+import org.apache.hadoop.hbase.util.throttles.SizeBasedMultiThrottler;
+import org.apache.hadoop.hbase.util.throttles.SizeBasedThrottler;
+import org.apache.hadoop.hbase.util.throttles.SizeBasedThrottlerInterface;
 
 /** An abstract IPC service.  IPC calls take a single {@link Writable} as a
  * parameter, and return a {@link Writable} as their value.  A service runs on
@@ -93,11 +96,7 @@ public abstract class HBaseServer {
 
   public static final byte CURRENT_VERSION = VERSION_RPCOPTIONS;
 
- /**
-  * How much memory do we want for the blocking queue
-  */
-  private static final int MAX_CALL_QUEUE_MEMORY_SIZE = 1024*1024*1024;
-  private SizeBasedThrottler callQueueThrottler;
+  private SizeBasedThrottlerInterface callQueueThrottler;
 
   public static final Log LOG = LogFactory.getLog(HBaseServer.class.getName());
 
@@ -1375,7 +1374,26 @@ public abstract class HBaseServer {
     this.handlerCount = handlerCount;
     this.socketSendBufferSize = 0;
     this.callQueue  = new LinkedBlockingQueue<RawCall>();
-    callQueueThrottler = new SizeBasedThrottler(MAX_CALL_QUEUE_MEMORY_SIZE);
+    long maxCallQueueMemorySize = conf.getLong(
+        HConstants.MAX_CALL_QUEUE_MEMORY_SIZE_STRING,
+        HConstants.MAX_CALL_QUEUE_MEMORY_SIZE);
+    long maxSmallerCallQueueMemorySize = conf.getLong(
+        HConstants.MAX_SMALLER_CALL_QUEUE_MEMORY_SIZE_STRING,
+        HConstants.MAX_SMALLER_CALL_QUEUE_MEMORY_SIZE);
+    long maxLargerCallQueueMemorySize = conf.getLong(
+        HConstants.MAX_LARGER_CALL_QUEUE_MEMORY_SIZE_STRING,
+        HConstants.MAX_LARGER_CALL_QUEUE_MEMORY_SIZE);
+    int smallQueueRequestLimit = conf.getInt(
+        HConstants.SMALL_QUEUE_REQUEST_LIMIT_STRING,
+        HConstants.SMALL_QUEUE_REQUEST_LIMIT);
+    if (conf.getBoolean(HConstants.USE_MULTIPLE_THROTTLES, false)) {
+      callQueueThrottler = new SizeBasedMultiThrottler(
+          maxSmallerCallQueueMemorySize,
+          maxLargerCallQueueMemorySize,
+          smallQueueRequestLimit);
+    } else {
+      callQueueThrottler = new SizeBasedThrottler(maxCallQueueMemorySize);
+    }
     this.maxIdleTime = 2*conf.getInt("ipc.client.connection.maxidletime", 1000);
     this.maxConnectionsToNuke = conf.getInt("ipc.client.kill.max", 10);
     this.thresholdIdleConnections = conf.getInt("ipc.client.idlethreshold", 4000);

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/SizeBasedThrottler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/SizeBasedThrottler.java?rev=1489991&r1=1489990&r2=1489991&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/SizeBasedThrottler.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/SizeBasedThrottler.java Wed Jun  5 18:18:26 2013
@@ -1,111 +0,0 @@
-package org.apache.hadoop.hbase.util;
-
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * Utility class that can be used to implement
- * queues with limited capacity (in terms of memory).
- * It maintains internal counter and provides
- * two operations: increase and decrease.
- * Increase blocks until internal counter is lower than
- * given threshold and then increases internal counter.
- * Decrease decreases internal counter and wakes up
- * waiting threads if counter is lower than threshold.
- *
- * This implementation allows you to set the value of internal
- * counter to be greater than threshold. It happens
- * when internal counter is lower than threshold and
- * increase method is called with parameter 'delta' big enough
- * so that sum of delta and internal counter is greater than
- * threshold. This is not a bug, this is a feature.
- * It solves some problems:
- *   - thread calling increase with big parameter will not be
- *     starved by other threads calling increase with small
- *     arguments.
- *   - thread calling increase with argument greater than
- *     threshold won't deadlock. This is useful when throttling
- *     queues - you can submit object that is bigger than limit.
- *
- * This implementation introduces small costs in terms of
- * synchronization (no synchronization in most cases at all).
- */
-public class SizeBasedThrottler {
-
-  private final long threshold;
-  private final AtomicLong currentSize;
-
-  /**
-   * Creates SizeBoundary with provided threshold
-   *
-   * @param threshold threshold used by instance
-   */
-  public SizeBasedThrottler(long threshold) {
-    if (threshold <= 0) {
-      throw new IllegalArgumentException("Treshold must be greater than 0");
-    }
-    this.threshold = threshold;
-    this.currentSize = new AtomicLong(0);
-  }
-
-  /**
-   * Blocks until internal counter is lower than threshold
-   * and then increases value of internal counter.
-   *
-   * Note that order in which increases will be granted is not guaranteed,
-   * i.e. some request can wait, while newer request are granted in the meantime
-   *
-   * @param delta increase internal counter by this value
-   * @return new value of internal counter
-   * @throws InterruptedException when interrupted during waiting
-   */
-  public long increase(long delta) throws InterruptedException{
-    while (true) {
-      long size = currentSize.get();
-      if (size >= threshold) {
-        synchronized (this) {
-          while ((size = currentSize.get()) >= threshold) {
-            wait();
-          }
-        }
-      }
-
-      if (currentSize.compareAndSet(size, size + delta)) {
-        return size + delta;
-      }
-    }
-  }
-
-
-  /**
-   * Decreases value of internal counter. Wakes up waiting threads if required.
-   *
-   * @param delta decrease internal counter by this value
-   * @return new value of internal counter
-   */
-  public long decrease(long delta) {
-    final long newSize = currentSize.addAndGet(-delta);
-
-    if (newSize < threshold && newSize + delta >= threshold) {
-      synchronized (this) {
-        notifyAll();
-      }
-    }
-
-    return newSize;
-  }
-
-  /**
-   *
-   * @return current value of internal counter
-   */
-  public long getCurrentValue(){
-    return currentSize.get();
-  }
-
-  /**
-   * @return threshold
-   */
-  public long getThreshold(){
-    return threshold;
-  }
-}

Added: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/SizeBasedMultiThrottler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/SizeBasedMultiThrottler.java?rev=1489991&view=auto
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/SizeBasedMultiThrottler.java (added)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/SizeBasedMultiThrottler.java Wed Jun  5 18:18:26 2013
@@ -0,0 +1,63 @@
+/**
+ * Copyright 2013 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hbase.util.throttles;
+
+public class SizeBasedMultiThrottler implements SizeBasedThrottlerInterface {
+  final long smallMax;
+  final SizeBasedThrottlerInterface smallerThrottler;
+  final SizeBasedThrottlerInterface largerThrottler;
+
+  public SizeBasedMultiThrottler(long smallerThreshold, long largerThreshold,
+      long smallMax) {
+    if (smallerThreshold <= 0 || largerThreshold <= 0) {
+      throw new IllegalArgumentException("Threshold must be greater than 0");
+    }
+    this.smallMax = smallMax;
+    this.smallerThrottler = new SizeBasedThrottler(smallerThreshold);
+    this.largerThrottler = new SizeBasedThrottler(largerThreshold);
+  }
+
+  private SizeBasedThrottlerInterface chooseThrottler(long delta) {
+    if (delta <= smallMax) {
+      return smallerThrottler;
+    } else {
+      return largerThrottler;
+    }
+  }
+
+  @Override
+  public long increase(long delta) throws InterruptedException {
+    chooseThrottler(delta).increase(delta);
+    return getCurrentValue();
+  }
+
+  @Override
+  public long decrease(long delta) {
+    chooseThrottler(delta).decrease(delta);
+    return getCurrentValue();
+  }
+
+  @Override
+  public long getCurrentValue() {
+    return smallerThrottler.getCurrentValue()
+        + largerThrottler.getCurrentValue();
+  }
+}

Copied: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/SizeBasedThrottler.java (from r1489990, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/SizeBasedThrottler.java)
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/SizeBasedThrottler.java?p2=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/SizeBasedThrottler.java&p1=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/SizeBasedThrottler.java&r1=1489990&r2=1489991&rev=1489991&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/SizeBasedThrottler.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/SizeBasedThrottler.java Wed Jun  5 18:18:26 2013
@@ -1,4 +1,23 @@
-package org.apache.hadoop.hbase.util;
+/**
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.util.throttles;
 
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -29,7 +48,7 @@ import java.util.concurrent.atomic.Atomi
  * This implementation introduces small costs in terms of
  * synchronization (no synchronization in most cases at all).
  */
-public class SizeBasedThrottler {
+public class SizeBasedThrottler implements SizeBasedThrottlerInterface{
 
   private final long threshold;
   private final AtomicLong currentSize;

Added: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/SizeBasedThrottlerInterface.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/SizeBasedThrottlerInterface.java?rev=1489991&view=auto
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/SizeBasedThrottlerInterface.java (added)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/throttles/SizeBasedThrottlerInterface.java Wed Jun  5 18:18:26 2013
@@ -0,0 +1,30 @@
+/**
+ * Copyright 2013 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hbase.util.throttles;
+
+public interface SizeBasedThrottlerInterface {
+  public long increase(long delta) throws InterruptedException;
+
+  public long decrease(long delta);
+
+  public long getCurrentValue();
+
+}

Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/util/TestSizeBasedThrottler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/util/TestSizeBasedThrottler.java?rev=1489991&r1=1489990&r2=1489991&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/util/TestSizeBasedThrottler.java (original)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/util/TestSizeBasedThrottler.java Wed Jun  5 18:18:26 2013
@@ -1,9 +1,30 @@
+/**
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.hadoop.hbase.util;
 
 import java.util.ArrayList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import org.apache.hadoop.hbase.util.throttles.SizeBasedThrottler;
 import org.junit.Test;
 import static org.junit.Assert.*;