jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1449733 - in /jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark: AbstractTest.java Benchmark.java BenchmarkRunner.java wikipedia/ wikipedia/WikipediaImport.java
Date Mon, 25 Feb 2013 14:52:26 GMT
Author: jukka
Date: Mon Feb 25 14:52:26 2013
New Revision: 1449733

URL: http://svn.apache.org/r1449733
Log:
OAK-641: Improved benchmark tooling

Add a simple Wikipedia import benchmark

Added:
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/wikipedia/
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/wikipedia/WikipediaImport.java
Modified:
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/Benchmark.java
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/BenchmarkRunner.java

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java?rev=1449733&r1=1449732&r2=1449733&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java
Mon Feb 25 14:52:26 2013
@@ -32,7 +32,7 @@ import org.apache.jackrabbit.oak.fixture
 /**
  * Abstract base class for individual performance benchmarks.
  */
-public abstract class AbstractTest implements Benchmark {
+abstract class AbstractTest extends Benchmark {
 
     private Repository repository;
 
@@ -280,9 +280,4 @@ public abstract class AbstractTest imple
         threads.add(thread);
     }
 
-    public String toString() {
-        String name = getClass().getName();
-        return name.substring(name.lastIndexOf('.') + 1);
-    }
-
 }

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/Benchmark.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/Benchmark.java?rev=1449733&r1=1449732&r2=1449733&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/Benchmark.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/Benchmark.java
Mon Feb 25 14:52:26 2013
@@ -18,7 +18,7 @@ package org.apache.jackrabbit.oak.benchm
 
 import org.apache.jackrabbit.oak.fixture.RepositoryFixture;
 
