Merge "Bug 2233 - RPC register exception when rpc has no input"
[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 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.common.api.data.LogicalDatastoreType;
12 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
13 import org.opendaylight.controller.md.sal.dom.broker.impl.DOMDataBrokerImpl;
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 AbstractInMemoryBrokerWriteTransactionBenchmark extends AbstractInMemoryWriteTransactionBenchmark {
23
24     protected DOMDataBrokerImpl domBroker;
25
26     protected void initTestNode() throws Exception {
27         final YangInstanceIdentifier testPath = YangInstanceIdentifier.builder(BenchmarkModel.TEST_PATH)
28             .build();
29         DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
30         writeTx.put(LogicalDatastoreType.OPERATIONAL, testPath, provideOuterListNode());
31
32         writeTx.submit().get();
33     }
34
35     @Benchmark
36     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
37     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
38     public void write100KSingleNodeWithOneInnerItemInOneCommitBenchmark() throws Exception {
39
40         DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
41         for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
42             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_100K_PATHS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
43         }
44
45         writeTx.submit().get();
46     }
47
48     @Benchmark
49     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
50     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
51     public void write100KSingleNodeWithOneInnerItemInCommitPerWriteBenchmark() throws Exception {
52         for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
53             DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
54             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_100K_PATHS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
55
56             writeTx.submit().get();
57         }
58     }
59
60     @Benchmark
61     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
62     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
63     public void write50KSingleNodeWithTwoInnerItemsInOneCommitBenchmark() throws Exception {
64         DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
65         for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
66             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_50K_PATHS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
67         }
68
69         writeTx.submit().get();
70     }
71
72     @Benchmark
73     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
74     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
75     public void write50KSingleNodeWithTwoInnerItemsInCommitPerWriteBenchmark() throws Exception {
76         for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
77             DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
78             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_50K_PATHS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
79             writeTx.submit().get();
80         }
81     }
82
83     @Benchmark
84     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
85     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
86     public void write10KSingleNodeWithTenInnerItemsInOneCommitBenchmark() throws Exception {
87         DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
88         for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
89             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_10K_PATHS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
90         }
91         writeTx.submit().get();
92     }
93
94     @Benchmark
95     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
96     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
97     public void write10KSingleNodeWithTenInnerItemsInCommitPerWriteBenchmark() throws Exception {
98         for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
99             DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
100             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_10K_PATHS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
101             writeTx.submit().get();
102         }
103     }
104 }