Return-Path: X-Original-To: apmail-hc-dev-archive@www.apache.org Delivered-To: apmail-hc-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E1A7C1994B for ; Mon, 25 Apr 2016 19:05:14 +0000 (UTC) Received: (qmail 94121 invoked by uid 500); 25 Apr 2016 19:05:13 -0000 Delivered-To: apmail-hc-dev-archive@hc.apache.org Received: (qmail 93968 invoked by uid 500); 25 Apr 2016 19:05:13 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 93667 invoked by uid 99); 25 Apr 2016 19:05:13 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Apr 2016 19:05:13 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 3C9BA2C1F7D for ; Mon, 25 Apr 2016 19:05:13 +0000 (UTC) Date: Mon, 25 Apr 2016 19:05:13 +0000 (UTC) From: "Ralph Carlson (JIRA)" To: dev@hc.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Closed] (HTTPCLIENT-1739) repeated calls to HttpClients.custom.build take longer over time MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/HTTPCLIENT-1739?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Ralph Carlson closed HTTPCLIENT-1739. ------------------------------------- Resolution: Unresolved I don't have time to compile example for it. I am looking for alternative http client, feel free to ignore issues > repeated calls to HttpClients.custom.build take longer over time > ---------------------------------------------------------------- > > Key: HTTPCLIENT-1739 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1739 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpClient > Affects Versions: 4.5.2 > Environment: windows xp 32 bit, windows 7 64 bit and RedHat enterprise 7. Tested on Web Server apache-tomee-plus-1.7.1/apache-tomee-plus-1.7.4 deployed as @Webservice's calling external webservices using httpclient > Reporter: Ralph Carlson > Priority: Minor > > (Tested on latest version and version 4.3 and both have same issue.) > repeated calls to HttpClients.custom.build take longer over time. Tested using http library in webservice that calls and outside webservice. Initially HttpClients.custom.build run quickly for first several hundred, then takes increasingly longer to create client despite all objects clean up as per api spec each request. Some cache or code in the api takes longer and longer to create the client and no api methods exposed that can change this, only solution now was to create a Map to cache HttpClients so not creating new ones and look up HttpClient you need based on input parameters. > sample code that when called over and over again creates the issue: > {code:java} > protected static CloseableHttpClient _getCloseableHttpClient(HttpClientToolsInput input) throws Exception > { //method > //--------------- you can cache these object as static final since never change and still get the same result , included here as example code for bug > SSLContextBuilder sslContextBuilder = SSLContexts.custom(); > sslContextBuilder.loadTrustMaterial(null, new TrustStrategy() > { > public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } > @Override public boolean isTrusted(java.security.cert.X509Certificate[] chain,String authType) throws CertificateException { return true; } > }); > SSLContext sslContext = sslContextBuilder.build(); > > SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory( sslContext, new String[] {"TLSv1", "TLSv1.1", "TLSv1.2"},null,new HostnameVerifier() > { > public void verify(String host, X509Certificate cert) throws SSLException { } > @Override public boolean verify(String s, SSLSession sslSession) { > return true; > } > }); > > Registry socketFactoryRegistry = > RegistryBuilder. create().register("http", PlainConnectionSocketFactory.INSTANCE).register("https", sslConnectionSocketFactory).build(); > SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContextBuilder.build()); > //--------------- you can cache these object as static final : end > //--------------- these objects below are created and clean up each request > BasicHttpClientConnectionManager cm = new BasicHttpClientConnectionManager(socketFactoryRegistry); > RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout( > input.getSocketTimeout()).setConnectTimeout( > input.getConnectionTimeout()).setConnectionRequestTimeout( > input.getConnectionRequestTimeout()).build(); > // ---------------- get same bug if modify code to use different client other than CloseableHttpClient > // ---------------- the .build() method takes longer and longer to build each cycle > CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(cm) > .setDefaultRequestConfig(defaultRequestConfig) > .setSSLSocketFactory(sslsf) > .setDefaultCredentialsProvider(credsProvider).setSSLHostnameVerifier ( new NoopHostnameVerifier() ).build(); > > > > } //method > {code:java} > this HttpClient.customer().build() method should take roughly same amount of time to return object despite how many objects it created previously, now with enough runs it can take minutes to return object(s) -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org