jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1529176 - /jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/
Date Fri, 04 Oct 2013 15:12:50 GMT
Author: jukka
Date: Fri Oct  4 15:12:49 2013
New Revision: 1529176

URL: http://svn.apache.org/r1529176
Log:
OAK-1046: Faster anonymous read operations

Move the getTestSession() call to outside the runTest() method to prevent the slow login()
performance (OAK-634) from masking other performance issues.
Refactory the DeepTreeTests to reduce duplication of code.

Removed:
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractDeepTreeTest.java
Modified:
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest.java
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadDeepTreeTest.java
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/CreateNodesBenchmark.java
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ReadDeepTreeTest.java

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest.java?rev=1529176&r1=1529175&r2=1529176&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest.java
Fri Oct  4 15:12:49 2013
@@ -19,7 +19,6 @@ package org.apache.jackrabbit.oak.benchm
 import javax.jcr.ItemVisitor;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 import javax.jcr.security.AccessControlList;
 import javax.jcr.security.AccessControlManager;
 import javax.jcr.security.AccessControlPolicy;
@@ -35,7 +34,8 @@ import org.apache.jackrabbit.util.Text;
  * Concurrently reads random items from the deep tree where every 10th node is
  * access controlled.
  */
-public class ConcurrentReadAccessControlledTreeTest extends AbstractDeepTreeTest {
+public class ConcurrentReadAccessControlledTreeTest
+        extends ConcurrentReadDeepTreeTest {
 
     public ConcurrentReadAccessControlledTreeTest(
             boolean runAsAdmin, int itemsToRead, int bgReaders, boolean doReport) {
@@ -90,34 +90,6 @@ public class ConcurrentReadAccessControl
         };
 
         visitor.visit(testRoot);
-
-        for (int i = 0; i < bgReaders; i++) {
-            addBackgroundJob(new RandomRead(getTestSession()));
-        }
-    }
-
-    @Override
-    protected void runTest() throws Exception {
-        Session testSession = getTestSession();
-        RandomRead randomRead = new RandomRead(testSession);
-        randomRead.run();
-        testSession.logout();
     }
 
-    private class RandomRead implements Runnable {
-
-        private final Session testSession;
-
-        private RandomRead(Session testSession) {
-            this.testSession = testSession;
-        }
-
-        public void run() {
-            try {
-                randomRead(testSession, allPaths, itemsToRead);
-            } catch (RepositoryException e) {
-                throw new RuntimeException(e);
-            }
-        }
-    }
-}
\ No newline at end of file
+}

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadDeepTreeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadDeepTreeTest.java?rev=1529176&r1=1529175&r2=1529176&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadDeepTreeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadDeepTreeTest.java
Fri Oct  4 15:12:49 2013
@@ -16,50 +16,14 @@
  */
 package org.apache.jackrabbit.oak.benchmark;
 
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
 /**
  * Concurrently reads random items from the deep tree.
  */
-public class ConcurrentReadDeepTreeTest extends AbstractDeepTreeTest {
+public class ConcurrentReadDeepTreeTest extends ReadDeepTreeTest {
 
     public ConcurrentReadDeepTreeTest(
             boolean runAsAdmin, int itemsToRead, int bgReaders, boolean doReport) {
         super(runAsAdmin, itemsToRead, bgReaders, doReport);
     }
 
-    @Override
-    protected void beforeSuite() throws Exception {
-        super.beforeSuite();
-
-        for (int i = 0; i < bgReaders; i++) {
-            addBackgroundJob(new RandomRead(getTestSession()));
-        }
-    }
-
-    @Override
-    protected void runTest() throws Exception {
-        Session testSession = getTestSession();
-        RandomRead randomRead = new RandomRead(testSession);
-        randomRead.run();
-        testSession.logout();
-    }
-
-    private class RandomRead implements Runnable {
-
-        private final Session testSession;
-
-        private RandomRead(Session testSession) {
-            this.testSession = testSession;
-        }
-
-        public void run() {
-            try {
-                randomRead(testSession, allPaths, itemsToRead);
-            } catch (RepositoryException e) {
-                throw new RuntimeException(e);
-            }
-        }
-    }
-}
\ No newline at end of file
+}

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/CreateNodesBenchmark.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/CreateNodesBenchmark.java?rev=1529176&r1=1529175&r2=1529176&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/CreateNodesBenchmark.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/CreateNodesBenchmark.java
Fri Oct  4 15:12:49 2013
@@ -56,30 +56,34 @@ public class CreateNodesBenchmark extend
         Session session = repository.login(
                 new SimpleCredentials("admin", "admin".toCharArray()));
         AtomicInteger count = new AtomicInteger();
-        long time = System.currentTimeMillis();
+        long startTime = System.currentTimeMillis();
         Node testRoot = session.getRootNode().addNode("r" + AbstractTest.TEST_ID);
