You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2019/08/07 12:54:29 UTC

[GitHub] [hbase] Apache9 commented on a change in pull request #343: HBASE-22634 : Improve performance of BufferedMutator

Apache9 commented on a change in pull request #343: HBASE-22634 : Improve performance of BufferedMutator	
URL: https://github.com/apache/hbase/pull/343#discussion_r311535313
 
 

 ##########
 File path: hbase-client/src/main/java/org/apache/hadoop/hbase/client/BufferedMutatorImpl.java
 ##########
 @@ -302,11 +348,53 @@ private void doFlush(boolean flushAll) throws InterruptedIOException,
         }
         asf = ap.submit(createTask(access));
       }
-      // DON'T do the wait in the try-with-resources. Otherwise, the undealt mutations won't
-      // be released.
-      asf.waitUntilDone();
-      if (asf.hasError()) {
-        errors.add(asf.getErrors());
+
+      if (flushAll || writeBufferSize == 0) {
+        // if we have setWriteBufferPeriodicFlushTimeoutMs we may have concurrent update
+        List<AsyncRequestFuture> waitList;
+        synchronized(asfList) {
+          waitList = new ArrayList<>(asfList);
+        }
+        // DON'T do the wait in the try-with-resources. Otherwise, the undealt mutations won't
+        // be released.
+        for(AsyncRequestFuture toWait:waitList) {
+          toWait.waitUntilDone();
+          if (toWait.hasError()) {
+            errors.add(toWait.getErrors());
+          }
+        }
+        synchronized(asfList) {
+          asfList.removeAll(waitList);
+        }
+        asf.waitUntilDone();
+        if (asf.hasError()) {
+          errors.add(asf.getErrors());
+        }
+      } else {
+        // Do some cleanup in asfList to decrease memory
+        int nbRemoved = 0;
+        while (asfList.size() >= maxThreads*4) {
+          synchronized(asfList) {
+            Iterator<AsyncRequestFuture> it = asfList.iterator();
+            while (it.hasNext()) {
+              AsyncRequestFutureImpl toCheck = (AsyncRequestFutureImpl) it.next();
+              if (toCheck.isFinished()) {
+                it.remove();
+                nbRemoved++;
+              }
+            }
+            if (nbRemoved == 0) {
+              try {
+                Thread.sleep(1);
 
 Review comment:
   So this means we will do a busy waiting here? This is not always the best choice, maybe we should provide a configurable way to wait here, the default one should be the typical wait/notify, and if do not care wasting the CPU cycles but only want the maximum throughput, you can use busy waiting.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services