Migrate to MD-SAL APIs
[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 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
12 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
13 import org.opendaylight.mdsal.dom.broker.SerializedDOMDataBroker;
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  * Abstract class to handle transaction benchmarks.
21  *
22  * @author Lukas Sedlak
23  */
24 public abstract class AbstractInMemoryBrokerWriteTransactionBenchmark
25         extends AbstractInMemoryWriteTransactionBenchmark {
26
27     protected SerializedDOMDataBroker domBroker;
28
29     protected void initTestNode() throws Exception {
30         final YangInstanceIdentifier testPath = YangInstanceIdentifier.builder(BenchmarkModel.TEST_PATH).build();
31         DOMDataTreeReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
32         writeTx.put(LogicalDatastoreType.OPERATIONAL, testPath, provideOuterListNode());
33
34         writeTx.commit().get();
35     }
36
37     @Benchmark
38     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
39     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
40     public void write100KSingleNodeWithOneInnerItemInOneCommitBenchmark() throws Exception {
41
42         DOMDataTreeReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
43         for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
44             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_100K_PATHS[outerListKey],
45                     OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
46         }
47
48         writeTx.commit().get();
49     }
50
51     @Benchmark
52     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
53     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
54     public void write100KSingleNodeWithOneInnerItemInCommitPerWriteBenchmark() throws Exception {
55         for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
56             DOMDataTreeReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
57             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_100K_PATHS[outerListKey],
58                     OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
59
60             writeTx.commit().get();
61         }
62     }
63
64     @Benchmark
65     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
66     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
67     public void write50KSingleNodeWithTwoInnerItemsInOneCommitBenchmark() throws Exception {
68         DOMDataTreeReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
69         for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
70             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_50K_PATHS[outerListKey],
71                     OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
72         }
73
74         writeTx.commit().get();
75     }
76
77     @Benchmark
78     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
79     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
80     public void write50KSingleNodeWithTwoInnerItemsInCommitPerWriteBenchmark() throws Exception {
81         for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
82             DOMDataTreeReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
83             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_50K_PATHS[outerListKey],
84                     OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
85             writeTx.commit().get();
86         }
87     }
88
89     @Benchmark
90     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
91     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
92     public void write10KSingleNodeWithTenInnerItemsInOneCommitBenchmark() throws Exception {
93         DOMDataTreeReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
94         for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
95             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_10K_PATHS[outerListKey],
96                     OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
97         }
98         writeTx.commit().get();
99     }
100
101     @Benchmark
102     @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
103     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
104     public void write10KSingleNodeWithTenInnerItemsInCommitPerWriteBenchmark() throws Exception {
105         for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
106             DOMDataTreeReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
107             writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_10K_PATHS[outerListKey],
108                     OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
109             writeTx.commit().get();
110         }
111     }
112 }