下面列出了org.openjdk.jmh.annotations.GroupThreads#org.openjdk.jmh.annotations.Group 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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("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
public void write(ProducerCounter counter) throws IOException {
cbos.write(data);
counter.producedBytes += dataSize;
if (flushOnEach || r.nextInt(100) < 30) {
cbos.flush();
counter.flush++;
}
}
@Benchmark
@Group
public void requestN(ConsumerCounter counter) {
if (subscription == null) {
toSource(publisher).subscribe(new Subscriber<Buffer>() {
@Override
public void onSubscribe(final Subscription s) {
subscription = s;
}
@Override
public void onNext(final Buffer buffer) {
counter.consumedBytes += buffer.readableBytes();
++counter.onNext;
}
@Override
public void onError(final Throwable t) {
}
@Override
public void onComplete() {
}
});
}
subscription.request(1);
}
@Benchmark @Group("no_contention") @GroupThreads(1)
public void no_contention_drain(DrainCounters counters, ConsumerMarker cm) {
q.drainTo(next -> {
counters.drained++;
return true;
});
}
@Benchmark @Group("mild_contention") @GroupThreads(1)
public void mild_contention_drain(DrainCounters counters, ConsumerMarker cm) {
q.drainTo(next -> {
counters.drained++;
return true;
});
}
@Benchmark @Group("high_contention") @GroupThreads(1)
public void high_contention_drain(DrainCounters counters, ConsumerMarker cm) {
q.drainTo(next -> {
counters.drained++;
return true;
});
}
@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("no_contention") @GroupThreads(1)
public void no_contention_offer(OfferCounters counters) {
if (q.offer(ONE, 1)) {
counters.offersMade++;
} else {
counters.offersFailed++;
}
}
@Benchmark @Group("no_contention") @GroupThreads(1)
public void no_contention_drain(DrainCounters counters, ConsumerMarker cm) {
q.drainTo((s, b) -> {
counters.drained++;
return true;
}, 1000);
}
@Benchmark @Group("mild_contention") @GroupThreads(2)
public void mild_contention_offer(OfferCounters counters) {
if (q.offer(ONE, 1)) {
counters.offersMade++;
} else {
counters.offersFailed++;
}
}
@Benchmark
@Group("single")
@GroupThreads(2)
public TLCState[] consumerSingle() {
final TLCState[] res = new TLCState[batch.length];
for (int i = 0; i < batch.length; i++) {
res[i] = this.s.sDequeue();
}
return res;
}
@Benchmark
@Group("single")
@GroupThreads(2)
public void producerSingle() {
for (int i = 0; i < batch.length; i++) {
this.s.sEnqueue(batch[i]);
}
}
@Benchmark
@Group("batchasym")
@GroupThreads(2)
public TLCState[] consumerBatch() {
final TLCState[] res = new TLCState[batch.length];
for (int i = 0; i < batch.length; i++) {
res[i] = this.s.sDequeue();
}
return res;
}
@Benchmark @Group("high_contention") @GroupThreads(1)
public void high_contention_poll(PollCounters counters) {
if (queue.poll() == null) {
counters.pollsFailed++;
} else {
counters.pollsMade++;
}
}
@GenerateMicroBenchmark
@Group("tpt")
public void offer(OpCounters counters) {
if (!q.offer(ONE)) {
counters.offerFail++;
}
if (DELAY_PRODUCER != 0) {
BlackHole.consumeCPU(DELAY_PRODUCER);
}
}
@GenerateMicroBenchmark
@Group("tpt")
public void poll(OpCounters counters, ConsumerMarker cm) {
if (q.poll() == null) {
counters.pollFail++;
}
if (DELAY_CONSUMER != 0) {
BlackHole.consumeCPU(DELAY_CONSUMER);
}
}
@GenerateMicroBenchmark
@Group("tpt")
public void offer(OpCounters counters) {
if (!q.offer(ONE)) {
counters.offerFail++;
Thread.yield();
}
if (DELAY_PRODUCER != 0) {
BlackHole.consumeCPU(DELAY_PRODUCER);
}
}
@GenerateMicroBenchmark
@Group("tpt")
public void poll(OpCounters counters, ConsumerMarker cm) {
if (q.poll() == null) {
counters.pollFail++;
Thread.yield();
}
if (DELAY_CONSUMER != 0) {
BlackHole.consumeCPU(DELAY_CONSUMER);
}
}
/**
*
*/
@Benchmark
@Group("park")
public void park() {
if (thread == null)
thread = Thread.currentThread();
LockSupport.park(thread);
}
/**
*
*/
@Benchmark
@GroupThreads(THREAD_COUNT)
@Group("park")
public void unpark() {
LockSupport.unpark(thread);
}
/**
*
*/
@Benchmark
@Group("condition")
@GroupThreads(THREAD_COUNT)
public void notifyAll0() {
synchronized (mux) {
mux.notify();
}
}
/**
*
*/
@Benchmark
@Group("condition")
public void wait0() throws InterruptedException {
synchronized (mux) {
mux.wait();
}
}
@Benchmark @Group("no_contention") @GroupThreads(1)
public void no_contention_offer(OfferCounters counters) {
if (queue.offer(Boolean.TRUE)) {
counters.offersMade++;
} else {
counters.offersFailed++;
}
}
@Benchmark @Group("no_contention") @GroupThreads(1)
public void no_contention_poll(PollCounters counters) {
if (queue.poll() == null) {
counters.pollsFailed++;
} else {
counters.pollsMade++;
}
}
@Benchmark @Group("mild_contention") @GroupThreads(2)
public void mild_contention_offer(OfferCounters counters) {
if (queue.offer(Boolean.TRUE)) {
counters.offersMade++;
} else {
counters.offersFailed++;
}
}
@Benchmark @Group("mild_contention") @GroupThreads(1)
public void mild_contention_poll(PollCounters counters) {
if (queue.poll() == null) {
counters.pollsFailed++;
} else {
counters.pollsMade++;
}
}
@Benchmark @Group("high_contention") @GroupThreads(8)
public void high_contention_offer(OfferCounters counters) {
if (queue.offer(Boolean.TRUE)) {
counters.offersMade++;
} else {
counters.offersFailed++;
}
}
@Benchmark
@Group("c1p4")
@GroupThreads(4)
public void c1p4Producer(Test test) throws InterruptedException {
test.producer().send(test.packet);
}