2 * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.dom.store.inmemory.benchmark;
10 import java.util.concurrent.ExecutionException;
11 import java.util.concurrent.TimeUnit;
12 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
13 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
14 import org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStore;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.openjdk.jmh.annotations.Benchmark;
17 import org.openjdk.jmh.annotations.Measurement;
18 import org.openjdk.jmh.annotations.Warmup;
21 * Abstract class for in-memory Datastore transaction benchmarks.
23 * @author Lukas Sedlak
25 public abstract class AbstractInMemoryDatastoreWriteTransactionBenchmark
26 extends AbstractInMemoryWriteTransactionBenchmark {
28 protected InMemoryDOMDataStore domStore;
30 protected void initTestNode() throws InterruptedException, ExecutionException {
31 final YangInstanceIdentifier testPath = YangInstanceIdentifier.builder(BenchmarkModel.TEST_PATH).build();
32 DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
33 writeTx.write(testPath, provideOuterListNode());
35 DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
36 cohort.canCommit().get();
37 cohort.preCommit().get();
38 cohort.commit().get();
42 @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
43 @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
44 public void write100KSingleNodeWithOneInnerItemInOneCommitBenchmark()
45 throws InterruptedException, ExecutionException {
46 DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
47 for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
48 writeTx.write(OUTER_LIST_100K_PATHS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
50 DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
51 cohort.canCommit().get();
52 cohort.preCommit().get();
53 cohort.commit().get();
57 @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
58 @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
59 public void write100KSingleNodeWithOneInnerItemInCommitPerWriteBenchmark()
60 throws InterruptedException, ExecutionException {
61 for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
62 DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
63 writeTx.write(OUTER_LIST_100K_PATHS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
65 DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
66 cohort.canCommit().get();
67 cohort.preCommit().get();
68 cohort.commit().get();
73 @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
74 @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
75 public void write50KSingleNodeWithTwoInnerItemsInOneCommitBenchmark()
76 throws InterruptedException, ExecutionException {
77 DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
78 for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
79 writeTx.write(OUTER_LIST_50K_PATHS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
81 DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
82 cohort.canCommit().get();
83 cohort.preCommit().get();
84 cohort.commit().get();
88 @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
89 @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
90 public void write50KSingleNodeWithTwoInnerItemsInCommitPerWriteBenchmark()
91 throws InterruptedException, ExecutionException {
92 for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
93 DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
94 writeTx.write(OUTER_LIST_50K_PATHS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
95 DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
96 cohort.canCommit().get();
97 cohort.preCommit().get();
98 cohort.commit().get();
103 @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
104 @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
105 public void write10KSingleNodeWithTenInnerItemsInOneCommitBenchmark()
106 throws InterruptedException, ExecutionException {
107 DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
108 for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
109 writeTx.write(OUTER_LIST_10K_PATHS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
111 DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
112 cohort.canCommit().get();
113 cohort.preCommit().get();
114 cohort.commit().get();
118 @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
119 @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
120 public void write10KSingleNodeWithTenInnerItemsInCommitPerWriteBenchmark()
121 throws InterruptedException, ExecutionException {
122 for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
123 DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
124 writeTx.write(OUTER_LIST_10K_PATHS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
125 DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
126 cohort.canCommit().get();
127 cohort.preCommit().get();
128 cohort.commit().get();