You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "Jackie-Jiang (via GitHub)" <gi...@apache.org> on 2023/03/29 22:40:02 UTC

[GitHub] [pinot] Jackie-Jiang commented on a diff in pull request #10487: Fix Bottleneck for Server Bootstrap by Making maxConnsPerRoute Configurable

Jackie-Jiang commented on code in PR #10487:
URL: https://github.com/apache/pinot/pull/10487#discussion_r1152553543


##########
pinot-common/src/main/java/org/apache/pinot/common/utils/http/HttpClient.java:
##########
@@ -86,22 +86,24 @@ public class HttpClient implements AutoCloseable {
   private final CloseableHttpClient _httpClient;
 
   public HttpClient() {
-    this(null);
+    this(HttpClientConfig.DEFAULT_HTTP_CLIENT_CONFIG, null);
   }
 
-  public HttpClient(@Nullable SSLContext sslContext) {
+  public HttpClient(HttpClientConfig httpClientConfig, @Nullable SSLContext sslContext) {
     SSLContext context = sslContext != null ? sslContext : TlsUtils.getSslContext();
     // Set NoopHostnameVerifier to skip validating hostname when uploading/downloading segments.
     SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(context, NoopHostnameVerifier.INSTANCE);
-    _httpClient = HttpClients.custom().setSSLSocketFactory(csf).build();
+    _httpClient = HttpClients.custom().setMaxConnTotal(httpClientConfig.getMaxConns())

Review Comment:
   To keep the existing behavior, we can set maxConns or maxConnsPerRoute only when the value from the config > 0, and make 0 the default value if config does not exist



##########
pinot-common/src/main/java/org/apache/pinot/common/utils/http/HttpClientConfig.java:
##########
@@ -0,0 +1,92 @@
+/**
+ * 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.pinot.common.utils.http;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.spi.env.PinotConfiguration;
+
+
+public class HttpClientConfig {
+  // Default config uses default values which are same as what Apache Commons Http-Client uses.
+  public static final HttpClientConfig DEFAULT_HTTP_CLIENT_CONFIG = HttpClientConfig.newBuilder().build();
+
+  protected static final String MAX_CONNS_CONFIG_NAME = "http.client.max_conns";
+  protected static final String MAX_CONNS_PER_ROUTE_CONFIG_NAME = "http.client.max_conns_per_route";

Review Comment:
   We use camel case for config keys. Also should we consider using the same name as the internal key for HttpClient (`maxConnTotal` and `maxConnPerRoute`)?



##########
pinot-common/src/main/java/org/apache/pinot/common/utils/http/HttpClientConfig.java:
##########
@@ -0,0 +1,92 @@
+/**
+ * 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.pinot.common.utils.http;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.spi.env.PinotConfiguration;
+
+
+public class HttpClientConfig {
+  // Default config uses default values which are same as what Apache Commons Http-Client uses.
+  public static final HttpClientConfig DEFAULT_HTTP_CLIENT_CONFIG = HttpClientConfig.newBuilder().build();
+
+  protected static final String MAX_CONNS_CONFIG_NAME = "http.client.max_conns";
+  protected static final String MAX_CONNS_PER_ROUTE_CONFIG_NAME = "http.client.max_conns_per_route";
+
+  private final int _maxConns;
+  private final int _maxConnsPerRoute;
+
+  private HttpClientConfig(int maxConns, int maxConnsPerRoute) {
+    _maxConns = maxConns;
+    _maxConnsPerRoute = maxConnsPerRoute;
+  }
+
+  public int getMaxConns() {
+    return _maxConns;
+  }
+
+  public int getMaxConnsPerRoute() {
+    return _maxConnsPerRoute;
+  }
+
+  /**
+   * Creates a {@link HttpClientConfig.Builder} and initializes it with relevant configs from the provided
+   * configuration. Since http-clients are used in a bunch of places in the code, each use-case can have their own
+   * prefix for their config. The caller should call {@link PinotConfiguration#subset(String)} to remove their prefix
+   * and this builder will look for exact matches of its relevant configs.
+   */
+  public static Builder newBuilder(PinotConfiguration pinotConfiguration) {
+    Builder builder = new Builder();
+    String maxConns = pinotConfiguration.getProperty(MAX_CONNS_CONFIG_NAME);
+    if (StringUtils.isNotEmpty(maxConns)) {
+      builder.withMaxConns(Integer.parseInt(maxConns));
+    }
+    String maxConnsPerRoute = pinotConfiguration.getProperty(MAX_CONNS_PER_ROUTE_CONFIG_NAME);
+    if (StringUtils.isNotEmpty(maxConnsPerRoute)) {
+      builder.withMaxConnsPerRoute(Integer.parseInt(maxConnsPerRoute));
+    }
+    return builder;
+  }
+
+  private static Builder newBuilder() {
+    return new Builder();
+  }
+
+  public static class Builder {
+    private int _maxConns = 20;
+    private int _maxConnsPerRoute = 2;

Review Comment:
   Where are these 2 default values come from? We should try to avoid magic number



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org