Search in sources :

Example 1 with Profiler

use of org.h2.util.Profiler in project jackrabbit-oak by apache.

the class ManyChildrenTest method manyChildrenWithoutIndex.

@Test
public void manyChildrenWithoutIndex() throws Exception {
    if (session == null) {
        return;
    }
    Node index = session.getRootNode().getNode("oak:index");
    if (index.hasNode("nodetype")) {
        index.getNode("nodetype").remove();
        session.save();
    }
    long start = System.currentTimeMillis(), last = start;
    // to test with more nodes, use:
    // int count = 1000000;
    int count = 10;
    Profiler prof = null;
    String nodeType = NodeTypeConstants.NT_OAK_UNSTRUCTURED;
    if (session.getRootNode().hasNode("many")) {
        session.getRootNode().getNode("many").remove();
        session.save();
    }
    Node many = session.getRootNode().addNode("many", nodeType);
    for (int i = 0; i < count; i++) {
        Node n = many.addNode("test" + i, nodeType);
        n.setProperty("prop", i);
        if (i % 100 == 0) {
            session.save();
        }
        long now = System.currentTimeMillis();
        if (now - last > 5000) {
            int opsPerSecond = (int) (i * 1000 / (now - start));
            System.out.println(i + " ops; " + opsPerSecond + " op/s");
            last = now;
            if (prof != null) {
                System.out.println(prof.getTop(5));
            }
            if (opsPerSecond < 1000 && i % 100 == 0) {
                prof = new Profiler();
                prof.startCollecting();
            }
        }
    }
    start = System.currentTimeMillis();
    last = start;
    for (int i = 0; i < count; i++) {
        Node n = many.getNode("test" + i);
        long x = n.getProperty("prop").getValue().getLong();
        assertEquals(i, x);
        long now = System.currentTimeMillis();
        if (now - last > 5000) {
            int opsPerSecond = (int) (i * 1000 / (now - start));
            System.out.println(i + " read ops; " + opsPerSecond + " op/s");
            last = now;
            if (prof != null) {
                System.out.println(prof.getTop(5));
            }
            if (opsPerSecond < 1000 && i % 100 == 0) {
                prof = new Profiler();
                prof.startCollecting();
            }
        }
    }
}
Also used : Profiler(org.h2.util.Profiler) Node(javax.jcr.Node) Test(org.junit.Test)

Example 2 with Profiler

use of org.h2.util.Profiler in project jackrabbit-oak by apache.

the class SlowObservationIT method observation.

@Test
public void observation() throws Exception {
    if (!isDocumentNodeStore()) {
        return;
    }
    AtomicBoolean saveInObservation = new AtomicBoolean();
    saveInObservation.set(true);
    ArrayList<MyListener> listeners = new ArrayList<MyListener>();
    for (int i = 0; i < OBSERVER_COUNT; i++) {
        Session observingSession = createAdminSession();
        MyListener listener = new MyListener(i, observingSession, saveInObservation);
        listener.open();
        listeners.add(listener);
    }
    log("Starting...");
    Profiler prof = null;
    long start = System.currentTimeMillis();
    for (int i = 1; ; i++) {
        if (prof == null && PROFILE) {
        // prof = new Profiler().startCollecting();
        }
        long time = System.currentTimeMillis() - start;
        if (time > 20 * 1000) {
            if (saveInObservation.get()) {
                log("Disable saves in observation now");
                saveInObservation.set(false);
            }
        }
        if (time > 30 * 1000) {
            break;
        }
        Node testNode;
        if (i % 100 < 52) {
            // in 52% of the cases, use testNode
            testNode = getNode(TEST_PATH);
        } else {
            // in 48% of the cases, use testNode2
            testNode = getNode(TEST2_PATH);
        }
        String a = "c-" + (i / 40);
        String b = "c-" + (i % 40);
        Node x;
        if (testNode.hasNode(a)) {
            x = testNode.getNode(a);
        } else {
            x = testNode.addNode(a, "oak:Unstructured");
        }
        Node t = x.addNode(b, "oak:Unstructured");
        for (int j = 0; j < 10; j++) {
            t.addNode("c-" + j, "oak:Unstructured");
        }
        long saveTime = System.currentTimeMillis();
        getAdminSession().save();
        saveTime = System.currentTimeMillis() - saveTime;
        if (saveTime > 100 || i % 200 == 0) {
            if (prof != null) {
                log(prof.getTop(1));
                prof = null;
            }
            log("Save #" + i + " took " + saveTime + " ms");
        }
    }
    log("Stopping...");
    for (MyListener listener : listeners) {
        listener.stop();
        listener.waitUntilDone();
        listener.close();
    }
    log("Done");
    if (PROFILE) {
        printFullThreadDump();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Profiler(org.h2.util.Profiler) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) Session(javax.jcr.Session) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Aggregations

Node (javax.jcr.Node)2 Profiler (org.h2.util.Profiler)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Session (javax.jcr.Session)1 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)1