X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fbroker%2Fimpl%2FDOMBrokerPerformanceTest.java;h=640d603039d0c9d5041141894977828b21aa656c;hp=2dec6f2e4d1bdf773001c66343c8cf1ad4549160;hb=cfd2e240178039a439001c4d3f1ca5f26097dcdd;hpb=4386d86231d7c6b84a8a70795ef43b178c0b9996 diff --git a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerPerformanceTest.java b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerPerformanceTest.java index 2dec6f2e4d..640d603039 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerPerformanceTest.java +++ b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerPerformanceTest.java @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.controller.md.sal.dom.broker.impl; import static org.junit.Assert.assertEquals; @@ -5,11 +13,16 @@ import static org.junit.Assert.assertTrue; import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION; import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableMap; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.Executors; - import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; @@ -18,260 +31,190 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; import org.opendaylight.controller.md.sal.dom.store.impl.TestModel; import org.opendaylight.controller.sal.core.spi.data.DOMStore; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableMap; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; - public class DOMBrokerPerformanceTest { - private static final Logger log = LoggerFactory.getLogger(DOMBrokerPerformanceTest.class); + private static final Logger LOG = LoggerFactory.getLogger(DOMBrokerPerformanceTest.class); - private static NormalizedNode outerList(final int i) { - return ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, i); + private static NormalizedNode outerList(final int index) { + return ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, index); } - private static InstanceIdentifier outerListPath(final int i) { - return InstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)// - .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, i) // + private static YangInstanceIdentifier outerListPath(final int index) { + return YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)// + .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, index) // .build(); } private SchemaContext schemaContext; - private DOMDataBrokerImpl domBroker; + private AbstractDOMDataBroker domBroker; private static V measure(final String name, final Callable callable) throws Exception { // TODO Auto-generated method stub - log.debug("Measurement:{} Start", name); + LOG.debug("Measurement:{} Start", name); long startNano = System.nanoTime(); try { return callable.call(); } finally { long endNano = System.nanoTime(); - log.info("Measurement:\"{}\" Time:{} ms", name, (endNano - startNano) / 1000000.0d); + LOG.info("Measurement:\"{}\" Time:{} ms", name, (endNano - startNano) / 1000000.0d); } } @Before public void setupStore() { - InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.sameThreadExecutor()); - InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService()); + InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.newDirectExecutorService()); schemaContext = TestModel.createTestContext(); operStore.onGlobalContextUpdated(schemaContext); configStore.onGlobalContextUpdated(schemaContext); - ImmutableMap stores = ImmutableMap. builder() // + ImmutableMap stores = ImmutableMap.builder() // .put(CONFIGURATION, configStore) // .put(OPERATIONAL, operStore) // .build(); ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()); - domBroker = new DOMDataBrokerImpl(stores, executor); + domBroker = new SerializedDOMDataBroker(stores, executor); } @Test public void testPerformance() throws Exception { - measure("Test Suite (all tests)", new Callable() { - - @Override - public Void call() throws Exception { - smallTestSuite(10, 1000); - //smallTestSuite(10, 100); - smallTestSuite(100, 100); - //smallTestSuite(100, 100); - //smallTestSuite(1000, 10); - smallTestSuite(1000, 10); - //smallTestSuite(1000, 1000); - return null; - } + measure("Test Suite (all tests)", (Callable) () -> { + smallTestSuite(10, 1000); + //smallTestSuite(10, 100); + smallTestSuite(100, 100); + //smallTestSuite(100, 100); + //smallTestSuite(1000, 10); + smallTestSuite(1000, 10); + //smallTestSuite(1000, 1000); + return null; }); } private void smallTestSuite(final int txNum, final int innerListWriteNum) throws Exception { - measure("TestSuite (Txs:" + txNum + " innerWrites:" + innerListWriteNum + ")", new Callable() { - - @Override - public Void call() throws Exception { - measureOneTransactionTopContainer(); - measureSeparateWritesOneLevel(txNum, innerListWriteNum); - return null; - } + measure("TestSuite (Txs:" + txNum + " innerWrites:" + innerListWriteNum + ")", (Callable) () -> { + measureOneTransactionTopContainer(); + measureSeparateWritesOneLevel(txNum, innerListWriteNum); + return null; }); } private void measureSeparateWritesOneLevel(final int txNum, final int innerNum) throws Exception { - final List transactions = measure("Txs:"+ txNum + " Allocate", - new Callable>() { - @Override - public List call() throws Exception { - List builder = new ArrayList<>(txNum); - for (int i = 0; i < txNum; i++) { - DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction(); - builder.add(writeTx); - } - return builder; - } - }); + final List transactions = measure("Txs:" + txNum + " Allocate", () -> { + List builder = new ArrayList<>(txNum); + for (int i = 0; i < txNum; i++) { + DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction(); + builder.add(writeTx); + } + return builder; + }); assertEquals(txNum, transactions.size()); - measure("Txs:"+ txNum + " Writes:1", new Callable() { - @Override - public Void call() throws Exception { - int i = 0; - for (DOMDataReadWriteTransaction writeTx :transactions) { - // Writes /test/outer-list/i in writeTx - writeTx.put(OPERATIONAL, outerListPath(i), outerList(i)); - i++; - } - return null; + measure("Txs:" + txNum + " Writes:1", (Callable) () -> { + int index = 0; + for (DOMDataReadWriteTransaction writeTx : transactions) { + // Writes /test/outer-list/i in writeTx + writeTx.put(OPERATIONAL, outerListPath(index), outerList(index)); + index++; } + return null; }); - measure("Txs:"+ txNum + " Writes:" + innerNum, new Callable() { - @Override - public Void call() throws Exception { - int i = 0; - for (DOMDataReadWriteTransaction writeTx :transactions) { - // Writes /test/outer-list/i in writeTx - InstanceIdentifier path = InstanceIdentifier.builder(outerListPath(i)) - .node(TestModel.INNER_LIST_QNAME).build(); - writeTx.put(OPERATIONAL, path, ImmutableNodes.mapNodeBuilder(TestModel.INNER_LIST_QNAME).build()); - for (int j = 0; j < innerNum; j++) { - InstanceIdentifier innerPath = InstanceIdentifier.builder(path) - .nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)) - .build(); - writeTx.put( - OPERATIONAL, - innerPath, - ImmutableNodes.mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, - String.valueOf(j))); - } - i++; + measure("Txs:" + txNum + " Writes:" + innerNum, (Callable) () -> { + int index = 0; + for (DOMDataReadWriteTransaction writeTx : transactions) { + // Writes /test/outer-list/i in writeTx + YangInstanceIdentifier path = YangInstanceIdentifier.builder(outerListPath(index)) + .node(TestModel.INNER_LIST_QNAME).build(); + writeTx.put(OPERATIONAL, path, ImmutableNodes.mapNodeBuilder(TestModel.INNER_LIST_QNAME).build()); + for (int j = 0; j < innerNum; j++) { + YangInstanceIdentifier innerPath = YangInstanceIdentifier.builder(path) + .nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)).build(); + writeTx.put(OPERATIONAL, innerPath, ImmutableNodes + .mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j))); } - return null; + index++; } + return null; }); - measure("Txs:" + txNum + " Submit, Finish", new Callable() { - @Override - public Void call() throws Exception { - List> allFutures = measure(txNum + " Submits", - new Callable>>() { - @Override - public List> call() throws Exception { - List> builder = new ArrayList<>(txNum); - for (DOMDataReadWriteTransaction tx :transactions) { - builder.add(tx.submit()); - } - return builder; - } - }); - Futures.allAsList(allFutures).get(); - return null; - } + measure("Txs:" + txNum + " Submit, Finish", (Callable) () -> { + List> allFutures = measure(txNum + " Submits", () -> { + List> builder = new ArrayList<>(txNum); + for (DOMDataReadWriteTransaction tx : transactions) { + builder.add(tx.commit()); + } + return builder; + }); + Futures.allAsList(allFutures).get(); + return null; }); - final DOMDataReadTransaction readTx = measure("Txs:1 (ro), Allocate", new Callable() { - @Override - public DOMDataReadTransaction call() throws Exception { - return domBroker.newReadOnlyTransaction(); + final DOMDataReadTransaction readTx = measure("Txs:1 (ro), Allocate", + (Callable) () -> domBroker + .newReadOnlyTransaction()); - } - }); - - measure("Txs:1 (ro) Reads:" + txNum + " (1-level)" , new Callable() { - @Override - public Void call() throws Exception { - for (int i = 0; i < txNum; i++) { - ListenableFuture>> potential = readTx.read(OPERATIONAL, - outerListPath(i)); - assertTrue("outerList/" + i, potential.get().isPresent()); - } - return null; + measure("Txs:1 (ro) Reads:" + txNum + " (1-level)", (Callable) () -> { + for (int i = 0; i < txNum; i++) { + ListenableFuture>> potential = readTx.read(OPERATIONAL, outerListPath(i)); + assertTrue("outerList/" + i, potential.get().isPresent()); } + return null; }); - measure("Txs:1 (ro) Reads:" + txNum * innerNum + " (2-level)", new Callable() { - @Override - public Void call() throws Exception { - for (int i = 0; i < txNum; i++) { - for (int j = 0; j < innerNum; j++) { - InstanceIdentifier path = InstanceIdentifier - .builder(outerListPath(i)) - // - .node(TestModel.INNER_LIST_QNAME) - .nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)) - .build(); - ListenableFuture>> potential = readTx.read(OPERATIONAL, path); - assertTrue("outer-list/" + i + "/inner-list/" + j, potential.get().isPresent()); - } + measure("Txs:1 (ro) Reads:" + txNum * innerNum + " (2-level)", (Callable) () -> { + for (int i = 0; i < txNum; i++) { + for (int j = 0; j < innerNum; j++) { + YangInstanceIdentifier path = YangInstanceIdentifier.builder(outerListPath(i)) + // + .node(TestModel.INNER_LIST_QNAME) + .nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)).build(); + ListenableFuture>> potential = readTx.read(OPERATIONAL, path); + assertTrue("outer-list/" + i + "/inner-list/" + j, potential.get().isPresent()); } - return null; } + return null; }); } private void measureOneTransactionTopContainer() throws Exception { - final DOMDataReadWriteTransaction writeTx = measure("Txs:1 Allocate", new Callable() { - @Override - public DOMDataReadWriteTransaction call() throws Exception { - return domBroker.newReadWriteTransaction(); - } - }); + final DOMDataReadWriteTransaction writeTx = + measure("Txs:1 Allocate", () -> domBroker.newReadWriteTransaction()); - measure("Txs:1 Write", new Callable() { - @Override - public Void call() throws Exception { - writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - writeTx.put(OPERATIONAL, TestModel.OUTER_LIST_PATH, + measure("Txs:1 Write", (Callable) () -> { + writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); + writeTx.put(OPERATIONAL, TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()); - return null; - } + return null; }); - measure("Txs:1 Reads:1", new Callable() { - @Override - public Void call() throws Exception { - // Reads /test in writeTx - ListenableFuture>> writeTxContainer = writeTx.read(OPERATIONAL, - TestModel.TEST_PATH); - assertTrue(writeTxContainer.get().isPresent()); - return null; - } + measure("Txs:1 Reads:1", (Callable) () -> { + // Reads /test in writeTx + ListenableFuture>> writeTxContainer = writeTx + .read(OPERATIONAL, TestModel.TEST_PATH); + assertTrue(writeTxContainer.get().isPresent()); + return null; }); - measure("Txs:1 Reads:1", new Callable() { - @Override - public Void call() throws Exception { - // Reads /test in writeTx - ListenableFuture>> writeTxContainer = writeTx.read(OPERATIONAL, - TestModel.TEST_PATH); - assertTrue(writeTxContainer.get().isPresent()); - return null; - } + measure("Txs:1 Reads:1", (Callable) () -> { + // Reads /test in writeTx + ListenableFuture>> writeTxContainer = writeTx + .read(OPERATIONAL, TestModel.TEST_PATH); + assertTrue(writeTxContainer.get().isPresent()); + return null; }); - measure("Txs:1 Submit, Finish", new Callable() { - @Override - public Void call() throws Exception { - measure("Txs:1 Submit", new Callable>() { - @Override - public ListenableFuture call() throws Exception { - return writeTx.submit(); - } - }).get(); - return null; - } + measure("Txs:1 Submit, Finish", (Callable) () -> { + measure("Txs:1 Submit", (Callable>) writeTx::commit).get(); + return null; }); } }