cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joerg Heinicke <joerg.heini...@gmx.de>
Subject Re: BufferedOutputStream
Date Tue, 03 Jun 2008 14:44:57 GMT
Reinhard Pötz <reinhard <at> apache.org> writes:

> >> Is my understanding right that the content length header can only be set 
> >> as long as you haven't written into the underlying output stream?
> > 
> > Yes, it is. That's why the buffering has to be big enough, i.e. nothing must
> > have been flushed yet.
> 
> What happens when the buffer size is exceeded? Does it mean that the 
> output is streamed and the content length parameter can't be set?

If the buffer size is exceeded the output stream is flushed and eventually
written to the response. A header like the content-length can no longer be set.

That's why Cocoon's BufferedOutputStream was setup to buffer all and everything
by default which lead to COCOON-2168 [1] with Cocoon's default setting. With the
change to a buffer of 1 MB rather than endless buffering we switched back to
java.io.BufferedOutputStream, but this allocates the memory for the buffer
immediately. So even with 10 KB pages you always end up with 1 MB byte[]. I
intend to fix this in our BufferedOutputStream with an increasing buffer and the
two configuration parameters initial buffer size and flush buffer size.

Just to make it clear: We talk about default configuration of Cocoon here. You
still can enforce complete buffering by setting flush buffer size to -1 again.
But it's up to the user to enforce this and potentially run into OOME. It's also
up to the users to find a reasonable flush buffer size as it always used to be
when they haven't used the endless buffering. Only thing that is going to change
is in case of not endless buffering: The full buffer is not allocated
immediately but step by step.

Joerg

[1] https://issues.apache.org/jira/browse/COCOON-2168


Mime
View raw message