Return-Path: X-Original-To: apmail-hc-httpclient-users-archive@www.apache.org Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 051B710117 for ; Wed, 13 Nov 2013 16:39:00 +0000 (UTC) Received: (qmail 62722 invoked by uid 500); 13 Nov 2013 16:38:58 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 62700 invoked by uid 500); 13 Nov 2013 16:38:58 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 62692 invoked by uid 99); 13 Nov 2013 16:38:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Nov 2013 16:38:57 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy includes SPF record at spf.trusted-forwarder.org) Received: from [217.150.250.48] (HELO kalnich.nine.ch) (217.150.250.48) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Nov 2013 16:38:51 +0000 Received: from [192.168.42.106] (unknown [213.55.184.222]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by kalnich.nine.ch (Postfix) with ESMTPSA id DAAC5B8005D for ; Wed, 13 Nov 2013 17:38:29 +0100 (CET) Message-ID: <1384360708.3761.95.camel@ubuntu> Subject: Re: When does a connection get closed when using a DefaultConnectionReuseStrategy? From: Oleg Kalnichevski To: HttpClient User Discussion Date: Wed, 13 Nov 2013 17:38:28 +0100 In-Reply-To: <8960B2ED-3336-4301-AF46-F89142D50195@di.unimi.it> References: <0E99678E-B658-49CD-A939-0661548DE3A6@di.unimi.it> <1384357418.3761.93.camel@ubuntu> <8960B2ED-3336-4301-AF46-F89142D50195@di.unimi.it> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.8.4-0ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org On Wed, 2013-11-13 at 16:48 +0100, Sebastiano Vigna wrote: > On 13 Nov 2013, at 4:43 PM, Oleg Kalnichevski wrote: > > > On Wed, 2013-11-13 at 14:35 +0100, Sebastiano Vigna wrote: > >> Question: when a connection opened with DefaultConnectionReuseStrategy will be actually closed? When the same client is used with a different host? Or is there some explicit operation that must be done to close the connection? > >> > > > > I am not sure I understand the question. Do you mean when a connection > > kept alive in the pool gets closed when expired? > > > Sorry. > > We use the following client: > > httpClient = HttpClients.custom() > .setSslcontext( TRUST_SELF_SIGNED_SSL_CONTEXT ) > .setConnectionManager( connManager ) > .setConnectionReuseStrategy( DefaultConnectionReuseStrategy.INSTANCE ) > .build(); > > Now, after we do a number of consecutive fetches form the same host, we know that it won't happen for several seconds, or even minutes. We don't want the client to keep the connection open after we completed our fetch cycle. We download in parallel from hundreds of thousands of hosts at several thousand pages per second, so we cannot leave open connection around or we risk to exaust the ports. > > How can we be sure that the TCP connection with a host is shut down immediately, after we finish our batch of consecutive fetches? > NHttpClientConnectionManager#closeIdleConnections( 0, TimeUnit.MILLISECONDS) is what you want. Oleg --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org For additional commands, e-mail: httpclient-users-help@hc.apache.org