@Test @Ignore public void multipleConcurrentRequests() { concurrentRequestScheduler(10); }
public ConcurrentRequestScheduler(final int concurrentRequests, final double rampup, final TimeUnit rampupUnit) { checkArgument(concurrentRequests > 0, "concurrentRequests must be > 0"); checkArgument(rampup >= 0.0, "rampup must be >= 0.0 [%s]", rampup); checkNotNull(rampupUnit); this.concurrentRequests = concurrentRequests; this.rampup = rampup; this.rampupUnit = rampupUnit; this.started = new CountDownLatch(1); if (DoubleMath.fuzzyEquals(rampup, 0.0, Math.pow(0.1, 6))) { this.permits = new Semaphore(concurrentRequests); } else { this.permits = new Semaphore(0); final Thread rampupThread = new Thread(new Runnable() { @Override public void run() { final double rampSeconds = (rampup * rampupUnit.toNanos(1)) / TimeUnit.SECONDS.toNanos(1); _logger.debug("Ramp seconds [{}]", rampSeconds); final RateLimiter ramp = RateLimiter.create(concurrentRequests / rampSeconds); _logger.debug("Ramp rate [{}]", ramp.getRate()); _logger.debug("Awaiting start latch"); Uninterruptibles.awaitUninterruptibly(ConcurrentRequestScheduler.this.started); _logger.info("Starting ramp"); for (int i = 0; i < concurrentRequests; i++) { _logger.debug("Acquiring RateLimiter permit"); ramp.acquire(); _logger.debug("Releasing semaphore permit"); ConcurrentRequestScheduler.this.permits.release(); } _logger.info("Finished ramp"); } }, "concurrent-scheduler-ramp"); rampupThread.setDaemon(true); rampupThread.start(); _logger.debug("Starting permits [{}]", this.permits.availablePermits()); } }
ConcurrentRequestScheduler implements Scheduler { public ConcurrentRequestScheduler(final int concurrentRequests, final double rampup, final TimeUnit rampupUnit) { checkArgument(concurrentRequests > 0, "concurrentRequests must be > 0"); checkArgument(rampup >= 0.0, "rampup must be >= 0.0 [%s]", rampup); checkNotNull(rampupUnit); this.concurrentRequests = concurrentRequests; this.rampup = rampup; this.rampupUnit = rampupUnit; this.started = new CountDownLatch(1); if (DoubleMath.fuzzyEquals(rampup, 0.0, Math.pow(0.1, 6))) { this.permits = new Semaphore(concurrentRequests); } else { this.permits = new Semaphore(0); final Thread rampupThread = new Thread(new Runnable() { @Override public void run() { final double rampSeconds = (rampup * rampupUnit.toNanos(1)) / TimeUnit.SECONDS.toNanos(1); _logger.debug("Ramp seconds [{}]", rampSeconds); final RateLimiter ramp = RateLimiter.create(concurrentRequests / rampSeconds); _logger.debug("Ramp rate [{}]", ramp.getRate()); _logger.debug("Awaiting start latch"); Uninterruptibles.awaitUninterruptibly(ConcurrentRequestScheduler.this.started); _logger.info("Starting ramp"); for (int i = 0; i < concurrentRequests; i++) { _logger.debug("Acquiring RateLimiter permit"); ramp.acquire(); _logger.debug("Releasing semaphore permit"); ConcurrentRequestScheduler.this.permits.release(); } _logger.info("Finished ramp"); } }, "concurrent-scheduler-ramp"); rampupThread.setDaemon(true); rampupThread.start(); _logger.debug("Starting permits [{}]", this.permits.availablePermits()); } } }
ConcurrentRequestScheduler implements Scheduler { public ConcurrentRequestScheduler(final int concurrentRequests, final double rampup, final TimeUnit rampupUnit) { checkArgument(concurrentRequests > 0, "concurrentRequests must be > 0"); checkArgument(rampup >= 0.0, "rampup must be >= 0.0 [%s]", rampup); checkNotNull(rampupUnit); this.concurrentRequests = concurrentRequests; this.rampup = rampup; this.rampupUnit = rampupUnit; this.started = new CountDownLatch(1); if (DoubleMath.fuzzyEquals(rampup, 0.0, Math.pow(0.1, 6))) { this.permits = new Semaphore(concurrentRequests); } else { this.permits = new Semaphore(0); final Thread rampupThread = new Thread(new Runnable() { @Override public void run() { final double rampSeconds = (rampup * rampupUnit.toNanos(1)) / TimeUnit.SECONDS.toNanos(1); _logger.debug("Ramp seconds [{}]", rampSeconds); final RateLimiter ramp = RateLimiter.create(concurrentRequests / rampSeconds); _logger.debug("Ramp rate [{}]", ramp.getRate()); _logger.debug("Awaiting start latch"); Uninterruptibles.awaitUninterruptibly(ConcurrentRequestScheduler.this.started); _logger.info("Starting ramp"); for (int i = 0; i < concurrentRequests; i++) { _logger.debug("Acquiring RateLimiter permit"); ramp.acquire(); _logger.debug("Releasing semaphore permit"); ConcurrentRequestScheduler.this.permits.release(); } _logger.info("Finished ramp"); } }, "concurrent-scheduler-ramp"); rampupThread.setDaemon(true); rampupThread.start(); _logger.debug("Starting permits [{}]", this.permits.availablePermits()); } } ConcurrentRequestScheduler(final int concurrentRequests, final double rampup,
      final TimeUnit rampupUnit); }
