Author: chetanm
Date: Thu Sep 15 07:18:08 2016
New Revision: 1760854

URL: http://svn.apache.org/viewvc?rev=1760854&view=rev
Log:
OAK-4412 - Lucene hybrid index

Benchmarking - Introduce a notion of mutator which would change the indexed 
property values. Also make stats provider static such that it can be used in 
DocumentNodeStore for testing purpose

Modified:
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/HybridIndexTest.java

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/HybridIndexTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/HybridIndexTest.java?rev=1760854&r1=1760853&r2=1760854&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/HybridIndexTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/HybridIndexTest.java
 Thu Sep 15 07:18:08 2016
@@ -21,6 +21,7 @@ package org.apache.jackrabbit.oak.benchm
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Queue;
 import java.util.Random;
@@ -84,8 +85,14 @@ import static org.apache.jackrabbit.oak.
 
 public class HybridIndexTest extends AbstractTest<HybridIndexTest.TestContext> 
{
 
-    private ScheduledExecutorService executorService = 
MoreExecutors.getExitingScheduledExecutorService(
+    private static final ScheduledExecutorService executorService = 
MoreExecutors.getExitingScheduledExecutorService(
             (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(5));
+    private static final boolean metricStatsEnabled =
+            Boolean.parseBoolean(System.getProperty("metricStatsEnabled", 
"true"));
+    private static MetricStatisticsProvider metricStatsProvider;
+    public static final StatisticsProvider STATISTICS_PROVIDER = 
getStatsProvider(metricStatsEnabled);
+
+
     private final Random random = new Random(42); //fixed seed
     private String indexedPropName = "foo";
     private int nodesPerIteration = Integer.getInteger("nodesPerIteration", 
25);
@@ -94,7 +101,7 @@ public class HybridIndexTest extends Abs
     private int asyncInterval = Integer.getInteger("asyncInterval", 5);
     private int queueSize = Integer.getInteger("queueSize", 1000);
     private boolean hybridIndexEnabled = 
Boolean.getBoolean("hybridIndexEnabled");
-    private boolean metricStatsEnabled = 
Boolean.parseBoolean(System.getProperty("metricStatsEnabled", "true"));
+
     private boolean searcherEnabled = 
Boolean.parseBoolean(System.getProperty("searcherEnabled", "true"));
     private File indexCopierDir;
     private IndexCopier copier;
@@ -109,9 +116,10 @@ public class HybridIndexTest extends Abs
             "STOPPED", "ABORTED");
     private final File workDir;
     private Whiteboard whiteboard;
-    private MetricStatisticsProvider metricStatsProvider;
     private Searcher searcher;
+    private Mutator mutator;
     private final AtomicInteger indexedNodeCount = new AtomicInteger();
+    private List<TestContext> contexts = new ArrayList<>();
 
     public HybridIndexTest(File workDir) {
         this.workDir = workDir;
@@ -151,16 +159,22 @@ public class HybridIndexTest extends Abs
             runAsyncIndex();
         }
         defaultContext = new TestContext();
+        contexts.add(defaultContext);
         searcher = new Searcher();
+        mutator = new Mutator();
 
         if (searcherEnabled) {
             addBackgroundJob(searcher);
         }
+
+        addBackgroundJob(mutator);
     }
 
     @Override
     protected TestContext prepareThreadExecutionContext() throws 
RepositoryException {
-        return new TestContext();
+        TestContext ctx = new TestContext();
+        contexts.add(ctx);
+        return ctx;
     }
 
     @Override
@@ -195,16 +209,18 @@ public class HybridIndexTest extends Abs
             getAsyncIndexUpdate().close();
             queue.close();
             nrtIndexFactory.close();
-            dumpStats();
         }
 
+        dumpStats();
+
         if (indexCopierDir != null) {
             FileUtils.deleteDirectory(indexCopierDir);
         }
         System.out.printf("numOfIndexes: %d, refreshDeltaMillis: %d, 
asyncInterval: %d, queueSize: %d , " +
                         "hybridIndexEnabled: %s, metricStatsEnabled: %s %n", 
numOfIndexes, refreshDeltaMillis,
                 asyncInterval, queueSize, hybridIndexEnabled, 
metricStatsEnabled);
-        System.out.printf("Searcher: %d, indexedNodeCount: %d %n", 
searcher.resultSize, indexedNodeCount.get());
+        System.out.printf("Searcher: %d, Mutator: %d, indexedNodeCount: %d 
%n", searcher.resultSize, mutator
+                .mutationCount, indexedNodeCount.get());
     }
 
     private void dumpStats() {
@@ -216,7 +232,7 @@ public class HybridIndexTest extends Abs
                 .filter(new MetricFilter() {
                     @Override
                     public boolean matches(String name, Metric metric) {
-                        return name.startsWith("HYBRID");
+                        return name.startsWith("HYBRID") || 
name.startsWith("DOCUMENT_NS_MERGE");
                     }
                 })
                 .build()
@@ -232,6 +248,10 @@ public class HybridIndexTest extends Abs
         public TestContext() throws RepositoryException {
             dump = session.getRootNode()
                     .addNode(nextNodeName(), NT_OAK_UNSTRUCTURED)
+                    .addNode(nextNodeName(), NT_OAK_UNSTRUCTURED)
+                    .addNode(nextNodeName(), NT_OAK_UNSTRUCTURED)
+                    .addNode(nextNodeName(), NT_OAK_UNSTRUCTURED)
+                    .addNode(nextNodeName(), NT_OAK_UNSTRUCTURED)
                     .addNode(nextNodeName(), NT_OAK_UNSTRUCTURED);
             session.save();
             paths.add(dump.getPath());
@@ -268,11 +288,7 @@ public class HybridIndexTest extends Abs
                 null, //augmentorFactory
                 mip);
 
-        StatisticsProvider sp = StatisticsProvider.NOOP;
-        if (metricStatsEnabled) {
-            metricStatsProvider = new MetricStatisticsProvider(null, 
executorService);
-            sp = metricStatsProvider;
-        }
+        StatisticsProvider sp = STATISTICS_PROVIDER;
         queue = new DocumentQueue(queueSize, tracker, executorService, sp);
         localIndexObserver = new LocalIndexObserver(queue, sp);
     }
@@ -298,6 +314,16 @@ public class HybridIndexTest extends Abs
         return createdFolder;
     }
 
+    private static StatisticsProvider getStatsProvider(boolean 
metricStatsEnabled){
+        StatisticsProvider sp = StatisticsProvider.NOOP;
+        if (metricStatsEnabled) {
+            metricStatsProvider = new MetricStatisticsProvider(null, 
executorService);
+            sp = metricStatsProvider;
+        }
+        return sp;
+    }
+
+
     private class PropertyIndexInitializer implements RepositoryInitializer {
 
         @Override
@@ -363,4 +389,28 @@ public class HybridIndexTest extends Abs
             resultSize += Iterators.size(Iterators.limit(result.getNodes(), 
500));
         }
     }
+
+    private class Mutator implements Runnable {
+        final Session session = loginWriter();
+        int mutationCount = 0;
+        @Override
+        public void run() {
+            try{
+                run0();
+            } catch (RepositoryException e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        private void run0() throws RepositoryException {
+            TestContext ctx = contexts.get(random.nextInt(contexts.size()));
+            String path = ctx.paths.peek();
+            session.refresh(false);
+            if (path != null){
+                session.getNode(path).setProperty(indexedPropName, 
nextIndexedValue());
+                session.save();
+                mutationCount++;
+            }
+        }
+    }
 }


Reply via email to