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 15:30:10 UTC

[lucene-solr] 04/06: @578 Optimizations.

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

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

commit 9c7ed58c5196e010c4b94730245a72ae869e6897
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Thu Aug 20 08:11:46 2020 -0500

    @578 Optimizations.
---
 .../client/solrj/embedded/JettySolrRunner.java     |  2 +-
 .../java/org/apache/solr/cloud/ZkController.java   |  2 +-
 .../apache/solr/cloud/overseer/ZkStateWriter.java  |  6 +++-
 .../java/org/apache/solr/core/CoreContainer.java   |  9 ++---
 .../java/org/apache/solr/core/XmlConfigFile.java   | 11 +++---
 .../org/apache/solr/metrics/SolrMetricManager.java | 25 +++++++++----
 .../apache/solr/metrics/SolrMetricsContext.java    |  8 +++--
 .../apache/solr/response/TextResponseWriter.java   |  4 +--
 .../cloud/TestWaitForStateWithJettyShutdowns.java  |  6 ----
 .../src/java/org/apache/solr/common/ParWork.java   |  4 +--
 .../org/apache/solr/common/util/FastWriter.java    |  5 +--
 .../apache/solr/common/util/SolrJSONWriter.java    |  4 +--
 .../solr/common/util/SolrQueuedThreadPool.java     | 41 ++++++++++------------
 .../src/java/org/apache/solr/SolrTestCase.java     | 11 +++---
 .../java/org/apache/solr/util/BaseTestHarness.java | 35 +++++++++---------
 .../src/java/org/apache/solr/util/TestHarness.java |  4 +--
 16 files changed, 97 insertions(+), 80 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java b/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
index 426d0c1..da5cc7b 100644
--- a/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
+++ b/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
@@ -301,7 +301,7 @@ public class JettySolrRunner implements Closeable {
       qtp.setLowThreadsThreshold(Integer.getInteger("solr.lowContainerThreadsThreshold", -1)); // we don't use this or connections will get cut
       qtp.setMinThreads(Integer.getInteger("solr.minContainerThreads", 2));
       qtp.setIdleTimeout(Integer.getInteger("solr.containerThreadsIdle", THREAD_POOL_MAX_IDLE_TIME_MS));
-      qtp.setStopTimeout(1);
+      qtp.setStopTimeout(0);
       qtp.setReservedThreads(-1); // -1 auto sizes, important to keep
     }
 
diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
index 3d25de4..be84376 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
@@ -856,7 +856,7 @@ public class ZkController implements Closeable {
 //
     paths.put(ZkStateReader.CLUSTER_STATE, emptyJson);
     //   operations.add(zkClient.createPathOp(ZkStateReader.CLUSTER_PROPS, emptyJson));
-    paths.put(ZkStateReader.SOLR_PKGS_PATH, emptyJson);
+    paths.put(ZkStateReader.SOLR_PKGS_PATH, null);
     paths.put(ZkStateReader.ROLES, emptyJson);
 
 
diff --git a/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java b/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java
index 6ca23f1..ac60169 100644
--- a/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java
+++ b/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java
@@ -419,7 +419,11 @@ public class ZkStateWriter {
 
       updatesToWrite.clear();
       if (log.isDebugEnabled()) log.debug("Failed updates {}", failedUpdates.values());
-      updatesToWrite.putAll(failedUpdates);
+   //   updatesToWrite.putAll(failedUpdates);
+      if (failedUpdates.size() > 0) {
+        throw new AlreadyClosedException();
+      }
+
       success = true;
     } finally {
       timerContext.stop();
diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
index eaac591..f8660c7 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
@@ -788,7 +788,6 @@ public class CoreContainer implements Closeable {
         infoHandler = createHandler(INFO_HANDLER_PATH, cfg.getInfoHandlerClass(), InfoHandler.class);
       });
 
-
       work.collect("",() -> {
         // metricsHistoryHandler uses metricsHandler, so create it first
         metricsHandler = new MetricsHandler(this);
@@ -824,10 +823,12 @@ public class CoreContainer implements Closeable {
         });
       }
 
-      work.addCollect();
+    //  work.addCollect();
+      work.collect("",() -> {
+        coreAdminHandler = createHandler(CORES_HANDLER_PATH, cfg.getCoreAdminHandlerClass(), CoreAdminHandler.class);
+        configSetsHandler = createHandler(CONFIGSETS_HANDLER_PATH, cfg.getConfigSetsHandlerClass(), ConfigSetsHandler.class);
+      });
 
-      coreAdminHandler = createHandler(CORES_HANDLER_PATH, cfg.getCoreAdminHandlerClass(), CoreAdminHandler.class);
-      configSetsHandler = createHandler(CONFIGSETS_HANDLER_PATH, cfg.getConfigSetsHandlerClass(), ConfigSetsHandler.class);
     }
 
       // initialize gauges for reporting the number of cores and disk total/free
