Do not depend on odl-mdsal-broker-local
[controller.git] / opendaylight / md-sal / benchmark-data-store / src / main / java / org / opendaylight / controller / md / sal / dom / store / benchmark / AbstractInMemoryBrokerWriteTransactionBenchmark.java
1 /*
2  * Copyright (c) 2013, 2017 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
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
14 import org.opendaylight.controller.md.sal.dom.broker.impl.SerializedDOMDataBroker;
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;
19
20 /**
21  * Abstract class to handle transaction benchmarks.
22  *
23  * @author Lukas Sedlak
24  */
25 public abstract class AbstractInMemoryBrokerWriteTransactionBenchmark
26         extends AbstractInMemoryWriteTransactionBenchmark {
27
28     protected SerializedDOMDataBroker domBroker;
29
30     protected void initTestNode() throws Exception {
31         final YangInstanceIdentifier testPath = YangInstanceIdentifier.builder(BenchmarkModel.TEST_PATH).build();
32         DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
33         writeTx.put(LogicalDatastoreType.OPERATIONAL, testPath, provideOuterListNode());
34
35         writeTx.submit().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
43         DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
44         for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
45             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_100K_PATHS[outerListKey],
46                     OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
47         }
48
49         writeTx.submit().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             DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
58             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_100K_PATHS[outerListKey],
59                     OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
60
61             writeTx.submit().get();
62         }
63     }
64
65     @Benchmark
66     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
67     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
68     public void write50KSingleNodeWithTwoInnerItemsInOneCommitBenchmark() throws Exception {
69         DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
70         for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
71             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_50K_PATHS[outerListKey],
72                     OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
73         }
74
75         writeTx.submit().get();
76     }
77
78     @Benchmark
79     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
80     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
81     public void write50KSingleNodeWithTwoInnerItemsInCommitPerWriteBenchmark() throws Exception {
82         for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
83             DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
84             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_50K_PATHS[outerListKey],
85                     OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
86             writeTx.submit().get();
87         }
88     }
89
90     @Benchmark
91     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
92     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
93     public void write10KSingleNodeWithTenInnerItemsInOneCommitBenchmark() throws Exception {
94         DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
95         for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
96             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_10K_PATHS[outerListKey],
97                     OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
98         }
99         writeTx.submit().get();
100     }
101
102     @Benchmark
103     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
104     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
105     public void write10KSingleNodeWithTenInnerItemsInCommitPerWriteBenchmark() throws Exception {
106         for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
107             DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
108             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_10K_PATHS[outerListKey],
109                     OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
110             writeTx.submit().get();
111         }
112     }
113 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.