You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ho...@apache.org on 2022/06/27 18:16:53 UTC

[solr] branch main updated: SOLR-16266: Eliminate unneccessary byte[] copy in Http2SolrClient

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

hossman pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 13b1fd20db9 SOLR-16266: Eliminate unneccessary byte[] copy in Http2SolrClient
13b1fd20db9 is described below

commit 13b1fd20db9f1eb9d264aed6382771ec17cb80db
Author: Chris Hostetter <ho...@apache.org>
AuthorDate: Mon Jun 27 11:14:31 2022 -0700

    SOLR-16266: Eliminate unneccessary byte[] copy in Http2SolrClient
---
 solr/CHANGES.txt                                              |  2 ++
 .../org/apache/solr/client/solrj/impl/Http2SolrClient.java    | 11 +++++++----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 5b7d350911c..6f9964f5e63 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -59,6 +59,8 @@ Optimizations
 
 * SOLR-16146: Avoid loading all collections during node startup (noble)
 
+* SOLR-16266: Eliminate unneccessary byte[] copy in Http2SolrClient (hossman)
+
 Bug Fixes
 ---------------------
 * SOLR-15918: Skip repetitive parent znode creation on config set upload (Mike Drob)
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
index a10d578a6a3..170bfcf5c3e 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
@@ -29,6 +29,7 @@ import java.lang.reflect.InvocationTargetException;
 import java.net.ConnectException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
@@ -77,7 +78,7 @@ import org.eclipse.jetty.client.ProtocolHandlers;
 import org.eclipse.jetty.client.api.Request;
 import org.eclipse.jetty.client.api.Response;
 import org.eclipse.jetty.client.http.HttpClientTransportOverHTTP;
-import org.eclipse.jetty.client.util.BytesContentProvider;
+import org.eclipse.jetty.client.util.ByteBufferContentProvider;
 import org.eclipse.jetty.client.util.FormContentProvider;
 import org.eclipse.jetty.client.util.InputStreamContentProvider;
 import org.eclipse.jetty.client.util.InputStreamResponseListener;
@@ -616,12 +617,14 @@ public class Http2SolrClient extends SolrClient {
 
       if (contentWriter != null) {
         Request req = httpClient.newRequest(url + wparams.toQueryString()).method(method);
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        BinaryRequestWriter.BAOS baos = new BinaryRequestWriter.BAOS();
         contentWriter.write(baos);
 
-        // TODO reduce memory usage
+        // SOLR-16265: TODO reduce memory usage
         return req.content(
-            new BytesContentProvider(contentWriter.getContentType(), baos.toByteArray()));
+            // We're throwing this BAOS away, so no need to copy the byte[], just use the raw buf
+            new ByteBufferContentProvider(
+                contentWriter.getContentType(), ByteBuffer.wrap(baos.getbuf(), 0, baos.size())));
       } else if (streams == null || isMultipart) {
         // send server list and request list as query string params
         ModifiableSolrParams queryParams = calculateQueryParams(this.queryParams, wparams);