You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2020/08/20 13:37:01 UTC

[lucene-solr] branch reference_impl_dev updated: @579 Optimizations.

This is an automated email from the ASF dual-hosted git repository.

markrmiller pushed a commit to branch reference_impl_dev
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/reference_impl_dev by this push:
     new 7185aae  @579 Optimizations.
7185aae is described below

commit 7185aae32b899d66c71cdcede5111c3aa0884f48
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Thu Aug 20 08:36:43 2020 -0500

    @579 Optimizations.
---
 .../solr/uninverting/TestFieldCacheWithThreads.java | 18 +++++++++++-------
 .../java/org/apache/solr/common/TimeTracker.java    | 11 +++++++----
 .../src/java/org/apache/solr/util/TestHarness.java  | 21 +++++++++------------
 3 files changed, 27 insertions(+), 23 deletions(-)

diff --git a/solr/core/src/test/org/apache/solr/uninverting/TestFieldCacheWithThreads.java b/solr/core/src/test/org/apache/solr/uninverting/TestFieldCacheWithThreads.java
index e338573..77e694f 100644
--- a/solr/core/src/test/org/apache/solr/uninverting/TestFieldCacheWithThreads.java
+++ b/solr/core/src/test/org/apache/solr/uninverting/TestFieldCacheWithThreads.java
@@ -23,6 +23,7 @@ import java.util.List;
 import java.util.Random;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.lucene.analysis.MockAnalyzer;
@@ -51,10 +52,11 @@ public class TestFieldCacheWithThreads extends SolrTestCase {
     Directory dir = newDirectory();
     IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
 
-    final List<Long> numbers = new ArrayList<>();
-    final List<BytesRef> binary = new ArrayList<>();
-    final List<BytesRef> sorted = new ArrayList<>();
     final int numDocs = TEST_NIGHTLY ? atLeast(100) : 20;
+    final List<Long> numbers = new ArrayList<>(numDocs);
+    final List<BytesRef> binary = new ArrayList<>(numDocs);
+    final List<BytesRef> sorted = new ArrayList<>(numDocs);
+
     for(int i=0;i<numDocs;i++) {
       Document d = new Document();
       long number = random().nextLong();
@@ -86,7 +88,7 @@ public class TestFieldCacheWithThreads extends SolrTestCase {
           public void run() {
             try {
               startingGun.await();
-              int iters = atLeast(1000);
+              int iters = atLeast(TEST_NIGHTLY ? 1000 : 100);
               for(int iter=0;iter<iters;iter++) {
                 int docID = threadRandom.nextInt(numDocs);
                 switch(threadRandom.nextInt(4)) {
@@ -201,6 +203,7 @@ public class TestFieldCacheWithThreads extends SolrTestCase {
     final long END_TIME = System.nanoTime() + TimeUnit.NANOSECONDS.convert((TEST_NIGHTLY ? 30 : 1), TimeUnit.SECONDS);
 
     final int NUM_THREADS = TEST_NIGHTLY ? TestUtil.nextInt(random(), 1, 10) : 2;
+    List<Future>  futures = new ArrayList<>(NUM_THREADS);
     Thread[] threads = new Thread[NUM_THREADS];
     for(int thread=0;thread<NUM_THREADS;thread++) {
       threads[thread] = new Thread() {
@@ -243,11 +246,12 @@ public class TestFieldCacheWithThreads extends SolrTestCase {
             }
           }
         };
-      threads[thread].start();
+      futures.add(testExecutor.submit(threads[thread]));
+
     }
 
-    for(Thread thread : threads) {
-      thread.join();
+    for(Future future : futures) {
+      future.get();
     }
 
     r.close();
diff --git a/solr/solrj/src/java/org/apache/solr/common/TimeTracker.java b/solr/solrj/src/java/org/apache/solr/common/TimeTracker.java
index a7054ef..b44f802 100644
--- a/solr/solrj/src/java/org/apache/solr/common/TimeTracker.java
+++ b/solr/solrj/src/java/org/apache/solr/common/TimeTracker.java
@@ -32,7 +32,7 @@ public class TimeTracker {
   
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
   
-  public static final Map<String,TimeTracker> CLOSE_TIMES = new ConcurrentHashMap<>(2048, 0.75f, 6);
+  public static final Map<String,TimeTracker> CLOSE_TIMES = new ConcurrentHashMap<>(256, 0.75f, 3);
   
   private final long startTime;
   private final PrintStream out;
@@ -42,7 +42,7 @@ public class TimeTracker {
   
   private final List<TimeTracker> children = Collections.synchronizedList(new ArrayList<>(64));
 
-  private final StringBuilder label = new StringBuilder(2046);
+  private final StringBuilder label;
   
   private final int depth;
   
@@ -60,8 +60,11 @@ public class TimeTracker {
     }
 
     this.startTime = System.nanoTime();
-    this.label.append(label);
     this.depth = i;
+    this.label = new StringBuilder(label.length() + depth + 6);
+
+    this.label.append(label);
+
     this.out = out;
     if (depth <= 1) {
       CLOSE_TIMES.put(
@@ -176,7 +179,7 @@ public class TimeTracker {
       return "";
     }
 
-    StringBuilder sb = new StringBuilder(1024);
+    StringBuilder sb = new StringBuilder(64);
 //    if (trackedObject != null) {
 //      if (trackedObject instanceof String) {
 //        sb.append(label + trackedObject.toString() + " " + getElapsedMS() + "ms");
diff --git a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
index e50e33c..008f62d 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
@@ -16,15 +16,6 @@
  */
 package org.apache.solr.util;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Path;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 import com.google.common.collect.ImmutableList;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.client.solrj.impl.HttpClientUtil;
@@ -38,15 +29,12 @@ import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.CoreDescriptor;
 import org.apache.solr.core.CorePropertiesLocator;
 import org.apache.solr.core.CoresLocator;
-import org.apache.solr.core.MetricsConfig;
 import org.apache.solr.core.NodeConfig;
-import org.apache.solr.core.PluginInfo;
 import org.apache.solr.core.SolrConfig;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.core.SolrPaths;
 import org.apache.solr.core.SolrXmlConfig;
 import org.apache.solr.handler.UpdateRequestHandler;
-import org.apache.solr.metrics.reporters.SolrJmxReporter;
 import org.apache.solr.request.LocalSolrQueryRequest;
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.request.SolrRequestHandler;
@@ -59,6 +47,15 @@ import org.apache.solr.schema.IndexSchemaFactory;
 import org.apache.solr.servlet.DirectSolrConnection;
 import org.apache.solr.update.UpdateShardHandlerConfig;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 /**
  * This class provides a simple harness that may be useful when
  * writing testcases.