knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject knox git commit: KNOX-604: Expose configuration of HttpClient's max connections per route setting
Date Wed, 28 Oct 2015 22:20:23 GMT
Repository: knox
Updated Branches:
  refs/heads/master 999831779 -> 8a0577249


KNOX-604: Expose configuration of HttpClient's max connections per route setting


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/8a057724
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/8a057724
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/8a057724

Branch: refs/heads/master
Commit: 8a057724991d1ba0c38d3619b9aada265faf8674
Parents: 9998317
Author: Kevin Minder <kevin.minder@hortonworks.com>
Authored: Wed Oct 28 18:15:11 2015 -0400
Committer: Kevin Minder <kevin.minder@hortonworks.com>
Committed: Wed Oct 28 18:15:11 2015 -0400

----------------------------------------------------------------------
 CHANGES                                         |  1 +
 .../gateway/config/impl/GatewayConfigImpl.java  | 10 ++++++++
 .../hadoop/gateway/config/GatewayConfig.java    |  3 +++
 .../dispatch/DefaultHttpClientFactory.java      | 27 ++++++++++++++++++++
 .../hadoop/gateway/GatewayTestConfig.java       |  6 +++++
 5 files changed, 47 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/8a057724/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index d6f0d99..8dfe06f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -8,6 +8,7 @@ Release Notes - Apache Knox - Version 0.7.0
     * [KNOX-549] - New Service-Test API can be added to topology. Accessible via Http call
or KnoxCLI
     * [KNOX-579] - Regex based identity assertion provider with static dictionary lookup
     * [KNOX-602] - JWT/SSO Cookie Based Federation Provider
+    * [KNOX-604] - Expose configuration of HttpClient's max connections per route setting
 
 ** Improvement
     * [KNOX-553] - Added topology validation from KnoxCLI to TopologyService deployment.

http://git-wip-us.apache.org/repos/asf/knox/blob/8a057724/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
index e62f438..a35586d 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
@@ -112,6 +112,7 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig
{
   private static final String KEYSTORE_TYPE = GATEWAY_CONFIG_FILE_PREFIX + ".keystore.type";
   private static final String XFORWARDED_ENABLED = GATEWAY_CONFIG_FILE_PREFIX + ".xforwarded.enabled";
   private static final String EPHEMERAL_DH_KEY_SIZE = GATEWAY_CONFIG_FILE_PREFIX + ".jdk.tls.ephemeralDHKeySize";
+  private static final String HTTP_CLIENT_MAX_CONNECTION = GATEWAY_CONFIG_FILE_PREFIX + ".httpclient.maxConnections";
 
   // These config property names are not inline with the convention of using the
   // GATEWAY_CONFIG_FILE_PREFIX as is done by those above. These are left for
@@ -445,4 +446,13 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig
{
   public String getEphemeralDHKeySize() {
     return get( EPHEMERAL_DH_KEY_SIZE, "2048");
   }
+
+  /* (non-Javadoc)
+   * @see org.apache.hadoop.gateway.config.GatewayConfig#getHttpClientMaxConnections()
+   */
+  @Override
+  public int getHttpClientMaxConnections() {
+    return getInt( HTTP_CLIENT_MAX_CONNECTION, 32 );
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/8a057724/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java
b/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java
index 6363ce4..5920526 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java
@@ -106,4 +106,7 @@ public interface GatewayConfig {
   boolean isXForwardedEnabled();
 
   String getEphemeralDHKeySize();
+
+  int getHttpClientMaxConnections();
+
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/8a057724/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/DefaultHttpClientFactory.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/DefaultHttpClientFactory.java
b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/DefaultHttpClientFactory.java
index 704e2b0..57de2e4 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/DefaultHttpClientFactory.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/DefaultHttpClientFactory.java
@@ -34,8 +34,10 @@ import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.config.Registry;
 import org.apache.http.config.RegistryBuilder;
 import org.apache.http.cookie.Cookie;
+import org.apache.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.http.impl.auth.SPNegoSchemeFactory;
 import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.protocol.HttpContext;
@@ -68,6 +70,13 @@ public class DefaultHttpClientFactory implements HttpClientFactory {
       builder = builder.setDefaultCookieStore(new NoCookieStore());
     }
 
+    builder.setKeepAliveStrategy( DefaultConnectionKeepAliveStrategy.INSTANCE );
+    builder.setConnectionReuseStrategy( DefaultConnectionReuseStrategy.INSTANCE );
+
+    int maxConnections = getMaxConnections( filterConfig );
+    builder.setMaxConnTotal( maxConnections );
+    builder.setMaxConnPerRoute( maxConnections );
+
     return builder
         .setRedirectStrategy(new NeverRedirectStrategy())
         .setRetryHandler(new NeverRetryHandler())
@@ -129,4 +138,22 @@ public class DefaultHttpClientFactory implements HttpClientFactory {
 
   }
 
+  private int getMaxConnections( FilterConfig filterConfig ) {
+    int maxConnections = 32;
+    GatewayConfig config =
+        (GatewayConfig)filterConfig.getServletContext().getAttribute( GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE
);
+    if( config != null ) {
+      maxConnections = config.getHttpClientMaxConnections();
+    }
+    String str = filterConfig.getInitParameter( "httpclient.maxConnections" );
+    if( str != null ) {
+      try {
+        maxConnections = Integer.parseInt( str );
+      } catch ( NumberFormatException e ) {
+        // Ignore it and use the default.
+      }
+    }
+    return maxConnections;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/8a057724/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
index 1da75b0..188b29c 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
@@ -258,4 +258,10 @@ public class GatewayTestConfig extends Configuration implements GatewayConfig
{
   public String getEphemeralDHKeySize() {
     return "2048";
   }
+
+  @Override
+  public int getHttpClientMaxConnections() {
+    return 8;
+  }
+
 }


Mime
View raw message