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 Ken Krugler <kk...@transpac.com> on 2009/08/04 00:33:30 UTC

When to use ConnectionKeepAliveStrategy

Hi all,

On http://hc.apache.org/httpcomponents-client/tutorial/html/ch02.html  
the section titled "Connection keep alive strategy" talks about when  
to implement a custom keep-alive strategy.

But I thought that if a connection gets dropped by the server due to  
inactivity, the next request made using that stale connection will  
trigger an IOException, which HttpClient will automatically handle by  
re-trying with a new connection.

So is the issue that retrying winds up being less efficient, versus  
auto-closing connections? Or is my understanding of what HttpClient 4  
will do with a stale connection too optimistic?

Thanks,

-- Ken


--------------------------
Ken Krugler
TransPac Software, Inc.
<http://www.transpac.com>
+1 530-210-6378


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


Re: When to use ConnectionKeepAliveStrategy

Posted by Sam Crawford <sa...@gmail.com>.
The other issue is that if you try to use a stale connection to make a
POST/PUT request (i.e. entity enclosing) then that data will not
necessarily be repeatable, so a retry would fail here.

Thanks,

Sam


2009/8/4 Oleg Kalnichevski <ol...@apache.org>:
> On Mon, Aug 03, 2009 at 03:33:30PM -0700, Ken Krugler wrote:
>> Hi all,
>>
>> On http://hc.apache.org/httpcomponents-client/tutorial/html/ch02.html
>> the section titled "Connection keep alive strategy" talks about when to
>> implement a custom keep-alive strategy.
>>
>> But I thought that if a connection gets dropped by the server due to
>> inactivity, the next request made using that stale connection will
>> trigger an IOException, which HttpClient will automatically handle by
>> re-trying with a new connection.
>>
>> So is the issue that retrying winds up being less efficient, versus
>> auto-closing connections? Or is my understanding of what HttpClient 4
>> will do with a stale connection too optimistic?
>>
>> Thanks,
>>
>> -- Ken
>>
>>
>
> Ken,
>
> It is not necessarily less efficient but some folks just do not like the idea
> of getting an exception. Besides, if combined with a watcher thread evicting
> expired connection from the pool, ConnectionKeepAliveStrategy helps ensure
> connections get closed as they expire, instead of sitting in the pool
> indefinitely waiting for a request to be made.
>
> Overall, it just makes things cleaner.
>
> Oleg
>
>
>> --------------------------
>> Ken Krugler
>> TransPac Software, Inc.
>> <http://www.transpac.com>
>> +1 530-210-6378
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

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


Re: When to use ConnectionKeepAliveStrategy

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, Aug 03, 2009 at 03:33:30PM -0700, Ken Krugler wrote:
> Hi all,
>
> On http://hc.apache.org/httpcomponents-client/tutorial/html/ch02.html  
> the section titled "Connection keep alive strategy" talks about when to 
> implement a custom keep-alive strategy.
>
> But I thought that if a connection gets dropped by the server due to  
> inactivity, the next request made using that stale connection will  
> trigger an IOException, which HttpClient will automatically handle by  
> re-trying with a new connection.
>
> So is the issue that retrying winds up being less efficient, versus  
> auto-closing connections? Or is my understanding of what HttpClient 4  
> will do with a stale connection too optimistic?
>
> Thanks,
>
> -- Ken
>
>

Ken,

It is not necessarily less efficient but some folks just do not like the idea
of getting an exception. Besides, if combined with a watcher thread evicting
expired connection from the pool, ConnectionKeepAliveStrategy helps ensure
connections get closed as they expire, instead of sitting in the pool
indefinitely waiting for a request to be made. 

Overall, it just makes things cleaner.

Oleg


> --------------------------
> Ken Krugler
> TransPac Software, Inc.
> <http://www.transpac.com>
> +1 530-210-6378
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>

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