diff --git a/solr/core/src/java/org/apache/solr/core/XmlConfigFile.java b/solr/core/src/java/org/apache/solr/core/XmlConfigFile.java
index b311291..acbaf22 100644
--- a/solr/core/src/java/org/apache/solr/core/XmlConfigFile.java
+++ b/solr/core/src/java/org/apache/solr/core/XmlConfigFile.java
@@ -79,6 +79,7 @@ public class XmlConfigFile { // formerly simply "Config"
 
       xpathFactory.getConfiguration().setValidation(false);
       xpathFactory.getConfiguration().setExpandAttributeDefaults(false);
+      xpathFactory.getConfiguration().setXIncludeAware(true);
 
     // tfactory.getConfiguration().setBooleanProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE);
   }
@@ -161,14 +162,14 @@ public class XmlConfigFile { // formerly simply "Config"
 
     try {
       DocumentBuilderImpl b = new DocumentBuilderImpl();
-
+      b.setErrorHandler(xmllog);
       if (is.getSystemId() != null) {
         b.setEntityResolver(loader.getSysIdResolver());
-        b.setXIncludeAware(true);
-        b.setValidating(false);
-        b.setErrorHandler(xmllog);
-        b.getConfiguration().setExpandAttributeDefaults(true);
       }
+      b.setXIncludeAware(true);
+      b.setValidating(false);
+      b.getConfiguration().setExpandAttributeDefaults(false);
+
       try {
         doc = copyDoc(b.parse(is));
       } catch (TransformerException e) {
diff --git a/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java b/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java
index ae7bbe9..231f472 100644
--- a/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java
+++ b/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java
@@ -716,21 +716,26 @@ public class SolrMetricManager {
    *                   using dotted notation
    * @param metricPath (optional) additional top-most metric name path elements
    */
-  public void registerMetric(SolrMetricsContext context, String registry, Metric metric, boolean force, String metricName, String... metricPath) {
+  public String registerMetric(SolrMetricsContext context, String registry, Metric metric, boolean force, String metricName, String... metricPath) {
     MetricRegistry metricRegistry = registry(registry);
     String fullName = mkName(metricName, metricPath);
     if (context != null) {
       context.registerMetricName(fullName);
     }
 
-    metricRegistry.remove(fullName);
     try {
       metricRegistry.register(fullName, metric);
     } catch (IllegalArgumentException e) {
-      if (!force) {
-        throw e;
+      metricRegistry.remove(fullName);
+      try {
+        metricRegistry.register(fullName, metric);
+      } catch (IllegalArgumentException e2) {
+        if (!force) {
+          throw e2;
+        }
       }
     }
+    return fullName;
   }
 
   /**
@@ -763,8 +768,8 @@ public class SolrMetricManager {
     }
   }
 
-  public void registerGauge(SolrMetricsContext context, String registry, Gauge<?> gauge, String tag, boolean force, String metricName, String... metricPath) {
-    registerMetric(context, registry, new GaugeWrapper(gauge, tag), force, metricName, metricPath);
+  public String registerGauge(SolrMetricsContext context, String registry, Gauge<?> gauge, String tag, boolean force, String metricName, String... metricPath) {
+    return registerMetric(context, registry, new GaugeWrapper(gauge, tag), force, metricName, metricPath);
   }
 
   public int unregisterGauges(String registryName, String tagSegment) {
@@ -789,6 +794,14 @@ public class SolrMetricManager {
     return removed.get();
   }
 
+  public int unregisterGauges(Set<String> names, String registryName) {
+    MetricRegistry registry = registry(registryName);
+    for (String name : names) {
+      registry.remove(name);
+    }
+    return names.size();
+  }
+
   /**
    * This method creates a hierarchical name with arbitrary levels of hierarchy
    *
diff --git a/solr/core/src/java/org/apache/solr/metrics/SolrMetricsContext.java b/solr/core/src/java/org/apache/solr/metrics/SolrMetricsContext.java
index 6297014..a927d68 100644
--- a/solr/core/src/java/org/apache/solr/metrics/SolrMetricsContext.java
+++ b/solr/core/src/java/org/apache/solr/metrics/SolrMetricsContext.java
@@ -41,6 +41,8 @@ public class SolrMetricsContext {
   final String tag;
   private final Set<String> metricNames = ConcurrentHashMap.newKeySet(128);
 
+  private final Set<String> gaugeNames = ConcurrentHashMap.newKeySet(128);
+
   public SolrMetricsContext(SolrMetricManager metricManager, String registryName, String tag) {
     this.registryName = registryName;
     this.metricManager = metricManager;
@@ -83,7 +85,9 @@ public class SolrMetricsContext {
    * do so may result in hard-to-debug memory leaks.</b></p>
    */
   public void unregister() {
-    metricManager.unregisterGauges(registryName, tag);
+    for (String gauge : gaugeNames) {
+      metricManager.unregisterGauges(registryName, tag);
+    }
   }
 
   /**
@@ -132,7 +136,7 @@ public class SolrMetricsContext {
    * Convenience method for {@link SolrMetricManager#registerGauge(SolrMetricsContext, String, Gauge, String, boolean, String, String...)}.
    */
   public void gauge(Gauge<?> gauge, boolean force, String metricName, String... metricPath) {
-    metricManager.registerGauge(this, registryName, gauge, tag, force, metricName, metricPath);
+    gaugeNames.add(metricManager.registerGauge(this, registryName, gauge, tag, force, metricName, metricPath));
   }
 
   /**
diff --git a/solr/core/src/java/org/apache/solr/response/TextResponseWriter.java b/solr/core/src/java/org/apache/solr/response/TextResponseWriter.java
index 803c340..64b796c 100644
--- a/solr/core/src/java/org/apache/solr/response/TextResponseWriter.java
+++ b/solr/core/src/java/org/apache/solr/response/TextResponseWriter.java
@@ -42,7 +42,7 @@ import org.apache.solr.search.ReturnFields;
  */
 public abstract class TextResponseWriter implements TextWriter {
 
-  protected final FastWriter writer;
+  protected final Writer writer;
   protected final IndexSchema schema;
   protected final SolrQueryRequest req;
   protected final SolrQueryResponse rsp;
@@ -80,7 +80,7 @@ public abstract class TextResponseWriter implements TextWriter {
 
   /** done with this ResponseWriter... make sure any buffers are flushed to writer */
   public void close() throws IOException {
-    if(writer != null) writer.flushBuffer();
+    if(writer != null && writer instanceof FastWriter) ((FastWriter) writer).flushBuffer();
   }
 
   @Override
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestWaitForStateWithJettyShutdowns.java b/solr/core/src/test/org/apache/solr/cloud/TestWaitForStateWithJettyShutdowns.java
index 677cf0b..f4afb8a 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestWaitForStateWithJettyShutdowns.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestWaitForStateWithJettyShutdowns.java
@@ -77,10 +77,6 @@ public class TestWaitForStateWithJettyShutdowns extends SolrTestCaseJ4 {
     try {
       log.info("Create our collection");
       CollectionAdminRequest.createCollection(col_name, "_default", 1, 1).process(cluster.getSolrClient());
-      
-      log.info("Sanity check that our collection has come online");
-      cluster.getSolrClient().waitForState(col_name, 30, TimeUnit.SECONDS,
-                                           SolrCloudTestCase.clusterShape(1, 1));
 
 
       // HACK implementation detail...
@@ -114,8 +110,6 @@ public class TestWaitForStateWithJettyShutdowns extends SolrTestCaseJ4 {
       log.info("Shutdown 1 node");
       final JettySolrRunner nodeToStop = cluster.getJettySolrRunner(0);
       nodeToStop.stop();
-      log.info("Wait to confirm our node is fully shutdown");
-      cluster.waitForJettyToStop(nodeToStop);
 
       // now that we're confident that node has stoped, check if a waitForState
       // call will detect the missing replica -- shouldn't need long wait times...
diff --git a/solr/solrj/src/java/org/apache/solr/common/ParWork.java b/solr/solrj/src/java/org/apache/solr/common/ParWork.java
index b748fb3..ad37262 100644
--- a/solr/solrj/src/java/org/apache/solr/common/ParWork.java
+++ b/solr/solrj/src/java/org/apache/solr/common/ParWork.java
@@ -69,7 +69,7 @@ public class ParWork implements Closeable {
   private final boolean requireAnotherThread;
   private final String rootLabel;
 
-  private volatile Set<ParObject> collectSet = ConcurrentHashMap.newKeySet(32);
+  private volatile Set<ParObject> collectSet = ConcurrentHashMap.newKeySet(16);
 
   private static volatile ThreadPoolExecutor EXEC;
 
@@ -278,7 +278,7 @@ public class ParWork implements Closeable {
     }
     ParObject ob = new ParObject();
     ob.object = object;
-    ob.label = object.getClass().getSimpleName();
+    ob.label = object.toString();
     collectSet.add(ob);
   }
 
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/FastWriter.java b/solr/solrj/src/java/org/apache/solr/common/util/FastWriter.java
index 2575624..fff6bc3 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/FastWriter.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/FastWriter.java
@@ -17,6 +17,7 @@
 package org.apache.solr.common.util;
 
 import java.io.IOException;
+import java.io.StringWriter;
 import java.io.Writer;
 
 /** Single threaded BufferedWriter
@@ -40,8 +41,8 @@ public class FastWriter extends Writer {
     this.pos = start;
   }
 
-  public static FastWriter wrap(Writer sink) {
-    return (sink instanceof FastWriter) ? (FastWriter)sink : new FastWriter(sink);
+  public static Writer wrap(Writer sink) {
+    return (sink instanceof FastWriter || sink instanceof StringWriter) ? sink : new FastWriter(sink);
   }
 
   @Override
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/SolrJSONWriter.java b/solr/solrj/src/java/org/apache/solr/common/util/SolrJSONWriter.java
index 5eeefd4..c7ab114 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/SolrJSONWriter.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/SolrJSONWriter.java
@@ -35,7 +35,7 @@ public class SolrJSONWriter implements JsonTextWriter {
   }
 
   final protected String namedListStyle;
-  final FastWriter writer;
+  final Writer writer;
   protected int level;
   protected boolean doIndent;
 
@@ -57,7 +57,7 @@ public class SolrJSONWriter implements JsonTextWriter {
    * done with all writing
    */
   public void close() throws IOException {
-    if (writer != null) writer.flushBuffer();
+    if (writer != null && writer instanceof FastWriter) ((FastWriter) writer).flushBuffer();
   }
 
 
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/SolrQueuedThreadPool.java b/solr/solrj/src/java/org/apache/solr/common/util/SolrQueuedThreadPool.java
index ae452d4..446fef5 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/SolrQueuedThreadPool.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/SolrQueuedThreadPool.java
@@ -16,21 +16,6 @@
  */
 package org.apache.solr.common.util;
 
-import java.io.Closeable;
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.RejectedExecutionException;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
-
 import org.apache.solr.common.ParWork;
 import org.eclipse.jetty.util.AtomicBiInteger;
 import org.eclipse.jetty.util.BlockingArrayQueue;
@@ -41,8 +26,6 @@ import org.eclipse.jetty.util.annotation.Name;
 import org.eclipse.jetty.util.component.ContainerLifeCycle;
 import org.eclipse.jetty.util.component.Dumpable;
 import org.eclipse.jetty.util.component.DumpableCollection;
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.thread.QueuedThreadPool;
 import org.eclipse.jetty.util.thread.ReservedThreadExecutor;
 import org.eclipse.jetty.util.thread.ThreadPool;
 import org.eclipse.jetty.util.thread.ThreadPoolBudget;
@@ -50,8 +33,23 @@ import org.eclipse.jetty.util.thread.TryExecutor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.Closeable;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
+
 public class SolrQueuedThreadPool extends ContainerLifeCycle implements ThreadFactory, ThreadPool.SizedThreadPool, Dumpable, TryExecutor, Closeable {
-    private static final org.eclipse.jetty.util.log.Logger LOG = Log.getLogger(QueuedThreadPool.class);
+    private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
     private static Runnable NOOP = () ->
     {
     };
@@ -206,7 +204,7 @@ public class SolrQueuedThreadPool extends ContainerLifeCycle implements ThreadFa
         if (LOG.isDebugEnabled())
             LOG.debug("Stopping {}", this);
         this.closed = true;
-
+        this.setStopTimeout(0);
         super.doStop();
 
         removeBean(_tryExecutor);
@@ -276,7 +274,7 @@ public class SolrQueuedThreadPool extends ContainerLifeCycle implements ThreadFa
                 }
                 catch (Throwable t)
                 {
-                    LOG.warn(t);
+                    LOG.warn("", t);
                 }
             }
             else if (job != NOOP)
@@ -1007,11 +1005,10 @@ public class SolrQueuedThreadPool extends ContainerLifeCycle implements ThreadFa
                     {
                         if (LOG.isDebugEnabled())
                             LOG.debug("interrupted {} in {}", job, SolrQueuedThreadPool.this);
-                        LOG.ignore(e);
                     }
                     catch (Throwable e)
                     {
-                        LOG.warn(e);
+                        LOG.warn("", e);
                     }
                     finally
                     {
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java
index 2a4ae0f..5565bce 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java
@@ -202,6 +202,11 @@ public class SolrTestCase extends LuceneTestCase {
     log.info("*******************************************************************");
     log.info("@BeforeClass ------------------------------------------------------");
 
+    System.setProperty("org.eclipse.jetty.util.log.class", "org.apache.logging.log4j.appserver.jetty.Log4j2Logger");
+
+    // we do this because threads can be finished, but waiting
+    // for an idle timeout or in a TERMINATED state, and we don't
+    // want to wait for them - in prod these threads are daemon
     interruptThreadsOnTearDown("ParWork", false);
 
     if (!SysStats.getSysStats().isAlive()) {
@@ -616,10 +621,6 @@ public class SolrTestCase extends LuceneTestCase {
         System.out.println("state:" + thread.getState());
       }
     }
-
-//    if (nameContains != null && nameContains.startsWith("ParWork")) {
-//      ParWork.closeExecutor();
-//    }
   }
 
   public static SolrQueuedThreadPool getQtp() {
@@ -634,7 +635,7 @@ public class SolrTestCase extends LuceneTestCase {
     qtp.setStopTimeout((int) TimeUnit.SECONDS.toMillis(60));
     qtp.setDaemon(true);
     qtp.setReservedThreads(-1); // -1 auto sizes, important to keep
-    qtp.setStopTimeout(1);
+    qtp.setStopTimeout(0);
     return qtp;
   }
 
diff --git a/solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java
index 1ffb0c5..c8a4631 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java
@@ -16,8 +16,10 @@
  */
 package org.apache.solr.util;
 
+import net.sf.saxon.dom.DocumentBuilderImpl;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.util.XML;
+import org.apache.solr.core.SolrXmlConfig;
 import org.apache.solr.core.XmlConfigFile;
 import org.apache.solr.rest.schema.FieldTypeXmlAdapter;
 import org.apache.solr.schema.IndexSchema;
@@ -27,6 +29,7 @@ import org.xml.sax.SAXException;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
 import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpressionException;
@@ -73,16 +76,16 @@ abstract public class BaseTestHarness {
 
     if (tests==null || tests.length == 0) return null;
 
-    Document document = null;
+    DocumentBuilderImpl b = new DocumentBuilderImpl();
+    b.setConfiguration(XmlConfigFile.xpathFactory.getConfiguration());
+
+    Document document;
     try {
-      document = getXmlDocumentBuilder().parse(new ByteArrayInputStream
+      document = b.parse(new ByteArrayInputStream
           (xml.getBytes(StandardCharsets.UTF_8)));
-    } catch (UnsupportedEncodingException e1) {
-      throw new RuntimeException("Totally weird UTF-8 exception", e1);
-    } catch (IOException | ParserConfigurationException e2) {
-      throw new RuntimeException("Parse or IO Exception", e2);
+    } catch (IOException e) {
+     throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
     }
-
     for (String xp : tests) {
       xp=xp.trim();
       Boolean bool = (Boolean) getXpath().evaluate(xp, document, XPathConstants.BOOLEAN);
@@ -98,16 +101,14 @@ abstract public class BaseTestHarness {
     throws XPathExpressionException, SAXException {
     if (null == xpath) return null;
 
-    Document document = null;
+    DocumentBuilderImpl b = new DocumentBuilderImpl();
+    b.setConfiguration(XmlConfigFile.xpathFactory.getConfiguration());
+    Document document;
     try {
-      document = getXmlDocumentBuilder().parse(new ByteArrayInputStream
+      document = b.parse(new ByteArrayInputStream
           (xml.getBytes(StandardCharsets.UTF_8)));
-    } catch (UnsupportedEncodingException e1) {
-      throw new RuntimeException("Totally weird UTF-8 exception", e1);
-    } catch (IOException e2) {
-      throw new RuntimeException("Totally weird io exception", e2);
-    } catch (ParserConfigurationException e) {
-      throw new RuntimeException("Parse exception", e);
+    } catch (IOException e) {
+      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
     }
 
     xpath = xpath.trim();
@@ -123,7 +124,7 @@ abstract public class BaseTestHarness {
   public static String makeSimpleDoc(String... fieldsAndValues) {
 
     try {
-      StringWriter w = new StringWriter();
+      StringWriter w = new StringWriter(32);
       w.append("<doc>");
       for (int i = 0; i < fieldsAndValues.length; i+=2) {
         XML.writeXML(w, "field", fieldsAndValues[i + 1], "name",
@@ -144,7 +145,7 @@ abstract public class BaseTestHarness {
    */
   public static String deleteByQuery(String q, String... args) {
     try {
-      StringWriter r = new StringWriter();
+      StringWriter r = new StringWriter(64);
       XML.writeXML(r, "query", q);
       return delete(r.getBuffer().toString(), args);
     } catch(IOException e) {
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 1db9cd2..e50e33c 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
@@ -338,12 +338,12 @@ public class TestHarness extends BaseTestHarness {
       }
       QueryResponseWriter responseWriter = core.getQueryResponseWriter(req);
       if (responseWriter instanceof BinaryQueryResponseWriter) {
-        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(32000);
+        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(256);
         BinaryQueryResponseWriter writer = (BinaryQueryResponseWriter) responseWriter;
         writer.write(byteArrayOutputStream, req, rsp);
         return new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8);
       } else {
-        StringWriter sw = new StringWriter(32000);
+        StringWriter sw = new StringWriter(256);
         responseWriter.write(sw,req,rsp);
         return sw.toString();
       }