2 * Copyright (c) 2013 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.controller.md.sal.dom.store.benchmark;
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.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
16 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
20 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
21 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.openjdk.jmh.annotations.Benchmark;
24 import org.openjdk.jmh.annotations.Measurement;
25 import org.openjdk.jmh.annotations.Warmup;
28 * @author Lukas Sedlak <lsedlak@cisco.com>
30 public abstract class AbstractInMemoryDatastoreWriteTransactionBenchmark {
32 private static final int WARMUP_ITERATIONS = 20;
33 private static final int MEASUREMENT_ITERATIONS = 20;
35 private static final int OUTER_LIST_100K = 100000;
36 private static final int OUTER_LIST_50K = 50000;
37 private static final int OUTER_LIST_10K = 10000;
39 private static final YangInstanceIdentifier[] OUTER_LIST_100K_PATHS = initOuterListPaths(OUTER_LIST_100K);
40 private static final YangInstanceIdentifier[] OUTER_LIST_50K_PATHS = initOuterListPaths(OUTER_LIST_50K);
41 private static final YangInstanceIdentifier[] OUTER_LIST_10K_PATHS = initOuterListPaths(OUTER_LIST_10K);
43 private static YangInstanceIdentifier[] initOuterListPaths(final int outerListPathsCount) {
44 final YangInstanceIdentifier[] paths = new YangInstanceIdentifier[outerListPathsCount];
46 for (int outerListKey = 0; outerListKey < outerListPathsCount; ++outerListKey) {
47 paths[outerListKey] = YangInstanceIdentifier.builder(BenchmarkModel.OUTER_LIST_PATH)
48 .nodeWithKey(BenchmarkModel.OUTER_LIST_QNAME, BenchmarkModel.ID_QNAME, outerListKey)
54 private static final MapNode ONE_ITEM_INNER_LIST = initInnerListItems(1);
55 private static final MapNode TWO_ITEM_INNER_LIST = initInnerListItems(2);
56 private static final MapNode TEN_ITEM_INNER_LIST = initInnerListItems(10);
58 private static MapNode initInnerListItems(final int count) {
59 final CollectionNodeBuilder<MapEntryNode, MapNode> mapEntryBuilder = ImmutableNodes
60 .mapNodeBuilder(BenchmarkModel.INNER_LIST_QNAME);
62 for (int i = 1; i <= count; ++i) {
64 .withChild(ImmutableNodes.mapEntry(BenchmarkModel.INNER_LIST_QNAME, BenchmarkModel.NAME_QNAME, i));
66 return mapEntryBuilder.build();
69 private static final NormalizedNode<?, ?>[] OUTER_LIST_ONE_ITEM_INNER_LIST = initOuterListItems(OUTER_LIST_100K, ONE_ITEM_INNER_LIST);
70 private static final NormalizedNode<?, ?>[] OUTER_LIST_TWO_ITEM_INNER_LIST = initOuterListItems(OUTER_LIST_50K, TWO_ITEM_INNER_LIST);
71 private static final NormalizedNode<?, ?>[] OUTER_LIST_TEN_ITEM_INNER_LIST = initOuterListItems(OUTER_LIST_10K, TEN_ITEM_INNER_LIST);
73 private static NormalizedNode<?,?>[] initOuterListItems(int outerListItemsCount, MapNode innerList) {
74 final NormalizedNode<?,?>[] outerListItems = new NormalizedNode[outerListItemsCount];
76 for (int i = 0; i < outerListItemsCount; ++i) {
78 outerListItems[i] = ImmutableNodes.mapEntryBuilder(BenchmarkModel.OUTER_LIST_QNAME, BenchmarkModel.ID_QNAME, outerListKey)
79 .withChild(innerList).build();
81 return outerListItems;
84 protected SchemaContext schemaContext;
85 protected InMemoryDOMDataStore domStore;
87 abstract public void setUp() throws Exception;
89 abstract public void tearDown();
91 protected void initTestNode() throws Exception {
92 final YangInstanceIdentifier testPath = YangInstanceIdentifier.builder(BenchmarkModel.TEST_PATH)
94 DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
95 writeTx.write(testPath, provideOuterListNode());
97 DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
98 cohort.canCommit().get();
99 cohort.preCommit().get();
100 cohort.commit().get();
103 private DataContainerChild<?, ?> provideOuterListNode() {
104 return ImmutableContainerNodeBuilder
106 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(BenchmarkModel.TEST_QNAME))
108 ImmutableNodes.mapNodeBuilder(BenchmarkModel.OUTER_LIST_QNAME)
113 @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
114 @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
115 public void write100KSingleNodeWithOneInnerItemInOneCommitBenchmark() throws Exception {
116 DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
117 for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
118 writeTx.write(OUTER_LIST_100K_PATHS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
120 DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
121 cohort.canCommit().get();
122 cohort.preCommit().get();
123 cohort.commit().get();
127 @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
128 @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
129 public void write100KSingleNodeWithOneInnerItemInCommitPerWriteBenchmark() throws Exception {
130 for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
131 DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
132 writeTx.write(OUTER_LIST_100K_PATHS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
134 DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
135 cohort.canCommit().get();
136 cohort.preCommit().get();
137 cohort.commit().get();
142 @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
143 @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
144 public void write50KSingleNodeWithTwoInnerItemsInOneCommitBenchmark() throws Exception {
145 DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
146 for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
147 writeTx.write(OUTER_LIST_50K_PATHS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
149 DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
150 cohort.canCommit().get();
151 cohort.preCommit().get();
152 cohort.commit().get();
156 @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
157 @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
158 public void write50KSingleNodeWithTwoInnerItemsInCommitPerWriteBenchmark() throws Exception {
159 for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
160 DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
161 writeTx.write(OUTER_LIST_50K_PATHS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
162 DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
163 cohort.canCommit().get();
164 cohort.preCommit().get();
165 cohort.commit().get();
170 @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
171 @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
172 public void write10KSingleNodeWithTenInnerItemsInOneCommitBenchmark() throws Exception {
173 DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
174 for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
175 writeTx.write(OUTER_LIST_10K_PATHS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
177 DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
178 cohort.canCommit().get();
179 cohort.preCommit().get();
180 cohort.commit().get();
184 @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
185 @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
186 public void write10KSingleNodeWithTenInnerItemsInCommitPerWriteBenchmark() throws Exception {
187 for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
188 DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
189 writeTx.write(OUTER_LIST_10K_PATHS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
190 DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
191 cohort.canCommit().get();
192 cohort.preCommit().get();
193 cohort.commit().get();