lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sim...@apache.org
Subject svn commit: r1167353 - in /lucene/dev/trunk/lucene/src/java/org/apache/lucene/store: FSDirectory.java RateLimiter.java
Date Fri, 09 Sep 2011 20:35:39 GMT
Author: simonw
Date: Fri Sep  9 20:35:38 2011
New Revision: 1167353

URL: http://svn.apache.org/viewvc?rev=1167353&view=rev
Log:
LUCENE-3416: Allow to pass an instance of RateLimiter to FSDirectory allowing to rate limit
merge IO across several directories / instances

Modified:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/FSDirectory.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RateLimiter.java

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/FSDirectory.java?rev=1167353&r1=1167352&r2=1167353&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/FSDirectory.java Fri Sep  9 20:35:38
2011
@@ -123,8 +123,7 @@ public abstract class FSDirectory extend
   private int chunkSize = DEFAULT_READ_CHUNK_SIZE; // LUCENE-1566
 
   // null means no limite
-  private Double maxMergeWriteMBPerSec;
-  private RateLimiter mergeWriteRateLimiter;
+  private volatile RateLimiter mergeWriteRateLimiter;
 
   // returns the canonical version of the directory, creating it if it doesn't exist.
   private static File getCanonicalPath(File file) throws IOException {
@@ -305,25 +304,40 @@ public abstract class FSDirectory extend
    *  only apply for certain to new merges.
    *
    * @lucene.experimental */
-  public synchronized void setMaxMergeWriteMBPerSec(Double mbPerSec) {
-    maxMergeWriteMBPerSec = mbPerSec;
+  public void setMaxMergeWriteMBPerSec(Double mbPerSec) {
+    RateLimiter limiter = mergeWriteRateLimiter;
     if (mbPerSec == null) {
-      if (mergeWriteRateLimiter != null) {
-        mergeWriteRateLimiter.setMaxRate(Double.MAX_VALUE);
+      if (limiter != null) {
+        limiter.setMbPerSec(Double.MAX_VALUE);
         mergeWriteRateLimiter = null;
       }
-    } else if (mergeWriteRateLimiter != null) {
-      mergeWriteRateLimiter.setMaxRate(mbPerSec);
+    } else if (limiter != null) {
+      limiter.setMbPerSec(mbPerSec);
     } else {
       mergeWriteRateLimiter = new RateLimiter(mbPerSec);
     }
   }
 
+  /**
+   * Sets the rate limiter to be used to limit (approx) MB/sec allowed
+   * by all IO performed when merging. Pass null to have no limit.
+   *
+   * <p>Passing an instance of rate limiter compared to setting it using
+   * {@link #setMaxMergeWriteMBPerSec(Double)} allows to use the same limiter
+   * instance across several directories globally limiting IO when merging
+   * across them.
+   *
+   * @lucene.experimental */
+  public void setMaxMergeWriteLimiter(RateLimiter mergeWriteRateLimiter) {
+    this.mergeWriteRateLimiter = mergeWriteRateLimiter;
+  }
+
   /** See {@link #setMaxMergeWriteMBPerSec}.
    *
    * @lucene.experimental */
   public Double getMaxMergeWriteMBPerSec() {
-    return maxMergeWriteMBPerSec;
+    RateLimiter limiter = mergeWriteRateLimiter;
+    return limiter == null ? null : limiter.getMbPerSec();
   }
 
   protected void ensureCanWrite(String name) throws IOException {

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RateLimiter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RateLimiter.java?rev=1167353&r1=1167352&r2=1167353&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RateLimiter.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RateLimiter.java Fri Sep  9 20:35:38
2011
@@ -26,6 +26,7 @@ import org.apache.lucene.util.ThreadInte
  *  want to read bytes or write bytes. */
 
 public class RateLimiter {
+  private volatile double mbPerSec;
   private volatile double nsPerByte;
   private volatile long lastNS;
 
@@ -35,13 +36,24 @@ public class RateLimiter {
 
   /** mbPerSec is the MB/sec max IO rate */
   public RateLimiter(double mbPerSec) {
-    setMaxRate(mbPerSec);
+    setMbPerSec(mbPerSec);
   }
 
-  public void setMaxRate(double mbPerSec) {
+  /**
+   * Sets an updated mb per second rate limit.
+   */
+  public void setMbPerSec(double mbPerSec) {
+    this.mbPerSec = mbPerSec;
     nsPerByte = 1000000000. / (1024*1024*mbPerSec);
   }
 
+  /**
+   * The current mb per second rate limit.
+   */
+  public double getMbPerSec() {
+    return this.mbPerSec;
+  }
+
   /** Pauses, if necessary, to keep the instantaneous IO
    *  rate at or below the target. NOTE: multiple threads
    *  may safely use this, however the implementation is



Mime
View raw message