You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Sebastiano Vigna <vi...@di.unimi.it> on 2013/11/13 14:35:29 UTC

When does a connection get closed when using a DefaultConnectionReuseStrategy?

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?

Ciao,

					seba


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: When does a connection get closed when using a DefaultConnectionReuseStrategy?

Posted by Sebastiano Vigna <vi...@di.unimi.it>.
On 13 Nov 2013, at 5:38 PM, Oleg Kalnichevski <ol...@apache.org> wrote:

>> 
>> 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.


Now, just out of curiosity and because I coulnd't follow the code: when does the (default) connection manager decide that a particular connection is idle? When we switch to another host?

Ciao,

					seba


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: When does a connection get closed when using a DefaultConnectionReuseStrategy?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2013-11-13 at 16:48 +0100, Sebastiano Vigna wrote:
> On 13 Nov 2013, at 4:43 PM, Oleg Kalnichevski <ol...@apache.org> 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


Re: When does a connection get closed when using a DefaultConnectionReuseStrategy?

Posted by Sebastiano Vigna <vi...@di.unimi.it>.
On 13 Nov 2013, at 4:43 PM, Oleg Kalnichevski <ol...@apache.org> 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?

Ciao,

					seba


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: When does a connection get closed when using a DefaultConnectionReuseStrategy?

Posted by Oleg Kalnichevski <ol...@apache.org>.
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?

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org