hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HTTPCLIENT-1493) Conditional stale connection checking
Date Tue, 03 Jun 2014 20:32:02 GMT

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1493?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14017104#comment-14017104
] 

Sebb commented on HTTPCLIENT-1493:
----------------------------------

I see.

I wonder is there any use case for the original strategy?
If so, maybe a wait time of zero could be used to skip the age check.

BTW, the code in AbstractConnPool should probably invoke entry.isExpired(System.currentTimeMillis()
before running validate() as the latter check may be a lot more expensive.

It also looks a bit odd to have the following code

{code}
if (entry.isClosed() || ... ) {
entry.close();
...
{code}

Putting the two changes together, perhaps try something like:

{code}
if (entry.isExpired(System.currentTimeMillis())) {
    entry.close();
} else if (this.validateAfterInactivity == 0) {
    if (!validate(entry)) {
        entry.close();
    }
} else if (this.validateAfterInactivity > 0) {
    if (entry.getUpdated() + this.validateAfterInactivity <= System.currentTimeMillis())
{
        if (!validate(entry)) {
            entry.close();
        }
    }
}
if (entry.isClosed()) {
    entry.close();
    this.available.remove(entry);
    pool.free(entry, false);
} else {
    break;
}
{code}

It might be cleaner to have a boolean helper method to decide whether to call validate - instead
of the two conditionals.

> Conditional stale connection checking
> -------------------------------------
>
>                 Key: HTTPCLIENT-1493
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1493
>             Project: HttpComponents HttpClient
>          Issue Type: New Feature
>            Reporter: Sebb
>             Fix For: 4.4 Final
>
>
> Stale connection checking is expensive. At present if it is enabled, it is performed
for every connection. This is quite expensive and generates additional requests.
> One reason for a server to drop a connection is when the connection has been idle for
a while. Some servers send Keep-Alive headers to inform the client of this; if they don't,
then the client will see an unexpected disconnection. Stale connection checking avoids this
problem, but at the cost of additional requests. When a connection is not busy, this is acceptable,
but for a busy connection the checks are mostly unnecessary.
> Another reason for dropping a connection is after it has been reused many times. The
server should send a connection close as part of the final response, but if it does not, a
stale check would help.
> For these reasons, it would be useful to be able to implement conditional stale connection
checking, based on connection idle time and/or connection reuse count. These conditions should
be optionally selectable.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

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


Mime
View raw message