-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce initial writer buffer size to 4
- Loading branch information
Showing
3 changed files
with
11 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 -------------- */ | ||
|
||
|
@@ -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; | ||
|
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
1e6ec2d
There was a problem hiding this comment.
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?..
1e6ec2d
There was a problem hiding this comment.
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?
1e6ec2d
There was a problem hiding this comment.
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.