Skip to content

Commit

Permalink
Merge pull request #240 from franz1981/drain_fill_bench
Browse files Browse the repository at this point in the history
Improved drain/fill benchmark by reducing GC and removing dead code
  • Loading branch information
nitsanw committed Apr 6, 2019
2 parents ec97d77 + 5b5ce94 commit 4ffdcf8
Showing 1 changed file with 25 additions and 68 deletions.
Expand Up @@ -40,13 +40,11 @@
@Measurement(iterations = 10, time = 1)
public class MpqDrainFillThroughputBackoffNone {
static final Object TEST_ELEMENT = 1;
Integer element = 1;
Integer escape;
MessagePassingQueue<Integer> q;

@Param(value = { "SpscArrayQueue", "MpscArrayQueue", "SpmcArrayQueue", "MpmcArrayQueue" })
String qType;

@Param(value = { "132000" })
int qCapacity;

Expand All @@ -57,27 +55,41 @@ public void createQandPrimeCompilation() {

@AuxCounters
@State(Scope.Thread)
public static class PollCounters {
public static class PollCounters implements MessagePassingQueue.Consumer<Integer>{
public long pollsFailed;
public long pollsMade;
private Integer escape;

@Override
public void accept(Integer e)
{
if (e == TEST_ELEMENT) {
pollsMade++;
} else {
escape = e;
}
}
}

@AuxCounters
@State(Scope.Thread)
public static class OfferCounters {
public static class OfferCounters implements MessagePassingQueue.Supplier<Integer>{
public long offersFailed;
public long offersMade;
private Integer element = 1;

@Override
public Integer get()
{
offersMade++;
return element;
}
}

@Benchmark
@Group("normal")
public void fill(final OfferCounters counters) {
long filled = q.fill(new MessagePassingQueue.Supplier<Integer>() {
public Integer get() {
counters.offersMade++;
return element;
}
});
long filled = q.fill(counters);
if (filled == 0) {
counters.offersFailed++;
backoff();
Expand All @@ -87,68 +99,13 @@ public Integer get() {
@Benchmark
@Group("normal")
public void drain(final PollCounters counters) {
long drained = q.drain(new MessagePassingQueue.Consumer<Integer>() {
public void accept(Integer e) {
if (e == TEST_ELEMENT) {
counters.pollsMade++;
} else {
escape = e;
}
}
});
long drained = q.drain(counters);
if (drained == 0) {
counters.pollsFailed++;
backoff();
}
}
//
// @Benchmark
// @Group("prepetual")
// public void fill(final OfferCounters counters, final Control ctl) {
// WaitStrategy w = new WaitStrategy(){
// public int idle(int idleCounter) {
// backoff();
// return idleCounter++;
// }
// };
// ExitCondition e = new ExitCondition() {
// public boolean keepRunning() {
// return !ctl.stopMeasurement;
// }
// };
// q.fill(new MessagePassingQueue.Supplier<Integer>() {
// public Integer get() {
// counters.offersMade++;
// return element;
// }
// }, w, e);
// }
//
// @Benchmark
// @Group("prepetual")
// public void drain(final PollCounters counters, final Control ctl) {
// WaitStrategy w = new WaitStrategy(){
// public int idle(int idleCounter) {
// backoff();
// return idleCounter++;
// }
// };
// ExitCondition e = new ExitCondition() {
// public boolean keepRunning() {
// return !ctl.stopMeasurement;
// }
// };
// q.drain(new MessagePassingQueue.Consumer<Integer>() {
// public void accept(Integer e) {
// if (e == element) {
// counters.pollsMade++;
// } else {
// escape = e;
// }
// }
// }, w, e);
// }


@TearDown(Level.Iteration)
public void emptyQ() {
synchronized (q)
Expand Down

0 comments on commit 4ffdcf8

Please sign in to comment.