X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?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;hb=b681508d95a7897da263a92f7e3f0aff0adecb33;hp=81af5f303381112141f65f8d2cd55a4b7e665088;hpb=4d4d6663416b8aa05b17e6b3176c2d530bfa6cc4;p=controller.git 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 81af5f3033..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 @@ -12,6 +12,7 @@ import static org.junit.Assert.assertEquals; 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; @@ -39,15 +40,15 @@ import org.slf4j.LoggerFactory; 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 YangInstanceIdentifier outerListPath(final int i) { + private static YangInstanceIdentifier outerListPath(final int index) { return YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)// - .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, i) // + .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, index) // .build(); } @@ -56,13 +57,13 @@ public class DOMBrokerPerformanceTest { 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); } } @@ -75,7 +76,7 @@ public class DOMBrokerPerformanceTest { operStore.onGlobalContextUpdated(schemaContext); configStore.onGlobalContextUpdated(schemaContext); - ImmutableMap stores = ImmutableMap. builder() // + ImmutableMap stores = ImmutableMap.builder() // .put(CONFIGURATION, configStore) // .put(OPERATIONAL, operStore) // .build(); @@ -106,69 +107,63 @@ public class DOMBrokerPerformanceTest { } private void measureSeparateWritesOneLevel(final int txNum, final int innerNum) throws Exception { - 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; - }); + 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", (Callable) () -> { - int i = 0; - for (DOMDataReadWriteTransaction writeTx :transactions) { + measure("Txs:" + txNum + " Writes:1", (Callable) () -> { + int index = 0; + for (DOMDataReadWriteTransaction writeTx : transactions) { // Writes /test/outer-list/i in writeTx - writeTx.put(OPERATIONAL, outerListPath(i), outerList(i)); - i++; + writeTx.put(OPERATIONAL, outerListPath(index), outerList(index)); + index++; } return null; }); - measure("Txs:"+ txNum + " Writes:" + innerNum, (Callable) () -> { - int i = 0; - for (DOMDataReadWriteTransaction writeTx :transactions) { + 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(i)) + 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))); + .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++; + index++; } 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.submit()); - } - return builder; - }); + 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", - (Callable) () -> domBroker.newReadOnlyTransaction()); + (Callable) () -> domBroker + .newReadOnlyTransaction()); - measure("Txs:1 (ro) Reads:" + txNum + " (1-level)" , (Callable) () -> { + measure("Txs:1 (ro) Reads:" + txNum + " (1-level)", (Callable) () -> { for (int i = 0; i < txNum; i++) { - ListenableFuture>> potential = readTx.read(OPERATIONAL, - outerListPath(i)); + ListenableFuture>> potential = readTx.read(OPERATIONAL, outerListPath(i)); assertTrue("outerList/" + i, potential.get().isPresent()); } return null; @@ -177,12 +172,10 @@ public class DOMBrokerPerformanceTest { 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)) + YangInstanceIdentifier path = YangInstanceIdentifier.builder(outerListPath(i)) // .node(TestModel.INNER_LIST_QNAME) - .nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)) - .build(); + .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()); } @@ -193,33 +186,34 @@ public class DOMBrokerPerformanceTest { private void measureOneTransactionTopContainer() throws Exception { - final DOMDataReadWriteTransaction writeTx = measure("Txs:1 Allocate", () -> domBroker.newReadWriteTransaction()); + final DOMDataReadWriteTransaction writeTx = + measure("Txs:1 Allocate", () -> domBroker.newReadWriteTransaction()); 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()); + ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()); return null; }); measure("Txs:1 Reads:1", (Callable) () -> { // Reads /test in writeTx - ListenableFuture>> writeTxContainer = writeTx.read(OPERATIONAL, - TestModel.TEST_PATH); + 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); + ListenableFuture>> writeTxContainer = writeTx + .read(OPERATIONAL, TestModel.TEST_PATH); assertTrue(writeTxContainer.get().isPresent()); return null; }); measure("Txs:1 Submit, Finish", (Callable) () -> { - measure("Txs:1 Submit", (Callable>) () -> writeTx.submit()).get(); + measure("Txs:1 Submit", (Callable>) writeTx::commit).get(); return null; }); }