ConcurrentRequestScheduler implements Scheduler { public ConcurrentRequestScheduler(final int concurrentRequests, final double rampup, final TimeUnit rampupUnit) { checkArgument(concurrentRequests > 0, "concurrentRequests must be > 0"); checkArgument(rampup >= 0.0, "rampup must be >= 0.0 [%s]", rampup); checkNotNull(rampupUnit); this.concurrentRequests = concurrentRequests; this.rampup = rampup; this.rampupUnit = rampupUnit; this.started = new CountDownLatch(1); if (DoubleMath.fuzzyEquals(rampup, 0.0, Math.pow(0.1, 6))) { this.permits = new Semaphore(concurrentRequests); } else { this.permits = new Semaphore(0); final Thread rampupThread = new Thread(new Runnable() { @Override public void run() { final double rampSeconds = (rampup * rampupUnit.toNanos(1)) / TimeUnit.SECONDS.toNanos(1); _logger.debug("Ramp seconds [{}]", rampSeconds); final RateLimiter ramp = RateLimiter.create(concurrentRequests / rampSeconds); _logger.debug("Ramp rate [{}]", ramp.getRate()); _logger.debug("Awaiting start latch"); Uninterruptibles.awaitUninterruptibly(ConcurrentRequestScheduler.this.started); _logger.info("Starting ramp"); for (int i = 0; i < concurrentRequests; i++) { _logger.debug("Acquiring RateLimiter permit"); ramp.acquire(); _logger.debug("Releasing semaphore permit"); ConcurrentRequestScheduler.this.permits.release(); } _logger.info("Finished ramp"); } }, "concurrent-scheduler-ramp"); rampupThread.setDaemon(true); rampupThread.start(); _logger.debug("Starting permits [{}]", this.permits.availablePermits()); } } ConcurrentRequestScheduler(final int concurrentRequests, final double rampup,
      final TimeUnit rampupUnit); @Override void schedule(); @Override void complete(); @Override String toString(); }
ConcurrentRequestScheduler implements Scheduler { public ConcurrentRequestScheduler(final int concurrentRequests, final double rampup, final TimeUnit rampupUnit) { checkArgument(concurrentRequests > 0, "concurrentRequests must be > 0"); checkArgument(rampup >= 0.0, "rampup must be >= 0.0 [%s]", rampup); checkNotNull(rampupUnit); this.concurrentRequests = concurrentRequests; this.rampup = rampup; this.rampupUnit = rampupUnit; this.started = new CountDownLatch(1); if (DoubleMath.fuzzyEquals(rampup, 0.0, Math.pow(0.1, 6))) { this.permits = new Semaphore(concurrentRequests); } else { this.permits = new Semaphore(0); final Thread rampupThread = new Thread(new Runnable() { @Override public void run() { final double rampSeconds = (rampup * rampupUnit.toNanos(1)) / TimeUnit.SECONDS.toNanos(1); _logger.debug("Ramp seconds [{}]", rampSeconds); final RateLimiter ramp = RateLimiter.create(concurrentRequests / rampSeconds); _logger.debug("Ramp rate [{}]", ramp.getRate()); _logger.debug("Awaiting start latch"); Uninterruptibles.awaitUninterruptibly(ConcurrentRequestScheduler.this.started); _logger.info("Starting ramp"); for (int i = 0; i < concurrentRequests; i++) { _logger.debug("Acquiring RateLimiter permit"); ramp.acquire(); _logger.debug("Releasing semaphore permit"); ConcurrentRequestScheduler.this.permits.release(); } _logger.info("Finished ramp"); } }, "concurrent-scheduler-ramp"); rampupThread.setDaemon(true); rampupThread.start(); _logger.debug("Starting permits [{}]", this.permits.availablePermits()); } } ConcurrentRequestScheduler(final int concurrentRequests, final double rampup,
      final TimeUnit rampupUnit); @Override void schedule(); @Override void complete(); @Override String toString();  }