Merge "Introduce a benchmark for databroker"
[controller.git] / opendaylight / md-sal / benchmark-data-store / src / main / java / org / opendaylight / controller / md / sal / dom / store / benchmark / AbstractInMemoryDatastoreWriteTransactionBenchmark.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.dom.store.benchmark;
9
10 import java.util.concurrent.TimeUnit;
11 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
12 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
13 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 import org.openjdk.jmh.annotations.Benchmark;
16 import org.openjdk.jmh.annotations.Measurement;
17 import org.openjdk.jmh.annotations.Warmup;
18
19 /**
20  * @author Lukas Sedlak <lsedlak@cisco.com>
21  */
22 public abstract class AbstractInMemoryDatastoreWriteTransactionBenchmark extends AbstractInMemoryWriteTransactionBenchmark {
23
24     protected InMemoryDOMDataStore domStore;
25
26     protected void initTestNode() throws Exception {
27         final YangInstanceIdentifier testPath = YangInstanceIdentifier.builder(BenchmarkModel.TEST_PATH)
28             .build();
29         DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
30         writeTx.write(testPath, provideOuterListNode());
31
32         DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
33         cohort.canCommit().get();
34         cohort.preCommit().get();
35         cohort.commit().get();
36     }
37
38     @Benchmark
39     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
40     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
41     public void write100KSingleNodeWithOneInnerItemInOneCommitBenchmark() throws Exception {
42         DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
43         for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
44             writeTx.write(OUTER_LIST_100K_PATHS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
45         }
46         DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
47         cohort.canCommit().get();
48         cohort.preCommit().get();
49         cohort.commit().get();
50     }
51
52     @Benchmark
53     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
54     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
55     public void write100KSingleNodeWithOneInnerItemInCommitPerWriteBenchmark() throws Exception {
56         for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
57             DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
58             writeTx.write(OUTER_LIST_100K_PATHS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
59
60             DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
61             cohort.canCommit().get();
62             cohort.preCommit().get();
63             cohort.commit().get();
64         }
65     }
66
67     @Benchmark
68     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
69     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
70     public void write50KSingleNodeWithTwoInnerItemsInOneCommitBenchmark() throws Exception {
71         DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
72         for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
73             writeTx.write(OUTER_LIST_50K_PATHS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
74         }
75         DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
76         cohort.canCommit().get();
77         cohort.preCommit().get();
78         cohort.commit().get();
79     }
80
81     @Benchmark
82     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
83     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
84     public void write50KSingleNodeWithTwoInnerItemsInCommitPerWriteBenchmark() throws Exception {
85         for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
86             DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
87             writeTx.write(OUTER_LIST_50K_PATHS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
88             DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
89             cohort.canCommit().get();
90             cohort.preCommit().get();
91             cohort.commit().get();
92         }
93     }
94
95     @Benchmark
96     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
97     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
98     public void write10KSingleNodeWithTenInnerItemsInOneCommitBenchmark() throws Exception {
99         DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
100         for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
101             writeTx.write(OUTER_LIST_10K_PATHS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
102         }
103         DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
104         cohort.canCommit().get();
105         cohort.preCommit().get();
106         cohort.commit().get();
107     }
108
109     @Benchmark
110     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
111     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
112     public void write10KSingleNodeWithTenInnerItemsInCommitPerWriteBenchmark() throws Exception {
113         for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
114             DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
115             writeTx.write(OUTER_LIST_10K_PATHS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
116             DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
117             cohort.canCommit().get();
118             cohort.preCommit().get();
119             cohort.commit().get();
120         }
121     }
122 }