Merge "Fix typos and missing space"
[controller.git] / opendaylight / md-sal / benchmark-data-store / src / main / java / org / opendaylight / controller / md / sal / dom / store / benchmark / InMemoryDataStoreWithExecutorServiceBenchmark.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 com.google.common.util.concurrent.ListeningExecutorService;
11 import com.google.common.util.concurrent.MoreExecutors;
12 import java.util.concurrent.ExecutorService;
13 import java.util.concurrent.TimeUnit;
14 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
15 import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
16 import org.openjdk.jmh.annotations.BenchmarkMode;
17 import org.openjdk.jmh.annotations.Fork;
18 import org.openjdk.jmh.annotations.Level;
19 import org.openjdk.jmh.annotations.Mode;
20 import org.openjdk.jmh.annotations.OutputTimeUnit;
21 import org.openjdk.jmh.annotations.Scope;
22 import org.openjdk.jmh.annotations.Setup;
23 import org.openjdk.jmh.annotations.State;
24 import org.openjdk.jmh.annotations.TearDown;
25
26 /**
27  * Benchmark for testing of performance of write operations for InMemoryDataStore. The instance
28  * of benchmark creates InMemoryDataStore with Data Change Listener Executor Service as BlockingBoundedFastThreadPool
29  * and DOM Store Executor Service as Blocking Bounded Fast Thread Pool.
30  *
31  * @see org.opendaylight.yangtools.util.concurrent.SpecialExecutors
32  * @see org.opendaylight.controller.md.sal.dom.store.benchmark.AbstractInMemoryDatastoreWriteTransactionBenchmark
33  *
34  * @author Lukas Sedlak <lsedlak@cisco.com>
35  */
36 @State(Scope.Thread)
37 @BenchmarkMode(Mode.AverageTime)
38 @OutputTimeUnit(TimeUnit.MILLISECONDS)
39 @Fork(1)
40 public class InMemoryDataStoreWithExecutorServiceBenchmark extends AbstractInMemoryDatastoreWriteTransactionBenchmark  {
41
42     private static final int MAX_DATA_CHANGE_EXECUTOR_POOL_SIZE = 20;
43     private static final int MAX_DATA_CHANGE_EXECUTOR_QUEUE_SIZE = 1000;
44     private static final int MAX_DATA_STORE_EXECUTOR_QUEUE_SIZE = 5000;
45
46     @Override
47     @Setup(Level.Trial)
48     public void setUp() throws Exception {
49         final String name = "DS_BENCHMARK";
50         final ExecutorService dataChangeListenerExecutor = SpecialExecutors.newBlockingBoundedFastThreadPool(
51             MAX_DATA_CHANGE_EXECUTOR_POOL_SIZE, MAX_DATA_CHANGE_EXECUTOR_QUEUE_SIZE, name + "-DCL");
52
53         final ListeningExecutorService domStoreExecutor = MoreExecutors.listeningDecorator(SpecialExecutors.newBoundedSingleThreadExecutor(
54             MAX_DATA_STORE_EXECUTOR_QUEUE_SIZE, "DOMStore-" + name ));
55
56         domStore = new InMemoryDOMDataStore(name, domStoreExecutor,
57             dataChangeListenerExecutor);
58         schemaContext = BenchmarkModel.createTestContext();
59         domStore.onGlobalContextUpdated(schemaContext);
60         initTestNode();
61     }
62
63     @Override
64     @TearDown
65     public void tearDown() {
66         schemaContext = null;
67         domStore = null;
68     }
69 }