jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r949722 - in /jackrabbit/commons/jcr-benchmark/trunk: pom.xml src/main/java/org/apache/jackrabbit/benchmark/LogoutAfterReadTest.java src/main/java/org/apache/jackrabbit/benchmark/PerformanceTestSuite.java
Date Mon, 31 May 2010 11:58:58 GMT
Author: mreutegg
Date: Mon May 31 11:58:58 2010
New Revision: 949722

URL: http://svn.apache.org/viewvc?rev=949722&view=rev
Log:
JCR-2643: Avoid item state reads during Session.logout()

Added:
    jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/LogoutAfterReadTest.java
  (with props)
Modified:
    jackrabbit/commons/jcr-benchmark/trunk/pom.xml
    jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/PerformanceTestSuite.java

Modified: jackrabbit/commons/jcr-benchmark/trunk/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-benchmark/trunk/pom.xml?rev=949722&r1=949721&r2=949722&view=diff
==============================================================================
--- jackrabbit/commons/jcr-benchmark/trunk/pom.xml (original)
+++ jackrabbit/commons/jcr-benchmark/trunk/pom.xml Mon May 31 11:58:58 2010
@@ -61,12 +61,12 @@
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-jcr-tests</artifactId>
-      <version>2.1-SNAPSHOT</version>
+      <version>2.2-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-core</artifactId>
-      <version>2.1-SNAPSHOT</version>
+      <version>2.2-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>

Added: jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/LogoutAfterReadTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/LogoutAfterReadTest.java?rev=949722&view=auto
==============================================================================
--- jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/LogoutAfterReadTest.java
(added)
+++ jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/LogoutAfterReadTest.java
Mon May 31 11:58:58 2010
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.benchmark;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+/**
+ * <code>LogoutAfterReadTest</code> implements a performance test that logs out
+ * sessions using multiple threads after some reading was done. See JCR-2643.
+ */
+public class LogoutAfterReadTest extends PerformanceTest {
+
+    private static final String TEST_CONTENT = "test-content";
+
+    private static final int NUM_SESSIONS = 1000;
+
+    private static final int NUM_THREADS = 8;
+
+    private List<String> identifiers = new ArrayList<String>();
+
+    private Session[] sessions = new Session[NUM_SESSIONS];
+
+    private ExecutorService executor;
+
+    @Override
+    public String toString() {
+        return NUM_SESSIONS + " x logout() after reads";
+    }
+
+    @Override
+    public void beforeSuite() throws Exception {
+        super.beforeSuite();
+        identifiers.clear();
+        Session session = createSession();
+        Node test;
+        if (!session.getRootNode().hasNode(TEST_CONTENT)) {
+            test = session.getRootNode().addNode(TEST_CONTENT);
+        } else {
+            test = session.getRootNode().getNode(TEST_CONTENT);
+        }
+        createNodes(identifiers, test, 10, 3, 0, 1000);
+    }
+
+    @Override
+    public void beforeTest() throws Exception {
+        super.beforeTest();
+        Random rand = new Random();
+        for (int i = 0; i < sessions.length; i++) {
+            Session s = createSession();
+            sessions[i] = s;
+            for (int j = 0; j < 100; j++) {
+                s.getNodeByIdentifier(identifiers.get(rand.nextInt(identifiers.size())));
+            }
+        }
+        executor = Executors.newFixedThreadPool(NUM_THREADS);
+    }
+
+    @Override
+    public void runTest() throws Exception {
+        for (Session session : sessions) {
+            final Session s = session;
+            executor.execute(new Runnable() {
+                public void run() {
+                    s.logout();
+                }
+            });
+        }
+        executor.shutdown();
+        executor.awaitTermination(1, TimeUnit.HOURS);
+    }
+
+    @Override
+    public void afterSuite() throws Exception {
+        Session session = createSession();
+        try {
+            if (session.getRootNode().hasNode(TEST_CONTENT)) {
+                session.getRootNode().getNode(TEST_CONTENT).remove();
+                session.save();
+            }
+        } finally {
+            session.logout();
+        }
+        super.afterSuite();
+    }
+
+    private Session createSession() throws Exception {
+        return getRepository().login(getCredentials());
+    }
+
+    private int createNodes(List<String> identifiers,
+                            Node n,
+                            int nodesPerLevel,
+                            int levels,
+                            int count,
+                            int saveInterval)
+            throws RepositoryException {
+        levels--;
+        for (int i = 0; i < nodesPerLevel; i++) {
+            Node child = n.addNode("node" + i);
+            identifiers.add(child.getIdentifier());
+            count++;
+            if (count % saveInterval == 0) {
+                n.getSession().save();
+            }
+            if (levels > 0) {
+                count = createNodes(identifiers, child, nodesPerLevel,
+                        levels, count, saveInterval);
+            }
+        }
+        if (levels == 0) {
+            // final save
+            n.getSession().save();
+        }
+        return count;
+    }
+}

Propchange: jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/LogoutAfterReadTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/PerformanceTestSuite.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/PerformanceTestSuite.java?rev=949722&r1=949721&r2=949722&view=diff
==============================================================================
--- jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/PerformanceTestSuite.java
(original)
+++ jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/PerformanceTestSuite.java
Mon May 31 11:58:58 2010
@@ -107,6 +107,7 @@ public class PerformanceTestSuite {
             new PerformanceTestSuite(repository, credentials);
         suite.runTest(new LoginTest());
         suite.runTest(new LoginLogoutTest());
+        suite.runTest(new LogoutAfterReadTest());
         // suite.runTest(new RefreshTest());
         // suite.runTest(new SmallFileReadTest());
         // suite.runTest(new SmallFileWriteTest());



Mime
View raw message