hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Igor Lubashev" <IgorLubas...@everypoint.com>
Subject RE: Performance issues in ChunkedInputStream
Date Thu, 12 Apr 2007 17:40:40 GMT
1.  BufferedInputStream is working fine.  I've looked at the source, and
it correctly tried to read data only when its internal buffer is
exhausted.  Most read calls reference only the internal buffer.  When
the data does get read from the underlying stream, it tries to read it
in large chunks.  (Of course, if the underlying stream returns very
little data, it is a different problem.)

2.  It is hard to believe that reading a byte at a time is a bottleneck,
but I've just quickly written a LineReaderInputStream, which is derived
from BufferedInputStream, so all the searching for CRLF/LF happens very
quickly internally.  The source is attached.

Just call readLine() method, and you'll get Strings out of the stream.
You can interleave all regular stream operations and readLine() calls.
However, if you wish to use readLine() *after* using the stream's read()
methods, make sure that you do not inadvertently pass this stream to
anything that is buffering the stream's data (or your strings may get
consumed via buffering).

- Igor

>>> I looked at the source for BufferedInputStream and it looks like
>>> it tries to fill the empty space in the buffer each time you read
>> it (for a socket connection it will read more than one packet of
>>> instead of just doing a single read from the underlying stream.
>> Ok, then the byte-by-byte reading in CIS when parsing the chunk
>> might well be the problem. If you want to fix that, you'll have to
>> deeply into CIS. Here is what I would do if I had no other choice:
>> - extend CIS by a local byte array as a buffer (needs two extra int
>>   for cursor and fill size)
>> - change the chunk header parsing to read a bunch of bytes into the
>>   buffer, then parsing from there
>> - change all read methods to return leftover bytes from the buffer
>>   before calling a read on the underlying stream
>> hope that helps,
>>   Roland
>Tony and Roland,
>I suspect rather strongly it is BufferedInputStream that needs fixing, 
>not ChunkedInputStream

View raw message