You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Bjarne Rasmussen <br...@novell.com> on 2004/09/01 18:27:25 UTC

Performance

We found a small performance discrepancy between Java's
HttpURLConnection and HttpClient. Disabling stale connection checks
helps but HttpURLConnection is still faster for small payloads. Making
the following change to HttpConnection.java (line 689 in version 2.0.1)
speeds things up considerably:

   inputStream = new BufferedInputStream(socket.getInputStream());

The BufferedInputStream's mark/reset methods can be used in place of
PushbackInputStream.unread, e.g.:

    this.socket.setSoTimeout(timeout);
    inputStream.mark(1);
    int byteRead = inputStream.read();
    if (byteRead != -1) {
       inputStream.reset();
       LOG.debug("Input data available");
       result = true;
    } else {
       LOG.debug("Input data not available");
    }

Thanks,
Bjarne.


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


Re: Performance

Posted by Oleg Kalnichevski <ol...@apache.org>.
Bjarne,

Could you define 'considerably' in some ANSI units? ;-)

I have just recently dealt with this problem. The empirical data that I
got appears to suggest that there's a (more or less) constant delta in
performance of ~2-3ms, which only makes a difference for relatively
small payloads. For more or less real-life scenarios HttpClient should
be at least as fast or faster than HttpUrlConnection 

http://marc.theaimsgroup.com/?l=httpclient-commons-dev&m=109300858528261&w=2

I'll re-run the tests to see if this change does result in noticeable
performance gains and poke around the Java source code to see if there's
indeed a reason for PushbackInputStream#unread to be slower than
BufferedInputStream#reset

Thanks

Oleg



On Wed, 2004-09-01 at 18:27, Bjarne Rasmussen wrote:
> We found a small performance discrepancy between Java's
> HttpURLConnection and HttpClient. Disabling stale connection checks
> helps but HttpURLConnection is still faster for small payloads. Making
> the following change to HttpConnection.java (line 689 in version 2.0.1)
> speeds things up considerably:
> 
>    inputStream = new BufferedInputStream(socket.getInputStream());
> 
> The BufferedInputStream's mark/reset methods can be used in place of
> PushbackInputStream.unread, e.g.:
> 
>     this.socket.setSoTimeout(timeout);
>     inputStream.mark(1);
>     int byteRead = inputStream.read();
>     if (byteRead != -1) {
>        inputStream.reset();
>        LOG.debug("Input data available");
>        result = true;
>     } else {
>        LOG.debug("Input data not available");
>     }
> 
> Thanks,
> Bjarne.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
> 


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