-public interface Benchmark {
+public abstract class Benchmark {
 
     /**
      * Runs this benchmark against all the given repository fixtures.
@@ -26,6 +26,11 @@ public interface Benchmark {
      *
      * @param fixtures repository fixtures
      */
-    void run(Iterable<RepositoryFixture> fixtures);
+    public abstract void run(Iterable<RepositoryFixture> fixtures);
+
+    public String toString() {
+        String name = getClass().getName();
+        return name.substring(name.lastIndexOf('.') + 1);
+    }
 
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/BenchmarkRunner.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/BenchmarkRunner.java?rev=1449733&r1=1449732&r2=1449733&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/BenchmarkRunner.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/BenchmarkRunner.java
Mon Feb 25 14:52:26 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.benchmark;
 
+import java.io.File;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
@@ -24,6 +25,7 @@ import joptsimple.OptionParser;
 import joptsimple.OptionSet;
 import joptsimple.OptionSpec;
 
+import org.apache.jackrabbit.oak.benchmark.wikipedia.WikipediaImport;
 import org.apache.jackrabbit.oak.fixture.JackrabbitRepositoryFixture;
 import org.apache.jackrabbit.oak.fixture.OakRepositoryFixture;
 import org.apache.jackrabbit.oak.fixture.RepositoryFixture;
@@ -56,6 +58,9 @@ public class BenchmarkRunner {
                 .withRequiredArg().defaultsTo("localhost");
         OptionSpec<Integer> port = parser.accepts("port", "MongoDB port")
                 .withRequiredArg().ofType(Integer.class).defaultsTo(27017);
+        OptionSpec<File> wikipedia =
+                parser.accepts("wikipedia", "Wikipedia dump")
+                .withRequiredArg().ofType(File.class);
 
         OptionSet options = parser.parse(args);
         RepositoryFixture[] allFixtures = new RepositoryFixture[] {
@@ -65,6 +70,24 @@ public class BenchmarkRunner {
                 OakRepositoryFixture.getMongo(host.value(options), port.value(options)),
                 OakRepositoryFixture.getSegment(host.value(options), port.value(options))
         };
+        Benchmark[] allBenchmarks = new Benchmark[] {
+            new LoginTest(),
+            new LoginLogoutTest(),
+            new ReadPropertyTest(),
+            new SetPropertyTest(),
+            new SmallFileReadTest(),
+            new SmallFileWriteTest(),
+            new ConcurrentReadTest(),
+            new ConcurrentReadWriteTest(),
+            new SimpleSearchTest(),
+            new SQL2SearchTest(),
+            new DescendantSearchTest(),
+            new SQL2DescendantSearchTest(),
+            new CreateManyChildNodesTest(),
+            new UpdateManyChildNodesTest(),
+            new TransientManyChildNodesTest(),
+            new WikipediaImport(wikipedia.value(options))
+        };
 
         Set<String> argset = Sets.newHashSet(options.nonOptionArguments());
         List<RepositoryFixture> fixtures = Lists.newArrayList();
@@ -73,19 +96,13 @@ public class BenchmarkRunner {
                 fixtures.add(fixture);
             }
         }
-        if (fixtures.isEmpty()) {
-            fixtures = Arrays.asList(allFixtures);
-        }
 
         List<Benchmark> benchmarks = Lists.newArrayList();
-        for (Benchmark benchmark : BENCHMARKS) {
+        for (Benchmark benchmark : allBenchmarks) {
             if (argset.remove(benchmark.toString())) {
                 benchmarks.add(benchmark);
             }
         }
-        if (benchmarks.isEmpty()) {
-            benchmarks = Arrays.asList(BENCHMARKS);
-        }
 
         if (argset.isEmpty()) {
             for (Benchmark benchmark : benchmarks) {
@@ -94,7 +111,6 @@ public class BenchmarkRunner {
         } else {
             System.err.println("Unknown arguments: " + argset);
         }
-
     }
 
 }

Added: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/wikipedia/WikipediaImport.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/wikipedia/WikipediaImport.java?rev=1449733&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/wikipedia/WikipediaImport.java
(added)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/wikipedia/WikipediaImport.java
Mon Feb 25 14:52:26 2013
@@ -0,0 +1,123 @@
+/*
+ * 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.oak.benchmark.wikipedia;
+
+import java.io.File;
+
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.jackrabbit.oak.benchmark.Benchmark;
+import org.apache.jackrabbit.oak.fixture.RepositoryFixture;
+import org.apache.jackrabbit.util.Text;
+
+public class WikipediaImport extends Benchmark {
+
+    private final File dump;
+
+    public WikipediaImport(File dump) {
+        this.dump = dump;
+    }
+
+    @Override
+    public void run(Iterable<RepositoryFixture> fixtures) {
+        if (dump.isFile()) {
+            System.out.format("Wikipedia import (%s)%n", dump);
+            for (RepositoryFixture fixture : fixtures) {
+                if (fixture.isAvailable(1)) {
+                    try {
+                        System.out.format("%s: importing Wikipedia...%n", fixture);
+                        Repository[] cluster = fixture.setUpCluster(1);
+                        try {
+                            run(cluster[0]);
+                        } finally {
+                            fixture.tearDownCluster();
+                        }
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                } else {
+                    System.out.format("%s: not available, skipping.%n", fixture);
+                }
+            }
+        } else {
+            System.out.format(
+                    "Missing Wikipedia dump %s, skipping import benchmark.%n",
+                    dump.getPath());
+        }
+    }
+
+    private void run(Repository repository) throws Exception {
+        long start = System.currentTimeMillis();
+        int pages = 0;
+
+        Session session = repository.login(
+                new SimpleCredentials("admin", "admin".toCharArray()));
+        try {
+            Node wikipedia = session.getRootNode().addNode("wikipedia");
+
+            String title = null;
+            String text = null;
+            XMLInputFactory factory = XMLInputFactory.newInstance();
+            XMLStreamReader reader =
+                    factory.createXMLStreamReader(new StreamSource(dump));
+            while (reader.hasNext()) {
+                switch (reader.next()) {
+                case XMLStreamConstants.START_ELEMENT:
+                    if ("title".equals(reader.getLocalName())) {
+                        title = reader.getElementText();
+                    } else if ("text".equals(reader.getLocalName())) {
+                        text = reader.getElementText();
+                    }
+                    break;
+                case XMLStreamConstants.END_ELEMENT:
+                    if ("page".equals(reader.getLocalName())) {
+                        String name = Text.escapeIllegalJcrChars(title);
+                        Node page = wikipedia.addNode(name);
+                        page.setProperty("title", title);
+                        page.setProperty("text", text);
+                        pages++;
+                        if (pages % 1000 == 0) {
+                            long millis = System.currentTimeMillis() - start;
+                            System.out.format(
+                                    "Imported %d pages in %d seconds (%dus/page)%n",
+                                    pages, millis / 1000, millis * 1000 / pages);
+                        }
+
+                    }
+                    break;
+                }
+            }
+
+            session.save();
+        } finally {
+            session.logout();
+        }
+
+        long millis = System.currentTimeMillis() - start;
+        System.out.format(
+                "Imported %d pages in %d seconds (%dus/page)%n",
+                pages, millis / 1000, millis * 1000 / pages);
+    }
+
+}



Mime
View raw message