From 1e6ec2d1e1f43c296479773919f871bda03b5821 Mon Sep 17 00:00:00 2001 From: Ben Manes Date: Tue, 19 Apr 2016 18:42:47 -0700 Subject: [PATCH] Reduce initial writer buffer size to 4 --- .../caffeine/cache/BoundedLocalCache.java | 2 +- .../caffeine/cache/WriteBufferTest.java | 18 +++++++++--------- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java index be10b575d8..3b31dfdc50 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java @@ -133,7 +133,7 @@ abstract class BoundedLocalCache extends BLCHeader.DrainStatusRef /** The number of CPUs */ static final int NCPU = Runtime.getRuntime().availableProcessors(); /** The initial capacity of the write buffer. */ - static final int WRITE_BUFFER_MIN = 16; + static final int WRITE_BUFFER_MIN = 4; /** The maximum capacity of the write buffer. */ static final int WRITE_BUFFER_MAX = 128 * ceilingNextPowerOfTwo(NCPU); /** The number of attempts to insert into the write buffer before yielding. */ diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/WriteBufferTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/WriteBufferTest.java index d1aec64ac8..17108fe298 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/WriteBufferTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/WriteBufferTest.java @@ -32,11 +32,11 @@ * @author ben.manes@gmail.com (Ben Manes) */ public final class WriteBufferTest { - private static final int PRODUCE = 10_000; private static final int NUM_PRODUCERS = 10; + private static final int PRODUCE = 100; private static final int POPULATED_SIZE = 10; - private static final int FULL_SIZE = 16; + private static final int FULL_SIZE = 32; /* ---------------- Size -------------- */ @@ -157,26 +157,26 @@ public void manyProducers_oneConsumer(WriteBuffer buffer) { assertThat(buffer.size(), is(0)); } - /* ---------------- buffer providers -------------- */ + /* ---------------- Providers -------------- */ @DataProvider(name = "empty") public Object[][] providesEmpty() { - return new Object[][] {{ makePopulated(0, FULL_SIZE) }}; + return new Object[][] {{ makePopulated(0) }}; } @DataProvider(name = "populated") public Object[][] providesPopulated() { - return new Object[][] {{ makePopulated(POPULATED_SIZE, FULL_SIZE) }}; + return new Object[][] {{ makePopulated(POPULATED_SIZE) }}; } @DataProvider(name = "full") public Object[][] providesFull() { - return new Object[][] {{ makePopulated(FULL_SIZE, FULL_SIZE) }}; + return new Object[][] {{ makePopulated(FULL_SIZE) }}; } - static WriteBuffer makePopulated(int size, int maximumSize) { - WriteBuffer buffer = new WriteBuffer<>(4, maximumSize); - for (int i = 0; i < size; i++) { + static WriteBuffer makePopulated(int items) { + WriteBuffer buffer = new WriteBuffer<>(4, FULL_SIZE); + for (int i = 0; i < items; i++) { buffer.offer(i); } return buffer; diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9e773a71ad..d4eb7d0f13 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-rc-1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-rc-2-bin.zip