| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,7 @@ public boolean isClosed() { | |||
| 32 | 32 | return counter.get() == CLOSED_VALUE; | |
| 33 | 33 | } | |
| 34 | 34 | ||
| 35 | + @Override | ||
| 35 | 36 | public RefCounterReleaser acquire() { | |
| 36 | 37 | final int newVal = | |
| 37 | 38 | counter.updateAndGet(currVal -> currVal == CLOSED_VALUE ? currVal : currVal + 1); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ public boolean isClosed() { | |||
| 33 | 33 | } | |
| 34 | 34 | } | |
| 35 | 35 | ||
| 36 | + @Override | ||
| 36 | 37 | public RefCounterReleaser acquire() { | |
| 37 | 38 | synchronized (this) { | |
| 38 | 39 | if (isClosed) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -129,7 +129,7 @@ private void populateDatabase(final Dbi<ByteBuffer> dbi) { | |||
| 129 | 129 | ||
| 130 | 130 | @Test | |
| 131 | 131 | void testPopulate() { | |
| 132 | - final Dbi<ByteBuffer> db = getDb(); | ||
| 132 | + getDb(); | ||
| 133 | 133 | } | |
| 134 | 134 | ||
| 135 | 135 | @Test | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,7 +45,7 @@ | |||
| 45 | 45 | public class RefCounterTest { | |
| 46 | 46 | private static final int PROCESSOR_COUNT = Runtime.getRuntime().availableProcessors(); | |
| 47 | 47 | private final int iterations = 20_000_000; | |
| 48 | - private final int threadCount = PROCESSOR_COUNT; | ||
| 48 | + private final int processorCount = PROCESSOR_COUNT; | ||
| 49 | 49 | ||
| 50 | 50 | /** | |
| 51 | 51 | * @return A {@link Stream} of all {@link RefCounter}s for {@link ParameterizedTest}s. | |
@@ -78,7 +78,7 @@ public void perfTest() { | |||
| 78 | 78 | final int round = i; | |
| 79 | 79 | // Run tests with all available processors | |
| 80 | 80 | System.out.println( | |
| 81 | - "Multi-threaded (" + threadCount + " threads) tests ---------------------------------"); | ||
| 81 | + "Multi-threaded (" + processorCount + " threads) tests ---------------------------------"); | ||
| 82 | 82 | ||
| 83 | 83 | System.out.println("Round: " + round + " " + StripedRefCounter.class.getSimpleName()); | |
| 84 | 84 | IntStream.of(1, 16, 32, 64, 128, 256) | |
@@ -208,17 +208,17 @@ void testRefCounters(final RefCounter refCounter) { | |||
| 208 | 208 | @MethodSource("multiThreadedRefCounterProvider") | |
| 209 | 209 | void multipleThreads(final RefCounter refCounter) { | |
| 210 | 210 | final int iterations = 1000; | |
| 211 | - final AtomicInteger[] callCounts = new AtomicInteger[threadCount]; | ||
| 212 | - for (int i = 0; i < threadCount; i++) { | ||
| 211 | + final AtomicInteger[] callCounts = new AtomicInteger[processorCount]; | ||
| 212 | + for (int i = 0; i < processorCount; i++) { | ||
| 213 | 213 | callCounts[i] = new AtomicInteger(); | |
| 214 | 214 | } | |
| 215 | - final CountDownLatch countDownLatch = new CountDownLatch(threadCount); | ||
| 215 | + final CountDownLatch countDownLatch = new CountDownLatch(processorCount); | ||
| 216 | 216 | //noinspection resource ExecutorService does not implement AutoCloseable in Java8 | |
| 217 | - final ExecutorService executorService = Executors.newFixedThreadPool(threadCount); | ||
| 217 | + final ExecutorService executorService = Executors.newFixedThreadPool(processorCount); | ||
| 218 | 218 | try { | |
| 219 | 219 | ||
| 220 | 220 | final CompletableFuture<?>[] futures = | |
| 221 | - IntStream.range(0, threadCount) | ||
| 221 | + IntStream.range(0, processorCount) | ||
| 222 | 222 | .boxed() | |
| 223 | 223 | .map( | |
| 224 | 224 | i -> | |
@@ -255,20 +255,20 @@ void multipleThreads_delayedRelease(final RefCounter refCounter) { | |||
| 255 | 255 | final Queue<RefCounter.RefCounterReleaser> releasers; | |
| 256 | 256 | ||
| 257 | 257 | //noinspection resource ExecutorService does not implement AutoCloseable in Java8 | |
| 258 | - final ExecutorService executorService = Executors.newFixedThreadPool(threadCount); | ||
| 259 | - final ExecutorService executorService2 = Executors.newFixedThreadPool(threadCount); | ||
| 258 | + final ExecutorService executorService = Executors.newFixedThreadPool(processorCount); | ||
| 259 | + final ExecutorService executorService2 = Executors.newFixedThreadPool(processorCount); | ||
| 260 | 260 | ||
| 261 | 261 | try { | |
| 262 | - callCounts = new AtomicInteger[threadCount]; | ||
| 263 | - for (int i = 0; i < threadCount; i++) { | ||
| 262 | + callCounts = new AtomicInteger[processorCount]; | ||
| 263 | + for (int i = 0; i < processorCount; i++) { | ||
| 264 | 264 | callCounts[i] = new AtomicInteger(); | |
| 265 | 265 | } | |
| 266 | - final CountDownLatch countDownLatch = new CountDownLatch(threadCount); | ||
| 266 | + final CountDownLatch countDownLatch = new CountDownLatch(processorCount); | ||
| 267 | 267 | ||
| 268 | 268 | releasers = new ConcurrentLinkedQueue<>(); | |
| 269 | 269 | final Queue<CompletableFuture<?>> futures = new ConcurrentLinkedQueue<>(); | |
| 270 | 270 | ||
| 271 | - IntStream.range(0, threadCount) | ||
| 271 | + IntStream.range(0, processorCount) | ||
| 272 | 272 | .boxed() | |
| 273 | 273 | .map( | |
| 274 | 274 | i -> | |
@@ -297,7 +297,7 @@ void multipleThreads_delayedRelease(final RefCounter refCounter) { | |||
| 297 | 297 | executorService.shutdown(); | |
| 298 | 298 | } | |
| 299 | 299 | ||
| 300 | - assertRefCount(refCounter, threadCount * iterations); | ||
| 300 | + assertRefCount(refCounter, processorCount * iterations); | ||
| 301 | 301 | ||
| 302 | 302 | for (AtomicInteger callCount : callCounts) { | |
| 303 | 303 | assertThat(callCount).hasValue(iterations); | |
@@ -338,7 +338,7 @@ void testImmediateClose(final RefCounter refCounter) { | |||
| 338 | 338 | @MethodSource("multiThreadedRefCounterProvider") | |
| 339 | 339 | void testBehaviour(final RefCounter refCounter) throws InterruptedException { | |
| 340 | 340 | final Random random = new Random(); | |
| 341 | - final int threadCount = this.threadCount - 1; | ||
| 341 | + final int threadCount = this.processorCount - 1; | ||
| 342 | 342 | //noinspection resource ExecutorService does not implement AutoCloseable in Java8 | |
| 343 | 343 | final ExecutorService executorService = Executors.newFixedThreadPool(threadCount); | |
| 344 | 344 | try { | |
@@ -347,7 +347,6 @@ void testBehaviour(final RefCounter refCounter) throws InterruptedException { | |||
| 347 | 347 | final AtomicReference<Object> mockEnv = new AtomicReference<>(); | |
| 348 | 348 | ||
| 349 | 349 | for (int k = 0; k < rounds; k++) { | |
| 350 | - final int round = k; | ||
| 351 | 350 | ||
| 352 | 351 | // Reset the env | |
| 353 | 352 | mockEnv.set(new Object()); | |
@@ -401,7 +400,6 @@ void testBehaviour(final RefCounter refCounter) throws InterruptedException { | |||
| 401 | 400 | // Give the other threads a chance to get underway | |
| 402 | 401 | TestUtils.sleep(200 + random.nextInt(200)); | |
| 403 | 402 | final AtomicBoolean didClose = new AtomicBoolean(false); | |
| 404 | - int closeCallCount = 0; | ||
| 405 | 403 | final AtomicInteger onCloseCallCount = new AtomicInteger(); | |
| 406 | 404 | while (!didClose.get()) { | |
| 407 | 405 | try { | |
@@ -450,7 +448,7 @@ void testBehaviour(final RefCounter refCounter) throws InterruptedException { | |||
| 450 | 448 | @MethodSource("multiThreadedRefCounterProvider") | |
| 451 | 449 | void testGetCount(final RefCounter refCounter) throws InterruptedException { | |
| 452 | 450 | final Random random = new Random(); | |
| 453 | - final int threadCount = this.threadCount - 1; | ||
| 451 | + final int threadCount = this.processorCount - 1; | ||
| 454 | 452 | //noinspection resource ExecutorService does not implement AutoCloseable in Java8 | |
| 455 | 453 | final ExecutorService executorService = Executors.newFixedThreadPool(threadCount); | |
| 456 | 454 | try { | |
@@ -599,13 +597,13 @@ public void noOpRefCounter() { | |||
| 599 | 597 | ||
| 600 | 598 | private void doNoOpRefCounter() { | |
| 601 | 599 | final AtomicReference<Instant> startTime = new AtomicReference<>(null); | |
| 602 | - final CompletableFuture<?>[] futures = new CompletableFuture[threadCount]; | ||
| 600 | + final CompletableFuture<?>[] futures = new CompletableFuture[processorCount]; | ||
| 603 | 601 | final NoOpRefCounter refCounter = new NoOpRefCounter(); | |
| 604 | - final CountDownLatch startLatch = new CountDownLatch(threadCount); | ||
| 605 | - final ExecutorService executorService = Executors.newFixedThreadPool(threadCount); | ||
| 602 | + final CountDownLatch startLatch = new CountDownLatch(processorCount); | ||
| 603 | + final ExecutorService executorService = Executors.newFixedThreadPool(processorCount); | ||
| 606 | 604 | try { | |
| 607 | - final int iterationsPerThread = iterations / threadCount; | ||
| 608 | - for (int i = 0; i < threadCount; i++) { | ||
| 605 | + final int iterationsPerThread = iterations / processorCount; | ||
| 606 | + for (int i = 0; i < processorCount; i++) { | ||
| 609 | 607 | futures[i] = | |
| 610 | 608 | CompletableFuture.runAsync( | |
| 611 | 609 | () -> { | |
@@ -632,9 +630,8 @@ private void doNoOpRefCounter() { | |||
| 632 | 630 | } | |
| 633 | 631 | CompletableFuture.allOf(futures).join(); | |
| 634 | 632 | ||
| 635 | - final Duration duration = Duration.between(startTime.get(), Instant.now()); | ||
| 636 | - final long iterationsPerSec = Math.round((double) iterations / duration.toMillis() * 1000); | ||
| 637 | - | ||
| 633 | + // final Duration duration = Duration.between(startTime.get(), Instant.now()); | ||
| 634 | + // final long iterationsPerSec = Math.round((double) iterations / duration.toMillis() * 1000); | ||
| 638 | 635 | // System.out.println( | |
| 639 | 636 | // "All Finished" | |
| 640 | 637 | // + ", threads: " | |
@@ -652,7 +649,7 @@ private void doNoOpRefCounter() { | |||
| 652 | 649 | } | |
| 653 | 650 | ||
| 654 | 651 | private void runPerfTest(int stripes, final RefCounter refCounter) { | |
| 655 | - runPerfTest(stripes, threadCount, refCounter); | ||
| 652 | + runPerfTest(stripes, processorCount, refCounter); | ||
| 656 | 653 | } | |
| 657 | 654 | ||
| 658 | 655 | private void runPerfTest(int stripes, final int threadCount, final RefCounter refCounter) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments