forked from ReactiveX/RxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue ReactiveX#12 TimeBasedRateLimiter and AtomicRateLimiter impleme…
…ntations + benchmarks
- Loading branch information
1 parent
5a30b38
commit bbfc98f
Showing
14 changed files
with
710 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/jmh/java/javaslang/circuitbreaker/30-Nov-2016-i7-I7-5557U-OSX-Java-1.8.0_112-x64.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Benchmark Mode Cnt Score Error Units | ||
|
||
RateLimiterBenchmark.atomicPermission thrpt 10 7.274 ± 0.132 ops/us | ||
RateLimiterBenchmark.semaphoreBasedPermission thrpt 10 17.335 ± 3.441 ops/us | ||
RateLimiterBenchmark.timeBasedPermission thrpt 10 3.522 ± 0.495 ops/us | ||
|
||
RateLimiterBenchmark.atomicPermission avgt 10 0.294 ± 0.038 us/op | ||
RateLimiterBenchmark.semaphoreBasedPermission avgt 10 0.120 ± 0.018 us/op | ||
RateLimiterBenchmark.timeBasedPermission avgt 10 0.562 ± 0.045 us/op | ||
|
||
RateLimiterBenchmark.atomicPermission sample 535765 1.480 ± 0.036 us/op | ||
RateLimiterBenchmark.atomicPermission:atomicPermission·p0.00 sample 0.040 us/op | ||
RateLimiterBenchmark.atomicPermission:atomicPermission·p0.50 sample 0.383 us/op | ||
RateLimiterBenchmark.atomicPermission:atomicPermission·p0.90 sample 4.288 us/op | ||
RateLimiterBenchmark.atomicPermission:atomicPermission·p0.95 sample 7.368 us/op | ||
RateLimiterBenchmark.atomicPermission:atomicPermission·p0.99 sample 14.080 us/op | ||
RateLimiterBenchmark.atomicPermission:atomicPermission·p0.999 sample 18.048 us/op | ||
RateLimiterBenchmark.atomicPermission:atomicPermission·p0.9999 sample 58.449 us/op | ||
RateLimiterBenchmark.atomicPermission:atomicPermission·p1.00 sample 1654.784 us/op | ||
RateLimiterBenchmark.semaphoreBasedPermission sample 635614 0.166 ± 0.010 us/op | ||
RateLimiterBenchmark.semaphoreBasedPermission:semaphoreBasedPermission·p0.00 sample 0.001 us/op | ||
RateLimiterBenchmark.semaphoreBasedPermission:semaphoreBasedPermission·p0.50 sample 0.135 us/op | ||
RateLimiterBenchmark.semaphoreBasedPermission:semaphoreBasedPermission·p0.90 sample 0.219 us/op | ||
RateLimiterBenchmark.semaphoreBasedPermission:semaphoreBasedPermission·p0.95 sample 0.236 us/op | ||
RateLimiterBenchmark.semaphoreBasedPermission:semaphoreBasedPermission·p0.99 sample 0.333 us/op | ||
RateLimiterBenchmark.semaphoreBasedPermission:semaphoreBasedPermission·p0.999 sample 2.468 us/op | ||
RateLimiterBenchmark.semaphoreBasedPermission:semaphoreBasedPermission·p0.9999 sample 15.519 us/op | ||
RateLimiterBenchmark.semaphoreBasedPermission:semaphoreBasedPermission·p1.00 sample 1372.160 us/op | ||
RateLimiterBenchmark.timeBasedPermission sample 553560 0.800 ± 0.053 us/op | ||
RateLimiterBenchmark.timeBasedPermission:timeBasedPermission·p0.00 sample 0.054 us/op | ||
RateLimiterBenchmark.timeBasedPermission:timeBasedPermission·p0.50 sample 0.550 us/op | ||
RateLimiterBenchmark.timeBasedPermission:timeBasedPermission·p0.90 sample 0.749 us/op | ||
RateLimiterBenchmark.timeBasedPermission:timeBasedPermission·p0.95 sample 0.826 us/op | ||
RateLimiterBenchmark.timeBasedPermission:timeBasedPermission·p0.99 sample 8.256 us/op | ||
RateLimiterBenchmark.timeBasedPermission:timeBasedPermission·p0.999 sample 33.920 us/op | ||
RateLimiterBenchmark.timeBasedPermission:timeBasedPermission·p0.9999 sample 160.221 us/op | ||
RateLimiterBenchmark.timeBasedPermission:timeBasedPermission·p1.00 sample 5742.592 us/op | ||
|
||
RateLimiterBenchmark.atomicPermission ss 10 17.140 ± 5.640 us/op | ||
RateLimiterBenchmark.semaphoreBasedPermission ss 10 9.724 ± 4.602 us/op | ||
RateLimiterBenchmark.timeBasedPermission ss 10 26.875 ± 10.869 us/op |
89 changes: 89 additions & 0 deletions
89
src/jmh/java/javaslang/circuitbreaker/RateLimiterBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package javaslang.circuitbreaker; | ||
|
||
import javaslang.ratelimiter.RateLimiter; | ||
import javaslang.ratelimiter.RateLimiterConfig; | ||
import javaslang.ratelimiter.internal.AtomicRateLimiter; | ||
import javaslang.ratelimiter.internal.SemaphoreBasedRateLimiter; | ||
import javaslang.ratelimiter.internal.TimeBasedRateLimiter; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Threads; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Supplier; | ||
|
||
@State(Scope.Benchmark) | ||
@OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
@BenchmarkMode(Mode.All) | ||
public class RateLimiterBenchmark { | ||
|
||
public static final int FORK_COUNT = 2; | ||
private static final int WARMUP_COUNT = 10; | ||
private static final int ITERATION_COUNT = 5; | ||
private static final int THREAD_COUNT = 2; | ||
|
||
private RateLimiter semaphoreBasedRateLimiter; | ||
private RateLimiter timeBasedRateLimiter; | ||
private RateLimiter atomicRateLimiter; | ||
|
||
private Supplier<String> semaphoreGuardedSupplier; | ||
private Supplier<String> timeGuardedSupplier; | ||
private Supplier<String> atomicGuardedSupplier; | ||
|
||
@Setup | ||
public void setUp() { | ||
RateLimiterConfig rateLimiterConfig = RateLimiterConfig.builder() | ||
.limitForPeriod(Integer.MAX_VALUE) | ||
.limitRefreshPeriod(Duration.ofNanos(10)) | ||
.timeoutDuration(Duration.ofSeconds(5)) | ||
.build(); | ||
semaphoreBasedRateLimiter = new SemaphoreBasedRateLimiter("semaphoreBased", rateLimiterConfig); | ||
timeBasedRateLimiter = new TimeBasedRateLimiter("timeBased", rateLimiterConfig); | ||
atomicRateLimiter = new AtomicRateLimiter("atomicBased", rateLimiterConfig); | ||
|
||
Supplier<String> stringSupplier = () -> { | ||
Blackhole.consumeCPU(1); | ||
return "Hello Benchmark"; | ||
}; | ||
semaphoreGuardedSupplier = RateLimiter.decorateSupplier(semaphoreBasedRateLimiter, stringSupplier); | ||
timeGuardedSupplier = RateLimiter.decorateSupplier(timeBasedRateLimiter, stringSupplier); | ||
atomicGuardedSupplier = RateLimiter.decorateSupplier(atomicRateLimiter, stringSupplier); | ||
} | ||
|
||
@Benchmark | ||
@Threads(value = THREAD_COUNT) | ||
@Warmup(iterations = WARMUP_COUNT) | ||
@Fork(value = FORK_COUNT) | ||
@Measurement(iterations = ITERATION_COUNT) | ||
public String semaphoreBasedPermission() { | ||
return semaphoreGuardedSupplier.get(); | ||
} | ||
|
||
@Benchmark | ||
@Threads(value = THREAD_COUNT) | ||
@Warmup(iterations = WARMUP_COUNT) | ||
@Fork(value = FORK_COUNT) | ||
@Measurement(iterations = ITERATION_COUNT) | ||
public String timeBasedPermission() { | ||
return timeGuardedSupplier.get(); | ||
} | ||
|
||
@Benchmark | ||
@Threads(value = THREAD_COUNT) | ||
@Warmup(iterations = WARMUP_COUNT) | ||
@Fork(value = FORK_COUNT) | ||
@Measurement(iterations = ITERATION_COUNT) | ||
public String atomicPermission() { | ||
return atomicGuardedSupplier.get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.