Hi Oleg,
Forgot to mention:
It's not that BufferedInputStream#reset is better or faster than
PushbackInputStream#unread. The BufferedInputStream merely supports
mark/reset as a side-effect of doing buffering. The PushbackInputStream
doesn't buffer. From HttpParser:
public static byte[] readRawLine(InputStream inputStream) throws
IOException {
ByteArrayOutputStream buf = new ByteArrayOutputStream(64);
int ch;
while ((ch = inputStream.read()) >= 0) {
buf.write(ch);
if (ch == '\n') {
break;
}
}
if (buf.size() == 0) {
return null;
}
return buf.toByteArray();
}
With PushbackInputStream every call to read will result in a JNI call
in the underlying SocketInputStream. With BufferedInputStream the socket
data is sucked in in 2K blocks thus vastly reducing the amount of JNI
we're doing.
Thanks,
Bjarne.
>>> [EMAIL PROTECTED] 9/1/2004 1:30:13 PM >>>
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:
[EMAIL PROTECTED]
> For additional commands, e-mail:
[EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]