KYLIN-2862 use PoolingClientConnectionManager instead of BasicClientConnManager
Signed-off-by: Li Yang <liy...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/241a4ae0 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/241a4ae0 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/241a4ae0 Branch: refs/heads/ranger Commit: 241a4ae08f097cc2e78573f58cf792e76908900b Parents: ffcbdb7 Author: dengfangyuan <dengfangy...@lianjia.com> Authored: Sun Sep 10 12:31:18 2017 +0800 Committer: Li Yang <liy...@apache.org> Committed: Sun Sep 10 19:08:17 2017 +0800 ---------------------------------------------------------------------- .../java/org/apache/kylin/common/KylinConfigBase.java | 12 ++++++++++++ .../org/apache/kylin/common/restclient/RestClient.java | 10 +++++++++- .../src/main/resources/kylin-defaults.properties | 8 ++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/241a4ae0/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java ---------------------------------------------------------------------- diff --git a/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java b/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java index 8f5d495..9a55bf2 100644 --- a/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java +++ b/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java @@ -1207,6 +1207,18 @@ abstract public class KylinConfigBase implements Serializable { return Boolean.parseBoolean(getOptional("kylin.web.cross-domain-enabled", "true")); } + // ============================================================================ + // RESTCLIENT + // ============================================================================ + + public int getDefaultMaxPerRoute() { + return Integer.valueOf(this.getOptional("kylin.rest-client.connection.default-max-per-route", "20")); + } + + public int getMaxTotal() { + return Integer.valueOf(this.getOptional("kylin.rest-client.connection.max-total", "200")); + } + /** * metric */ http://git-wip-us.apache.org/repos/asf/kylin/blob/241a4ae0/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java ---------------------------------------------------------------------- diff --git a/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java b/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java index 95aa626..19daaef 100644 --- a/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java +++ b/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java @@ -41,6 +41,7 @@ import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.conn.PoolingClientConnectionManager; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; @@ -51,6 +52,8 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.kylin.common.KylinConfig; + /** * @author yangli9 */ @@ -113,7 +116,12 @@ public class RestClient { HttpConnectionParams.setSoTimeout(httpParams, HTTP_SOCKET_TIMEOUT_MS); HttpConnectionParams.setConnectionTimeout(httpParams, HTTP_CONNECTION_TIMEOUT_MS); - client = new DefaultHttpClient(httpParams); + final PoolingClientConnectionManager cm = new PoolingClientConnectionManager(); + KylinConfig config = KylinConfig.getInstanceFromEnv(); + cm.setDefaultMaxPerRoute(config.getDefaultMaxPerRoute()); + cm.setMaxTotal(config.getMaxTotal()); + + client = new DefaultHttpClient(cm, httpParams); if (userName != null && password != null) { CredentialsProvider provider = new BasicCredentialsProvider(); http://git-wip-us.apache.org/repos/asf/kylin/blob/241a4ae0/core-common/src/main/resources/kylin-defaults.properties ---------------------------------------------------------------------- diff --git a/core-common/src/main/resources/kylin-defaults.properties b/core-common/src/main/resources/kylin-defaults.properties index 815d7d0..0d96367 100644 --- a/core-common/src/main/resources/kylin-defaults.properties +++ b/core-common/src/main/resources/kylin-defaults.properties @@ -42,6 +42,14 @@ kylin.web.timezone=GMT+8 kylin.web.cross-domain-enabled=true +### RESTCLIENT | WEB ### + +#max connections of one route +kylin.rest-client.connection.default-max-per-route=20 + +#max connections of one rest-client +kylin.rest-client.connection.max-total=200 + ### SOURCE ###