Examples of ThrottleSemaphore


Examples of net.sf.katta.util.ThrottledInputStream.ThrottleSemaphore

    LOG.info("local shard folder: " + shardsFolder.getAbsolutePath());
    int throttleInKbPerSec = _nodeConf.getShardDeployThrottle();
    final ShardManager shardManager;
    if (throttleInKbPerSec > 0) {
      LOG.info("throtteling of shard deployment to " + throttleInKbPerSec + " kilo-bytes per second");
      shardManager = new ShardManager(shardsFolder, new ThrottleSemaphore(throttleInKbPerSec * 1024));
    } else {
      shardManager = new ShardManager(shardsFolder);
    }
    _context = new NodeContext(_protocol, this, shardManager, _contentServer);
    _protocol.registerComponent(this);
View Full Code Here

Examples of net.sf.katta.util.ThrottledInputStream.ThrottleSemaphore

    long bytesPerSec = fileLength / durationInSec;
    printResults(fileLength, durationInSec, bytesPerSec);

    // now do the same throttled to half speed
    shardManager.uninstallShard(shardName);
    shardManager = new ShardManager(managerFolder, new ThrottleSemaphore(bytesPerSec / 3));
    startTime = System.currentTimeMillis();
    shardManager.installShard(shardName, _testFile.getAbsolutePath());
    durationInSec = (System.currentTimeMillis() - startTime) / 1000;
    long bytesPerSec2 = fileLength / durationInSec;
    printResults(fileLength, durationInSec, bytesPerSec2);
View Full Code Here

Examples of net.sf.katta.util.ThrottledInputStream.ThrottleSemaphore

  private static final int READ_TIME = 2000;

  @Test()
  public void testThrottleSemaphore() throws Exception {
    int bytesPerSecond = 30000;
    final ThrottleSemaphore semaphore = new ThrottleSemaphore(bytesPerSecond);
    Thread[] threads = new Thread[3];
    final AtomicInteger totalAquiredBytes = new AtomicInteger();
    final List<String> errors = new ArrayList<String>();
    long time = System.currentTimeMillis();
    for (int i = 0; i < threads.length; i++) {
      threads[i] = new Thread() {
        public void run() {
          try {
            int mbPerThread = 1;
            for (int i = 0; i < mbPerThread * 256; i++) {
              int acquireBytes;
              acquireBytes = semaphore.aquireBytes(4096);
              totalAquiredBytes.addAndGet(acquireBytes);
              // System.out.println(getName() + "[" + i + "]: " + acquireBytes);
              if (acquireBytes <= 0) {
                errors.add("acquired bytes incorrect " + acquireBytes);
              }
View Full Code Here

Examples of net.sf.katta.util.ThrottledInputStream.ThrottleSemaphore

  @Test(timeout = 10000)
  public void testThrottleReadFromMultipleInputStreams() throws Exception {
    long expectedReadTime = READ_TIME;
    int bytesPerSecond = 5000;
    ThrottleSemaphore semaphore = new ThrottleSemaphore(bytesPerSecond);
    ThrottledInputStream throttledInputStream1 = new ThrottledInputStream(new EndlessFastInputStream(), semaphore);
    ThrottledInputStream throttledInputStream2 = new ThrottledInputStream(new EndlessFastInputStream(), semaphore);

    ReadThread readThread1 = new ReadThread(throttledInputStream1, true);
    ReadThread readThread2 = new ReadThread(throttledInputStream2, true);
View Full Code Here

Examples of net.sf.katta.util.ThrottledInputStream.ThrottleSemaphore

  }

  private ReadThread checkThrottledRead(long expectedReadTime, int bytesPerSecond, boolean readWithBuffer)
          throws InterruptedException {
    ThrottledInputStream throttledInputStream = new ThrottledInputStream(new EndlessFastInputStream(),
            new ThrottleSemaphore(bytesPerSecond));
    ReadThread readThread = new ReadThread(throttledInputStream, readWithBuffer);
    readThread.start();
    readThread.join(expectedReadTime);

    readThread.interrupt();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.