Package org.modeshape.common.statistic

Examples of org.modeshape.common.statistic.Stopwatch


        assertThat(system.getPath(), is("/jcr:system"));
    }

    @Test
    public void shouldAllowCreatingManyUnstructuredNodesWithSameNameSiblings() throws Exception {
        Stopwatch sw = new Stopwatch();
        System.out.print("Iterating ");
        for (int i = 0; i != 15; ++i) {
            System.out.print(".");
            // Each iteration adds another node under the root and creates the many nodes under that node ...
            Node node = session.getRootNode().addNode("testNode");
            session.save();

            if (i > 2) {
                sw.start();
            }
            for (int j = 0; j != MANY_NODES_COUNT; ++j) {
                node.addNode("childNode");
            }
            session.save();
            if (i > 2) {
                sw.stop();
            }

            // Now add another node ...
            node.addNode("oneMore");
            session.save();

            node.remove();
            session.save();
            assertThat(session.getRootNode().getNodes().getSize(), is(1L));
        }
        System.out.println();
        System.out.println(sw.getDetailedStatistics());
    }
View Full Code Here


        session.save();
    }

    @Test
    public void shouldAllowCreatingManyUnstructuredNodesWithNoSameNameSiblings() throws Exception {
        Stopwatch sw = new Stopwatch();
        System.out.print("Iterating ");
        for (int i = 0; i != 10; ++i) {
            System.out.print(".");
            // Each iteration adds another node under the root and creates the many nodes under that node ...
            Node node = session.getRootNode().addNode("testNode");
            session.save();

            int count = MANY_NODES_COUNT;
            if (i > 2) {
                sw.start();
            }
            for (int j = 0; j != count; ++j) {
                node.addNode("childNode" + j);
            }
            session.save();
            if (i > 2) {
                sw.stop();
            }

            // Now add another node ...
            node.addNode("oneMore");
            session.save();

            node.remove();
            session.save();
            assertThat(session.getRootNode().getNodes().getSize(), is(1L));
        }
        System.out.println();
        System.out.println(sw.getDetailedStatistics());
    }
View Full Code Here

                                             boolean useSns,
                                             boolean print ) throws Exception {
        Node node = session.getRootNode().addNode("testArea");
        session.save();

        Stopwatch sw = new Stopwatch();
        if (print) {
            System.out.print("Iterating ");
        }
        int numNodesEach = 0;
        for (int i = 0; i != samples; ++i) {
            System.out.print(".");
            sw.start();
            numNodesEach = createSubgraph(session, node, depth, numberOfChildrenPerNode, numberOfPropertiesPerNode, useSns, 1);
            sw.stop();
            session.save();
        }

        // session.getRootNode().getNode("testArea").remove();
        // session.save();
        // assertThat(session.getRootNode().getNodes().getSize(), is(1L)); // only '/jcr:system'
        if (print) {
            System.out.println();
            System.out.println("Create subgraphs with " + numNodesEach + " nodes each: " + sw.getSimpleStatistics());
        }

        // Now try getting a node at one level down ...
        String name = "childNode";
        int index = numberOfChildrenPerNode / 2;
        String path = useSns ? (name + "[" + index + "]") : (name + index);
        sw.reset();
        sw.start();
        Node randomNode = node.getNode(path);
        sw.stop();
        assertThat(randomNode, is(notNullValue()));
        if (print) {
            System.out.println("Find " + randomNode.getPath() + ": " + sw.getTotalDuration());
        }
    }
View Full Code Here

        // create a parent with a number of nodes initially
        Node parent = session.getRootNode().addNode("testRoot");
        session.save();

        Stopwatch globalSw = new Stopwatch();
        globalSw.start();
        if (print) {
            System.out.println("Starting to insert batches...");
        }
        for (int i = 0; i < insertBatches; i++) {
            // reload the parent in the session after it was saved
            parent = session.getNode("/testRoot");
            createSubgraph(session, parent, 1, insertBatchSize, propertiesPerChild, true, 1);
        }
        globalSw.stop();
        if (print) {
            System.out.println("Inserted " + initialNodeCount + " nodes in: " + globalSw.getSimpleStatistics());
        }
        globalSw.reset();
        globalSw.start();
        Stopwatch readSW = new Stopwatch();
        // add additional batches of nodes while reading the paths after each batch of children was added
        int batchCount = 36;
        int batchSize = 1000;
        for (int i = 0; i < batchCount; i++) {
            // creates batchSize
            long childCountAtBatchStart = session.getNode("/testRoot").getNodes().getSize();
            int newChildrenCount = createSubgraph(session, parent, 1, batchSize, propertiesPerChild, true, 1);
            readSW.start();

            // load each of the newly added children into the session and get their paths
            final long newChildCount = childCountAtBatchStart + newChildrenCount;

            for (long j = childCountAtBatchStart; j < newChildCount; j++) {
                final String childAbsPath = "/testRoot/childNode[" + j + "]";
                final Node child = session.getNode(childAbsPath);
                child.getPath();
                child.getName();
            }
            readSW.lap();

            // change the parent & save so that it's flushed from the cache
            session.getNode("/testRoot").setProperty("test", "test");
            session.save();

            // now get the paths of each child via parent relative path navigation
            for (long j = childCountAtBatchStart; j <= newChildCount; j++) {
                final String childName = "childNode[" + j + "]";
                final Node child = session.getNode("/testRoot").getNode(childName);
                child.getPath();
                child.getName();
            }
            readSW.lap();

            // change the parent & save so that it's flushed from the cache
            session.getNode("/testRoot").setProperty("test", "test1");
            session.save();

            // iterate through all the children of the parent and read the path
            NodeIterator nodeIterator = session.getNode("/testRoot").getNodes();
            while (nodeIterator.hasNext()) {
                final Node child = nodeIterator.nextNode();
                child.getPath();
                child.getName();
            }
            readSW.stop();
            if (print) {
                System.out.println("Time to read batch " + i + " : " + readSW.getSimpleStatistics());
            }
            readSW.reset();

            // change the parent & save so that it's flushed from the cache
            session.getNode("/testRoot").setProperty("test", "test2");
            session.save();
View Full Code Here

        int propertiesPerNode = 0;
        String nodeType = "nt:unstructured";

        session.getRootNode().addNode("testRoot", nodeType);
        session.save();
        Stopwatch sw = new Stopwatch();
        sw.start();
        int totalNumberOfNodes = createSubgraphBreadthFirst(1, nodeType, "/testRoot", totalNodeCount, childrenPerNode,
                                                            propertiesPerNode, true);
        sw.stop();
        System.out.println("Total time to insert " + totalNumberOfNodes + " nodes in batches of " + childrenPerNode + ": "
                           + sw.getSimpleStatistics());
    }
