You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by ra...@gmx.de on 2003/08/01 12:58:18 UTC

Re: cvs commit: jakarta-poi/src/testcases/org/apache/poi/poifs/filesystem SlowInputStream.java TestDocument.java

>   Slow input stream patch, bug 13478
> ...
>           for (;;) {
>               int got = in.read(b, off + total, len - total);
>               if (got < 0) {
>                   return (total == 0) ? -1 : total;
>               } else {
>                   total += got;
>                   if (total == len)
>                       return total;
>               }
>           }

Hi Avik,

thanks for the patch! I suggest that the loop waits for a moment when read()
received less bytes than expected. Otherwise it would be a waste of CPU
cycles on very slow streams.

Best regards
Rainer Klute

-- 
                  RAINER KLUTE IT-CONSULTING GMBH
Dipl.-Inform.
Rainer Klute      klute@rainer-klute.de
Körner Grund 24   Telefon: +49 172 2324824
D-44143 Dortmund  Telefax: +49 231 5349423

COMPUTERBILD 15/03: Premium-e-mail-Dienste im Test
--------------------------------------------------
1. GMX TopMail - Platz 1 und Testsieger!
2. GMX ProMail - Platz 2 und Preis-Qualitätssieger!
3. Arcor - 4. web.de - 5. T-Online - 6. freenet.de - 7. daybyday - 8. e-Post


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Re: cvs commit: jakarta-poi/src/testcases/org/apache/poi/poifs/filesystem SlowInputStream.java TestDocument.java

Posted by Chris Nokleberg <ch...@sixlegs.com>.
On Fri, Aug 01, 2003 at 12:33:36PM -0400, Andrew C. Oliver wrote:
> I'm not saying it is.  I'm just saying we should consider it.  Weird, for
> some reason I thought interrupt was deprecated as well.  Apparently its not,
> only suspend, stop and resume.  I still avoid interrupt because I've seen
> some weird threading issues with WebSphere when it's used.  Also note that
> EJBs are not supposed to launch Thread.  While I don't think generating XLS
> through an EJB is the most brilliant thing to do, it is done and there
> probably are reasons to do it.  (esp where EJB->WebService are 1:1)

Another possibility for people who need a timeout w/o a Thread is that
they can wrap the InputStream in something like a TimeoutInputStream...no
need to build it into the core POI IO routines.

Chris

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Re: cvs commit: jakarta-poi/src/testcases/org/apache/poi/poifs/filesystem SlowInputStream.java TestDocument.java

Posted by "Andrew C. Oliver" <ac...@apache.org>.
On 8/1/03 12:30 PM, "Chris Nokleberg" <ch...@sixlegs.com> wrote:

> On Fri, Aug 01, 2003 at 12:08:52PM -0400, Andrew C. Oliver wrote:
>> 
>>> 
>>> You could have easily had a timeout situation with the old code--it was
>>> blocking as well. In any case, I don't think this is the appropriate
>>> place for a timeout. Instead, you should use a dedicated thread for
>>> reading the document if that is a concern.
>>> 
>> 
>> The problem is that the only methods of stopping a dedicated thread are
>> deprecated and are not blessed for multi-platform.
> 
> There are ways...interrupt(), setting a flag to be checked by the
> reading thread periodically, etc. But my main point was that the current
> situation is not any different from the previous one, where there was no
> timeout code--you could block on the very first read of the stream. The
> discussion of how to implement a timeout is orthogonal to the slow input
> stream patch.

I'm not saying it is.  I'm just saying we should consider it.  Weird, for
some reason I thought interrupt was deprecated as well.  Apparently its not,
only suspend, stop and resume.  I still avoid interrupt because I've seen
some weird threading issues with WebSphere when it's used.  Also note that
EJBs are not supposed to launch Thread.  While I don't think generating XLS
through an EJB is the most brilliant thing to do, it is done and there
probably are reasons to do it.  (esp where EJB->WebService are 1:1)

-Andy

> 
> Chris
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
> Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta POI Project: http://jakarta.apache.org/poi/
> 

-- 
Andrew C. Oliver
http://www.superlinksoftware.com/poi.jsp
Custom enhancements and Commercial Implementation for Jakarta POI

http://jakarta.apache.org/poi
For Java and Excel, Got POI?


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Re: cvs commit: jakarta-poi/src/testcases/org/apache/poi/poifs/filesystem SlowInputStream.java TestDocument.java

Posted by Chris Nokleberg <ch...@sixlegs.com>.
On Fri, Aug 01, 2003 at 12:08:52PM -0400, Andrew C. Oliver wrote:
> 
> > 
> > You could have easily had a timeout situation with the old code--it was
> > blocking as well. In any case, I don't think this is the appropriate
> > place for a timeout. Instead, you should use a dedicated thread for
> > reading the document if that is a concern.
> >
> 
> The problem is that the only methods of stopping a dedicated thread are
> deprecated and are not blessed for multi-platform.

There are ways...interrupt(), setting a flag to be checked by the
reading thread periodically, etc. But my main point was that the current
situation is not any different from the previous one, where there was no
timeout code--you could block on the very first read of the stream. The
discussion of how to implement a timeout is orthogonal to the slow input
stream patch.

