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