Package org.apache.lucene.store.RateLimiter

Examples of org.apache.lucene.store.RateLimiter.SimpleRateLimiter


* Simple testcase for RateLimiter.SimpleRateLimiter
*/
public final class TestRateLimiter extends LuceneTestCase {

  public void testPause() {
    SimpleRateLimiter limiter = new SimpleRateLimiter(10); // 10 MB / Sec
    limiter.pause(2);//init
    long pause = 0;
    for (int i = 0; i < 3; i++) {
      pause += limiter.pause(4 * 1024 * 1024); // fire up 3 * 4 MB
    }
    final long convert = TimeUnit.MILLISECONDS.convert(pause, TimeUnit.NANOSECONDS);
    assertTrue("we should sleep less than 2 seconds but did: " + convert + " millis", convert < 2000l);
    assertTrue("we should sleep at least 1 second but did only: " + convert + " millis", convert > 1000l);
  }
View Full Code Here


  }

  public void testThreads() throws Exception {

    double targetMBPerSec = 10.0 + 20 * random().nextDouble();
    final SimpleRateLimiter limiter = new SimpleRateLimiter(targetMBPerSec);

    final CountDownLatch startingGun = new CountDownLatch(1);

    Thread[] threads = new Thread[TestUtil.nextInt(random(), 3, 6)];
    final AtomicLong totBytes = new AtomicLong();
    for(int i=0;i<threads.length;i++) {
      threads[i] = new Thread() {
          @Override
          public void run() {
            try {
              startingGun.await();
            } catch (InterruptedException ie) {
              throw new ThreadInterruptedException(ie);
            }
            long bytesSinceLastPause = 0;
            for(int i=0;i<500;i++) {
              long numBytes = TestUtil.nextInt(random(), 1000, 10000);
              totBytes.addAndGet(numBytes);
              bytesSinceLastPause += numBytes;
              if (bytesSinceLastPause > limiter.getMinPauseCheckBytes()) {
                limiter.pause(bytesSinceLastPause);
                bytesSinceLastPause = 0;
              }
            }
          }
        };
View Full Code Here

* Simple testcase for RateLimiter.SimpleRateLimiter
*/
public final class TestRateLimiter extends LuceneTestCase {

  public void testPause() {
    SimpleRateLimiter limiter = new SimpleRateLimiter(10); // 10 MB / Sec
    limiter.pause(2);//init
    long pause = 0;
    for (int i = 0; i < 3; i++) {
      pause += limiter.pause(4 * 1024 * 1024); // fire up 3 * 4 MB
    }
    final long convert = TimeUnit.MILLISECONDS.convert(pause, TimeUnit.NANOSECONDS);
    assertTrue("we should sleep less than 2 seconds but did: " + convert + " millis", convert < 2000l);
    assertTrue("we should sleep at least 1 second but did only: " + convert + " millis", convert > 1000l);
  }
View Full Code Here

        this.maxBytesPerSec = componentSettings.getAsBytesSize("max_bytes_per_sec", componentSettings.getAsBytesSize("max_size_per_sec", new ByteSizeValue(20, ByteSizeUnit.MB)));
        if (maxBytesPerSec.bytes() <= 0) {
            rateLimiter = null;
        } else {
            rateLimiter = new SimpleRateLimiter(maxBytesPerSec.mbFrac());
        }

        logger.debug("using max_bytes_per_sec[{}], concurrent_streams [{}], file_chunk_size [{}], translog_size [{}], translog_ops [{}], and compress [{}]",
                maxBytesPerSec, concurrentStreams, fileChunkSize, translogSize, translogOps, compress);
View Full Code Here

                if (maxSizePerSec.bytes() <= 0) {
                    rateLimiter = null;
                } else if (rateLimiter != null) {
                    rateLimiter.setMbPerSec(maxSizePerSec.mbFrac());
                } else {
                    rateLimiter = new SimpleRateLimiter(maxSizePerSec.mbFrac());
                }
            }

            ByteSizeValue fileChunkSize = settings.getAsBytesSize(INDICES_RECOVERY_FILE_CHUNK_SIZE, RecoverySettings.this.fileChunkSize);
            if (!fileChunkSize.equals(RecoverySettings.this.fileChunkSize)) {
View Full Code Here

TOP

Related Classes of org.apache.lucene.store.RateLimiter.SimpleRateLimiter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.