Skip to content

Commit

Permalink
Reduce initial writer buffer size to 4
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Apr 20, 2016
1 parent a84573b commit 1e6ec2d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ abstract class BoundedLocalCache<K, V> extends BLCHeader.DrainStatusRef<K, V>
/** 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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
* @author [email protected] (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 -------------- */

Expand Down Expand Up @@ -157,26 +157,26 @@ public void manyProducers_oneConsumer(WriteBuffer<Integer> 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<Integer> makePopulated(int size, int maximumSize) {
WriteBuffer<Integer> buffer = new WriteBuffer<>(4, maximumSize);
for (int i = 0; i < size; i++) {
static WriteBuffer<Integer> makePopulated(int items) {
WriteBuffer<Integer> buffer = new WriteBuffer<>(4, FULL_SIZE);
for (int i = 0; i < items; i++) {
buffer.offer(i);
}
return buffer;
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 comments on commit 1e6ec2d

@kibertoad
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for the change?..

@johnou
Copy link

@johnou johnou commented on 1e6ec2d Apr 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kibertoad I guess smaller memory footprint with no visible performance hit?

@ben-manes
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. It adds two quick resizes (4 -> 8 -> 16) if there is a high write rate (or burst of writes). If writes are relatively rare and scattered then it is unlikely to need to cope with many, so a smaller initial footprint seems friendlier.

Note that our usage is similar to a cpu's write buffer and write combining.

Please sign in to comment.