Chris

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Re: cvs commit: jakarta-poi/src/testcases/org/apache/poi/poifs/filesystem SlowInputStream.java TestDocument.java

Posted by Rainer Klute <ra...@epost.de>.
On Fri, 1 Aug 2003 08:55:00 -0700 Chris Nokleberg <ch...@sixlegs.com> wrote:

> On Fri, Aug 01, 2003 at 09:33:10AM -0400, Andrew C. Oliver wrote:
> > On 8/1/03 6:58 AM, "rainer.klute@gmx.de" <ra...@gmx.de> wrote:
> > 
> > >>   Slow input stream patch, bug 13478
> > >> ...
> > >>           for (;;) {
> > >>               int got = in.read(b, off + total, len - total);
> > >>               if (got < 0) {
> > >>                   return (total == 0) ? -1 : total;
> > >>               } else {
> > >>                   total += got;
> > >>                   if (total == len)
> > >>                       return total;
> > >>               }
> > >>           }
> > > 
> > > Hi Avik,
> > > 
> > > thanks for the patch! I suggest that the loop waits for a moment when read()
> > > received less bytes than expected. Otherwise it would be a waste of CPU
> > > cycles on very slow streams.
> 
> It will never just spin, it is guaranteed to return at least one byte
> each time through the loop. And the way these things actually work, it
> won't be just one byte either--there is almost always some buffering
> going on at a lower level. Overall I am positive that making it wait
> will have a negative impact on performance.

Oops, yes, you are right, Chris.

Best regards
Rainer Klute

                           Rainer Klute IT-Consulting GmbH
  Dipl.-Inform.
  Rainer Klute             E-Mail:  klute@rainer-klute.de
  Körner Grund 24          Telefon: +49 172 2324824
D-44143 Dortmund           Telefax: +49 231 5349423

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Re: cvs commit: jakarta-poi/src/testcases/org/apache/poi/poifs/filesystem SlowInputStream.java TestDocument.java

Posted by "Andrew C. Oliver" <ac...@apache.org>.
> 
> You could have easily had a timeout situation with the old code--it was
> blocking as well. In any case, I don't think this is the appropriate
> place for a timeout. Instead, you should use a dedicated thread for
> reading the document if that is a concern.
>

The problem is that the only methods of stopping a dedicated thread are
deprecated and are not blessed for multi-platform.

-Andy
 
> Chris
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
> Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta POI Project: http://jakarta.apache.org/poi/
> 

-- 
Andrew C. Oliver
http://www.superlinksoftware.com/poi.jsp
Custom enhancements and Commercial Implementation for Jakarta POI

http://jakarta.apache.org/poi
For Java and Excel, Got POI?


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Re: cvs commit: jakarta-poi/src/testcases/org/apache/poi/poifs/filesystem SlowInputStream.java TestDocument.java

Posted by Chris Nokleberg <ch...@sixlegs.com>.
On Fri, Aug 01, 2003 at 09:33:10AM -0400, Andrew C. Oliver wrote:
> On 8/1/03 6:58 AM, "rainer.klute@gmx.de" <ra...@gmx.de> wrote:
> 
> >>   Slow input stream patch, bug 13478
> >> ...
> >>           for (;;) {
> >>               int got = in.read(b, off + total, len - total);
> >>               if (got < 0) {
> >>                   return (total == 0) ? -1 : total;
> >>               } else {
> >>                   total += got;
> >>                   if (total == len)
> >>                       return total;
> >>               }
> >>           }
> > 
> > Hi Avik,
> > 
> > thanks for the patch! I suggest that the loop waits for a moment when read()
> > received less bytes than expected. Otherwise it would be a waste of CPU
> > cycles on very slow streams.

It will never just spin, it is guaranteed to return at least one byte
each time through the loop. And the way these things actually work, it
won't be just one byte either--there is almost always some buffering
going on at a lower level. Overall I am positive that making it wait
will have a negative impact on performance.

> That and it needs a timeout as well.

You could have easily had a timeout situation with the old code--it was
blocking as well. In any case, I don't think this is the appropriate
place for a timeout. Instead, you should use a dedicated thread for
reading the document if that is a concern.

Chris

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Re: cvs commit: jakarta-poi/src/testcases/org/apache/poi/poifs/filesystem SlowInputStream.java TestDocument.java

Posted by "Andrew C. Oliver" <ac...@apache.org>.
On 8/1/03 6:58 AM, "rainer.klute@gmx.de" <ra...@gmx.de> wrote:

>>   Slow input stream patch, bug 13478
>> ...
>>           for (;;) {
>>               int got = in.read(b, off + total, len - total);
>>               if (got < 0) {
>>                   return (total == 0) ? -1 : total;
>>               } else {
>>                   total += got;
>>                   if (total == len)
>>                       return total;
>>               }
>>           }
> 
> Hi Avik,
> 
> thanks for the patch! I suggest that the loop waits for a moment when read()
> received less bytes than expected. Otherwise it would be a waste of CPU
> cycles on very slow streams.
> 
> Best regards
> Rainer Klute

That and it needs a timeout as well.

-- 
Andrew C. Oliver
http://www.superlinksoftware.com/poi.jsp
Custom enhancements and Commercial Implementation for Jakarta POI

http://jakarta.apache.org/poi
For Java and Excel, Got POI?


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/