下面列出了org.openjdk.jmh.annotations.Group#org.openjdk.jmh.infra.Control 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Benchmark
public void timerThroughputTest(Control ctrl) throws InterruptedException {
counterDown.set(times);
for (int i = 0; i < times; i++) {
timer.schedule(new Runnable() {
@Override
public void run() {
counterDown.decrementAndGet();
}
},
delay,
TimeUnit.MILLISECONDS);
}
while (!ctrl.stopMeasurement && counterDown.get() > 0) {
// spin
}
}
@Benchmark
@Group("trackDelayed")
public void trackWithDelayedAcks(Control control, TrackerState trackerState) throws Exception {
if (!control.stopMeasurement) {
final AcknowledgableWatermark wmark = new AcknowledgableWatermark(new DefaultCheckpointableWatermark(
"0", new LongWatermark(trackerState._index)));
trackerState._watermarkTracker.track(wmark);
trackerState._index++;
int delay = trackerState._random.nextInt(10);
trackerState._executorService.schedule(new Runnable() {
@Override
public void run() {
wmark.ack();
}
}, delay, TimeUnit.MILLISECONDS);
}
}
@Benchmark
@Group("scheduledDelayed")
public void scheduledDelayedAcks(Control control, TrackerState trackerState) throws Exception {
if (!control.stopMeasurement) {
final AcknowledgableWatermark wmark = new AcknowledgableWatermark(new DefaultCheckpointableWatermark(
"0", new LongWatermark(trackerState._index)));
trackerState._index++;
int delay = trackerState._random.nextInt(10);
trackerState._executorService.schedule(new Runnable() {
@Override
public void run() {
wmark.ack();
}
}, delay, TimeUnit.MILLISECONDS);
}
}
@Benchmark
@Group("scheduledNoRandom")
public void scheduledNoRandomDelayedAcks(Control control, TrackerState trackerState) throws Exception {
if (!control.stopMeasurement) {
final AcknowledgableWatermark wmark = new AcknowledgableWatermark(new DefaultCheckpointableWatermark(
"0", new LongWatermark(trackerState._index)));
trackerState._index++;
int delay = 10;
trackerState._executorService.schedule(new Runnable() {
@Override
public void run() {
wmark.ack();
}
}, delay, TimeUnit.MILLISECONDS);
}
}
@Benchmark
@Group("tenMixedArgs")
@GroupThreads(PRODUCER_THREADS)
public boolean tenMixedArgsCaller(final Control control, final CallerCounters counters) {
this.waitStrategy.control = control;
try {
this.proxy.tenMixedArgs(this.intArg,
this.objArg,
this.longArg,
this.customType0,
this.doubleArg,
this.customType1,
this.floatArg,
this.customType2,
this.booleanArg,
this.customType3);
counters.callsFailed = this.waitStrategy.retries;
return true;
} catch (final StoppedException e) {
return false;
}
}
@Benchmark
@Group("tenMixedArgs")
@GroupThreads(PRODUCER_THREADS)
public boolean tenMixedArgsCaller(final Control control, final CallerCounters counters) {
this.waitStrategy.control = control;
try {
this.proxy.tenMixedArgs(this.intArg,
this.objArg,
this.longArg,
this.customType0,
this.doubleArg,
this.customType1,
this.floatArg,
this.customType2,
this.booleanArg,
this.customType3);
counters.callsFailed = this.waitStrategy.retries;
return true;
} catch (final StoppedException e) {
return false;
}
}
@Benchmark
@Group("pingpong")
public void ping(Control cnt) {
while (!cnt.stopMeasurement && !flag.compareAndSet(false, true)) {
// this body is intentionally left blank
}
}
@Benchmark
@Group("pingpong")
public void pong(Control cnt) {
while (!cnt.stopMeasurement && !flag.compareAndSet(true, false)) {
// this body is intentionally left blank
}
}
@Benchmark
@Group(GROUP_NAME)
@GroupThreads(PRODUCER_THREADS_NUMBER)
public void write(Control control) {
while (!control.stopMeasurement && !queue.offer(1L)) {
}
}
@Benchmark
@Group(GROUP_NAME)
@GroupThreads(CONSUMER_THREADS_NUMBER)
public void read(Control control) {
while (!control.stopMeasurement && queue.poll() == null) {
}
}
@Benchmark
@Group(GROUP_NAME)
@GroupThreads(PRODUCER_THREADS_NUMBER)
public void write(Control control) {
while (!control.stopMeasurement && !queue.offer(1L)) {
}
}
@Benchmark
@GroupThreads(1)
@Group("signal")
public void signal(Control control) {
try {
signalLock.lock();
signalCondition.signal();
}finally {
signalLock.unlock();
}
}
@Benchmark
@GroupThreads(1)
@Group("signal")
public void await(Control control) {
try {
signalLock.lock();
signalCondition.await();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
signalLock.unlock();
}
}
@Benchmark
@GroupThreads(1)
@Group("signalAll")
public void signalAll(Control control) {
try {
signaAlllLock.lock();
signalAllCondition.signal();
}finally {
signaAlllLock.unlock();
}
}
@Benchmark
@GroupThreads(1)
@Group("signalAll")
public void awaitForSignalAll(Control control) {
try {
signaAlllLock.lock();
signalAllCondition.await();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
signaAlllLock.unlock();
}
}
@Benchmark
@GroupThreads(3)
@Group("GROUP_NAME")
public void volatileRead(Control control) {
int b = vol;
b++;
}
@Benchmark
@GroupThreads(3)
@Group("GROUP_NAME1")
public void atmoicRead(Control control) {
int c = atomicInteger.get();
c++;
}
@Benchmark
@Group(GROUP_NAME)
@GroupThreads(PRODUCER_THREADS_NUMBER)
public void write(Control control) {
while (!control.stopMeasurement && !queue.offer(1L)) {
}
}
@Benchmark
public void multiTimerTest(Control ctrl) throws InterruptedException {
int threads = 10;
counterDown.set(times * threads);
for (int i = 0; i < threads; i++) {
final int idx = i;
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(10 * idx);
} catch (InterruptedException e) {
}
for (int j = 0; j < times; j++) {
timer.schedule(new Runnable() {
@Override
public void run() {
counterDown.decrementAndGet();
}
},
delay,
TimeUnit.MILLISECONDS);
}
}
}).start();
}
while (!ctrl.stopMeasurement && counterDown.get() > 0) {
// spin
}
}
public void timerThroughputTest(Control ctrl) throws InterruptedException {
counterDown.set(times);
for (int i = 0; i < times; i++) {
timer.newTimeout((TimerTask) (v) -> counterDown.decrementAndGet(),
delay,
TimeUnit.MILLISECONDS);
}
while (!ctrl.stopMeasurement && counterDown.get() > 0) {
// spin
}
}
@Group("primitive")
@GroupThreads(1)
@Benchmark
public void send1(Control control) {
SpscIntArrayQueue q = queue;
while (!q.offer(1) && !control.stopMeasurement) {
}
}
@Group("primitive")
@GroupThreads(1)
@Benchmark
public void recv1(Control control) {
final SpscIntArrayQueue q = queue;
while (!control.stopMeasurement && q.poll() == 0) {
;
}
}
@Group("fastflow")
@GroupThreads(1)
@Benchmark
public void send4(Control control) {
SpscIntArrayQueueAtomic q = queueFastflow;
while (!q.offer(1) && !control.stopMeasurement) {
}
}
@Group("fastflow")
@GroupThreads(1)
@Benchmark
public void recv4(Control control) {
final SpscIntArrayQueueAtomic q = queueFastflow;
while (!control.stopMeasurement && q.poll() == 0) {
;
}
}
@Group("boxed")
@GroupThreads(1)
@Benchmark
public void send2(Control control) {
SpscArrayQueue<Integer> q = queueBoxed;
while (!q.offer(1) && !control.stopMeasurement) {
}
}
@Group("boxed")
@GroupThreads(1)
@Benchmark
public void recv2(Control control) {
SpscArrayQueue<Integer> q = queueBoxed;
while (!control.stopMeasurement && q.poll() == null) {
}
}
@Benchmark
@Group("trackImmediate")
public void trackImmediateAcks(Control control, TrackerState trackerState) throws Exception {
if (!control.stopMeasurement) {
AcknowledgableWatermark wmark = new AcknowledgableWatermark(new DefaultCheckpointableWatermark(
"0", new LongWatermark(trackerState._index)));
trackerState._watermarkTracker.track(wmark);
trackerState._index++;
wmark.ack();
}
}
@Benchmark
@Group(GROUP_NAME)
@GroupThreads(PRODUCER_THREADS_NUMBER)
public void write(Control control) {
//noinspection StatementWithEmptyBody
while (!control.stopMeasurement && !queue.offer(1L)) {
// Is intentionally left blank
}
}
@Benchmark
@Group(GROUP_NAME)
@GroupThreads(CONSUMER_THREADS_NUMBER)
public void read(Control control) {
//noinspection StatementWithEmptyBody
while (!control.stopMeasurement && queue.poll() == null) {
// Is intentionally left blank
}
}
@Benchmark
@Group("busy")
@GroupThreads(1)
public void writeBusy(Control cnt) {
ChannelProducer<Ping> lProducer = producer;
while (!lProducer.claim()) {
if (cnt.stopMeasurement) {
return;// drop out of spinning if the benchmark iteration is done
}
}
Ping element = lProducer.currentElement();
element.setValue(writeValue);
lProducer.commit();
}