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


##########
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:
   I prefer the second approach in case the default changes in the 
`HttpClient`. By reading the `HttpClient` code, if not explicitly specified, 
these 2 values are 0, and then the underlying default is used



-- 
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-unsubscr...@pinot.apache.org

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


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

Reply via email to