jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r982252 - /jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/ConcurrentReadTest.java
Date Wed, 04 Aug 2010 14:00:20 GMT
Author: jukka
Date: Wed Aug  4 14:00:19 2010
New Revision: 982252

URL: http://svn.apache.org/viewvc?rev=982252&view=rev
Log:
JCR-2699: Improve read/write concurrency

Add a simple concurrent reader test

Added:
    jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/ConcurrentReadTest.java
  (with props)

Added: jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/ConcurrentReadTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/ConcurrentReadTest.java?rev=982252&view=auto
==============================================================================
--- jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/ConcurrentReadTest.java
(added)
+++ jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/ConcurrentReadTest.java
Wed Aug  4 14:00:19 2010
@@ -0,0 +1,116 @@
+/*
+ * 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 javax.jcr.ItemVisitor;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+/**
+ * Test case that creates 10k nt:folder nodes (100x100) and starts 50
+ * concurrent readers to traverse this content tree.
+ */
+public class ConcurrentReadTest extends PerformanceTest {
+
+    private static final int FOLDER_COUNT = 100;
+
+    private static final int CLIENT_COUNT = 50;
+
+    private Session session;
+
+    private Node root;
+
+    private Session[] clients = new Session[CLIENT_COUNT];
+
+    public void beforeSuite() throws RepositoryException {
+        session = getRepository().login(getCredentials());
+
+        root = session.getRootNode().addNode(
+                "ConcurrentReadTest", "nt:folder");
+        for (int i = 0; i < FOLDER_COUNT; i++) {
+            Node folder = root.addNode("folder" + i, "nt:folder");
+            for (int j = 0; j < FOLDER_COUNT; j++) {
+                folder.addNode("folder" + j, "nt:folder");
+            }
+            session.save();
+        }
+
+        for (int i = 0; i < clients.length; i++) {
+            clients[i] = getRepository().login();
+        }
+    }
+
+    private static class Traversal implements Runnable, ItemVisitor {
+
+        private final Node root;
+
+        public Traversal(Session session) throws RepositoryException {
+            this.root = session.getRootNode().getNode("ConcurrentReadTest");
+        }
+
+        public void run() {
+            try {
+                root.accept(this);
+            } catch (RepositoryException e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        public void visit(Node node) throws RepositoryException {
+            NodeIterator iterator = node.getNodes();
+            while (iterator.hasNext()) {
+                iterator.nextNode().accept(this);
+            }
+        }
+
+        public void visit(Property property) {
+        }
+
+    }
+
+    public void runTest() throws Exception {
+        Thread[] threads = new Thread[clients.length];
+        for (int i = 0; i < threads.length; i++) {
+            threads[i] = new Thread(new Traversal(clients[i]));
+        }
+        for (int i = 0; i < threads.length; i++) {
+            threads[i].start();
+        }
+        for (int i = 0; i < threads.length; i++) {
+            threads[i].join();
+        }
+    }
+
+    public void afterSuite() throws RepositoryException {
+        for (int i = 0; i < clients.length; i++) {
+            clients[i].logout();
+        }
+
+        for (int i = 0; i < FOLDER_COUNT; i++) {
+            root.getNode("folder" + i).remove();
+            session.save();
+        }
+
+        root.remove();
+        session.save();
+        session.logout();
+    }
+
+}

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



Mime
View raw message