-        createNodes(testRoot, 10, 5, count);
-        time = System.currentTimeMillis() - time;
+        createNodes(testRoot, 20, 6, count, startTime);
+        long duration = System.currentTimeMillis() - startTime;
         System.out.format(
                 "Created %d nodes in %d seconds (%.2fms/node)%n",
-                count.get(), time / 1000, (double) time / count.get());
+                count.get(), duration / 1000, (double) duration / count.get());
     }
 
     private void createNodes(Node n, int nodesPerLevel,
-                            int levels, AtomicInteger count)
+                            int levels, AtomicInteger count, long startTime)
             throws RepositoryException {
         levels--;
         List<Node> nodes = new ArrayList<Node>();
         for (int i = 0; i < nodesPerLevel; i++) {
             nodes.add(n.addNode("folder-" + i, "nt:folder"));
             if (count.incrementAndGet() % 1000 == 0) {
-                System.out.format("Created %d nodes so far...%n", count.get());
+                long duration = System.currentTimeMillis() - startTime;
+                System.out.format(
+                        "Created %d nodes in %d seconds (%.2fms/node)...%n",
+                        count.get(), duration / 1000,
+                        (double) duration / count.get());
             }
         }
         n.getSession().save();
         if (levels > 0) {
             for (Node child : nodes) {
-                createNodes(child, nodesPerLevel, levels, count);
+                createNodes(child, nodesPerLevel, levels, count, startTime);
             }
         }
     }

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ReadDeepTreeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ReadDeepTreeTest.java?rev=1529176&r1=1529175&r2=1529176&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ReadDeepTreeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ReadDeepTreeTest.java
Fri Oct  4 15:12:49 2013
@@ -16,27 +16,145 @@
  */
 package org.apache.jackrabbit.oak.benchmark;
 
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.Item;
+import javax.jcr.ItemVisitor;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.util.TraversingItemVisitor;
 
 /**
  * Randomly read 1000 items from the deep tree.
  */
-public class ReadDeepTreeTest extends AbstractDeepTreeTest {
+public class ReadDeepTreeTest extends AbstractTest {
+
+    protected final boolean runAsAdmin;
+    protected final int itemsToRead;
+    protected final int bgReaders;
+    protected final boolean doReport;
+
+    protected Session adminSession;
+    protected Node testRoot;
+
+    private Session testSession;
+
+    protected List<String> allPaths;
+
+    protected ReadDeepTreeTest(
+            boolean runAsAdmin, int itemsToRead, int bgReaders, boolean doReport) {
+        this.runAsAdmin = runAsAdmin;
+        this.itemsToRead = itemsToRead;
+        this.bgReaders = bgReaders;
+        this.doReport = doReport;
+    }
 
     public ReadDeepTreeTest(
             boolean runAsAdmin, int itemsToRead, boolean doReport) {
-        super(runAsAdmin, itemsToRead, 0, doReport);
+        this(runAsAdmin, itemsToRead, 0, doReport);
     }
 
     @Override
     protected void beforeSuite() throws Exception {
-        super.beforeSuite();
+        adminSession = loginWriter();
+        String name = getClass().getSimpleName() + TEST_ID;
+        Node rn = adminSession.getRootNode();
+
+        long start = System.currentTimeMillis();
+        if (!rn.hasNode(name)) {
+            testRoot = adminSession.getRootNode().addNode(name, "nt:unstructured");
+            InputStream in = getClass().getClassLoader().getResourceAsStream("deepTree.xml");
+            adminSession.importXML(testRoot.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+            adminSession.save();
+        } else {
+            testRoot = rn.getNode(name);
+        }
+        System.out.println("Import deep tree: " + (System.currentTimeMillis()-start));
+
+        final List<String> paths = new ArrayList<String>();
+        ItemVisitor v = new TraversingItemVisitor.Default() {
+            @Override
+            protected void entering(Node node, int i) throws RepositoryException {
+                paths.add(node.getPath());
+                super.entering(node, i);
+            }
+            @Override
+            protected void entering(Property prop, int i) throws RepositoryException {
+                paths.add(prop.getPath());
+                super.entering(prop, i);
+            }
+        };
+        v.visit(testRoot);
+        allPaths = paths;
+
+        System.out.println("All paths: " + allPaths.size());
+
+        for (int i = 0; i < bgReaders; i++) {
+            final Session session = getTestSession();
+            addBackgroundJob(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        randomRead(session, allPaths, itemsToRead);
+                    } catch (RepositoryException e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+            });
+        }
+
+        testSession = getTestSession();
+    }
+
+    @Override
+    protected void afterSuite() throws Exception {
+        testRoot.remove();
+        adminSession.save();
     }
 
     @Override
     protected void runTest() throws Exception {
-        Session testSession = getTestSession();
         randomRead(testSession, allPaths, itemsToRead);
-        testSession.logout();
     }
-}
\ No newline at end of file
+
+    protected void randomRead(Session testSession, List<String> allPaths, int cnt)
throws RepositoryException {
+        int nodeCnt = 0;
+        int propertyCnt = 0;
+        int noAccess = 0;
+        int size = allPaths.size();
+        long start = System.currentTimeMillis();
+        for (int i = 0; i < cnt; i++) {
+            double rand = size * Math.random();
+            int index = (int) Math.floor(rand);
+            String path = allPaths.get(index);
+            if (testSession.itemExists(path)) {
+                Item item = testSession.getItem(path);
+                if (item.isNode()) {
+                    nodeCnt++;
+                } else {
+                    propertyCnt++;
+                }
+            } else {
+                noAccess++;
+            }
+        }
+        long end = System.currentTimeMillis();
+        if (doReport) {
+            System.out.println("Session " + testSession.getUserID() + " reading " + (cnt-noAccess)
+ " (Nodes: "+ nodeCnt +"; Properties: "+propertyCnt+") completed in " + (end - start));
+        }
+    }
+
+    protected Session getTestSession() {
+        if (runAsAdmin) {
+            return loginWriter();
+        } else {
+            return loginAnonymous();
+        }
+    }
+
+}



Mime
View raw message