View Full Code Here

        int propertiesPerNode = 0;
        String nodeType = "nt:folder";

        session.getRootNode().addNode("testRoot", nodeType);
        session.save();
        Stopwatch sw = new Stopwatch();
        sw.start();
        int totalNumberOfNodes = createSubgraphBreadthFirst(1, nodeType, "/testRoot", totalNodeCount, childrenPerNode,
                                                            propertiesPerNode, false);
        sw.stop();
        System.out.println("Total time to insert " + totalNumberOfNodes + " nodes in batches of " + childrenPerNode + ": "
                           + sw.getSimpleStatistics());
    }
View Full Code Here

        int propertiesPerNode = 0;
        String nodeType = "nt:unstructured";

        session.getRootNode().addNode("testRoot", nodeType);
        session.save();
        Stopwatch sw = new Stopwatch();
        sw.start();
        int totalNumberOfNodes = createSubgraphDepthFirst(nodeType, "/testRoot", totalNodeCount, childrenPerNode,
                                                          propertiesPerNode, true);
        sw.stop();
        System.out.println("Total time to insert " + totalNumberOfNodes + " nodes in batches of " + childrenPerNode + ": "
                           + sw.getSimpleStatistics());
    }
View Full Code Here

        int propertiesPerNode = 0;
        String nodeType = "nt:folder";

        session.getRootNode().addNode("testRoot", nodeType);
        session.save();
        Stopwatch sw = new Stopwatch();
        sw.start();
        int totalNumberOfNodes = createSubgraphDepthFirst(nodeType, "/testRoot", totalNodeCount, childrenPerNode,
                                                          propertiesPerNode, false);
        sw.stop();
        System.out.println("Total time to insert " + totalNumberOfNodes + " nodes in batches of " + childrenPerNode + ": "
                           + sw.getSimpleStatistics());
    }
View Full Code Here

        if (totalNumberOfNodes < numberOfChildrenPerNode) {
            numberOfChildrenPerNode = totalNumberOfNodes;
        }

        List<String> childPaths = new ArrayList<String>();
        Stopwatch sw = new Stopwatch();
        sw.start();

        Node parentNode = session.getNode(parentAbsPath);
        for (int i = 0; i != numberOfChildrenPerNode; ++i) {
            Node child = parentNode.addNode(useSns ? "childNode" : ("childNode" + i), nodeType);
            for (int j = 0; j != numberOfPropertiesPerNode; ++j) {
                String value = (i % 5 == 0) ? LARGE_STRING_VALUE : SMALL_STRING_VALUE;
                child.setProperty("property" + j, value);
            }
            numberCreated++;
            childPaths.add(child.getPath());
        }
        session.save();
        sw.stop();
        System.out.println("Time to insert " + numberCreated + " nodes on level " + level + ": " + sw.getSimpleStatistics());

        if (numberCreated == totalNumberOfNodes) {
            return numberCreated;
        }
        int remainingNodes = totalNumberOfNodes - numberCreated;
View Full Code Here

        if (totalNumberOfNodes < numberOfChildrenPerNode) {
            numberOfChildrenPerNode = totalNumberOfNodes;
        }

        String firstChildPath;
        Stopwatch sw = new Stopwatch();
        sw.start();
        int level = 1;
        do {
            sw.reset();
            sw.start();
            firstChildPath = null;
            Node parentNode = session.getNode(parentAbsPath);

            for (int i = 0; i != numberOfChildrenPerNode; ++i) {
                Node child = parentNode.addNode(useSns ? "childNode" : ("childNode" + i), nodeType);
                for (int j = 0; j != numberOfPropertiesPerNode; ++j) {
                    String value = (i % 5 == 0) ? LARGE_STRING_VALUE : SMALL_STRING_VALUE;
                    child.setProperty("property" + j, value);
                }
                if (firstChildPath == null) {
                    firstChildPath = child.getPath();
                }
            }
            session.save();
            sw.stop();
            System.out.println("Time to insert " + numberOfChildrenPerNode + " nodes on level " + level++ + ": "
                               + sw.getSimpleStatistics());
            totalNumberOfNodes -= numberOfChildrenPerNode;
            parentAbsPath = firstChildPath;

        } while (totalNumberOfNodes > 0);
        return totalNumberOfNodes;
View Full Code Here

TOP

Related Classes of org.modeshape.common.statistic.Stopwatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.