--- "Noel J. Bergman" <[EMAIL PROTECTED]> wrote:
> > Since we are talking about improving SMTP data
> handler
> > class I want to draw attention to some performance
> > issues I had found earlier while analyzing
> > CharTerminatedInputStream class.
> 
> > The point of major concern was the use of read
> method
> > to read data from Socket InputStream. for example
> if
> > we consider an average mail size of 40KB, read
> method
> > will be called 40 x 1024 = 40960
> 
> This seems to be factually wrong.  Consider the
> following:
> 
>             in = new
> BufferedInputStream(socket.getInputStream(), 1024);
>             inReader = new CRLFTerminatedReader(in,
> "ASCII");
>             InputStream msgIn = new
> CharTerminatedInputStream(in,
> SMTPTerminator);
> 
> In all cases, the filtered data is coming through
> BufferedInputStream with a
> 1K buffer.

The point here is not that the data is coming from
BufferedInputStream. The point of concern is that the
read() method is called so many times putting a huge
amount of function call overhead so i am just trying
find a way to avoid that.

I would prefer a approach wherein we read a block of
data and use a for loop to find out the terminating
characters, if terminator falls  at the block
boundary, read next block and continue to match
terminator. In this process any extra bytes in buffer
can be easily unread if we use PushBackInputStream.

The logic behind the above approach is that the for
loop executes much faster on a block of data say 2KB
as compared to calling read() method 2048 times over
the same block.

I have tested the above mentioned approach and the
results are quite impressive. It takes 12 seconds to
read 110KB mail file 1000 times using
CharTerminatedInputStream while on the other hand it
takes hardly 5 seconds to read the same mail file 1000
times using the new approach. The hardware
configuration was CPU P4/RAM 256MB DDR/HDD 40GB/OS Win
98

I'll submit the source code of my test routine and the
new optimized InputStream in my forthcoming mails.

Cheers

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to