[undertow-dev] setting a bufferSize

Edgar Espina espina.edgar at gmail.com
Mon Mar 2 07:30:05 EST 2015


Hi,

 Got this when using Undertow.Builder.setBufferSize, sorry for not being
clear in my previous email. You mentioned that undertow won't split into
two chunks of 5 bytes and overflows will use a pooled buffer... but now
how/when undertow decided to send and flush data? Is there a config
parameter? Thought it was Undertow.Builder.setBufferSize.

Thanks.



On Mon, Mar 2, 2015 at 1:17 AM, Stuart Douglas <sdouglas at redhat.com> wrote:

> I think you have misunderstood the point of the servlet output buffer.
>
> Basically the bufferSize parameter is the size of the servlets output
> buffer, it controls how much content can be written to the output stream
> before Undertow will start to send the data to the client. It does not
> provide any sort of maximum limit on the size, and it does not control the
> maximum write size (as in some situations we will write additional data
> using a gathering write).
>
> For example if you call setBufferSize(5), then write "Hi" to the output
> stream nothing will be sent to the client, as the response fits in the
> buffer, if you try and write "Hello World" then the response will be
> flushed, as the response is larger than 5 bytes and cannot be fully
> buffered. In this case though Undertow will not split the message into 5
> byte chunks, instead anything that overflows will be copied into a pooled
> buffer and written out using a gathering write for maximum performance.
>
> Undertow does not allocate arbitrary large amounts of memory for large
> responses (although note that in order to send the larger response in one
> write() call your application has to have allocated a byte array of that
> size).
>
> In general the only parameter you should change is the size of Undertow's
> internal buffer pool, and you should never call setBufferSize() unless you
> have a very specific reason (namely you want to fully buffer a response
> that is larger than the default buffer size).
>
> Stuart
>
>
>
> ----- Original Message -----
> > From: "Edgar Espina" <espina.edgar at gmail.com>
> > To: undertow-dev at lists.jboss.org
> > Sent: Monday, 2 March, 2015 11:45:27 AM
> > Subject: [undertow-dev] setting a bufferSize
> >
> > Hi,
> >
> > I found some issues will setting the bufferSize:
> >
> > 1) bufferSize isn't exactly the max number of bytes of a response body.
> For
> > example, bufferSize=5 with a "hello" response failed with a byte overflow
> > error. That's bc undertow requires some extra bytes for response headers
> and
> > others. This is not necessarily wrong but a response/buffer size is
> usually
> > the max number of bytes for the HTTP body (jetty, netty, others). It is
> > something minor, but will be nice to change this to represent the max
> size
> > of the HTTP body.
> >
> > 2) bufferSize is ignored when Content-Length is set. Here are some logs
> from
> > Apache HTTP client calling Undertow and Jetty with a buffer size of 20
> > bytes.
> >
> > Undertow: output size is 40bytes, buffer size is 20 bytes
> > 2015/03/01 21:30:32:053 ART [DEBUG] wire - http-outgoing-0 >> "GET
> /?data=
> > ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN &len=40 HTTP/1.1[\r][\n]"
> > 2015/03/01 21:30:32:053 ART [DEBUG] wire - http-outgoing-0 >> "Host:
> > localhost:54697[\r][\n]"
> > 2015/03/01 21:30:32:053 ART [DEBUG] wire - http-outgoing-0 >>
> "Connection:
> > Keep-Alive[\r][\n]"
> > 2015/03/01 21:30:32:054 ART [DEBUG] wire - http-outgoing-0 >>
> "User-Agent:
> > Apache-HttpClient/4.4-beta1 (Java 1.5 minimum; Java/1.8.0)[\r][\n]"
> > 2015/03/01 21:30:32:054 ART [DEBUG] wire - http-outgoing-0 >>
> > "Accept-Encoding: gzip,deflate[\r][\n]"
> > 2015/03/01 21:30:32:054 ART [DEBUG] wire - http-outgoing-0 >> "[\r][\n]"
> > 2015/03/01 21:30:32:120 ART [DEBUG] wire - http-outgoing-0 << "HTTP/1.1
> 200
> > OK[\r][\n]"
> > 2015/03/01 21:30:32:122 ART [DEBUG] wire - http-outgoing-0 <<
> "Content-Type:
> > text/html;charset=UTF-8[\r][\n]"
> > 2015/03/01 21:30:32:122 ART [DEBUG] wire - http-outgoing-0 <<
> > "Content-Length: 40[\r][\n]"
> > 2015/03/01 21:30:32:122 ART [DEBUG] wire - http-outgoing-0 << "Date:
> Mon, 02
> > Mar 2015 00:30:32 GMT[\r][\n]"
> > 2015/03/01 21:30:32:122 ART [DEBUG] wire - http-outgoing-0 << "[\r][\n]"
> > 2015/03/01 21:30:32:122 ART [DEBUG] wire - http-outgoing-0 << "
> > ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN "
> >
> > Jetty: output size is 40bytes, buffer size is 20 bytes
> > 2015/03/01 21:33:07:956 ART [DEBUG] wire - http-outgoing-1 >> "GET
> /?data=
> > ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN &len=40 HTTP/1.1[\r][\n]"
> > 2015/03/01 21:33:07:957 ART [DEBUG] wire - http-outgoing-1 >> "Host:
> > localhost:54732[\r][\n]"
> > 2015/03/01 21:33:07:957 ART [DEBUG] wire - http-outgoing-1 >>
> "Connection:
> > Keep-Alive[\r][\n]"
> > 2015/03/01 21:33:07:957 ART [DEBUG] wire - http-outgoing-1 >>
> "User-Agent:
> > Apache-HttpClient/4.4-beta1 (Java 1.5 minimum; Java/1.8.0)[\r][\n]"
> > 2015/03/01 21:33:07:957 ART [DEBUG] wire - http-outgoing-1 >>
> > "Accept-Encoding: gzip,deflate[\r][\n]"
> > 2015/03/01 21:33:07:957 ART [DEBUG] wire - http-outgoing-1 >> "[\r][\n]"
> > 2015/03/01 21:33:07:959 ART [DEBUG] wire - http-outgoing-1 << "HTTP/1.1
> 200
> > OK[\r][\n]"
> > 2015/03/01 21:33:07:959 ART [DEBUG] wire - http-outgoing-1 <<
> "Content-Type:
> > text/html;charset=UTF-8[\r][\n]"
> > 2015/03/01 21:33:07:959 ART [DEBUG] wire - http-outgoing-1 <<
> > "Content-Length: 40[\r][\n]"
> > 2015/03/01 21:33:07:959 ART [DEBUG] wire - http-outgoing-1 << "[\r][\n]"
> > 2015/03/01 21:33:07:959 ART [DEBUG] wire - http-outgoing-1 << "
> > ABCDEFGHIJKLMNOPQRST "
> > 2015/03/01 21:33:07:959 ART [DEBUG] headers - http-outgoing-1 <<
> HTTP/1.1 200
> > OK
> > 2015/03/01 21:33:07:959 ART [DEBUG] headers - http-outgoing-1 <<
> > Content-Type: text/html;charset=UTF-8
> > 2015/03/01 21:33:07:959 ART [DEBUG] headers - http-outgoing-1 <<
> > Content-Length: 40
> > 2015/03/01 21:33:07:960 ART [DEBUG] MainClientExec - Connection can be
> kept
> > alive indefinitely
> > 2015/03/01 21:33:07:960 ART [DEBUG] wire - http-outgoing-1 << "
> > UVWXYZABCDEFGHIJKLMN "
> >
> >
> > As you can see, undertow seems to ignore the bufferSize option and it
> sends
> > the whole output at once, while jetty sent two chunks of 20 bytes each.
> >
> > BufferSize work when Transfer-Encoding: Chunked is set, but ignored when
> > Content-Length is set. I didn't try with larger files but this makes me
> > worry bc I think sending a large file and setting Content-Length might
> > result in an OOM error.
> >
> > Found this in latest beta release: 1.2.0beta8 using
> exchange.getOutputStream
> > (blocking mode)
> >
> > Thanks
> >
> >
> > --
> > edgar
> >
> > _______________________________________________
> > undertow-dev mailing list
> > undertow-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/undertow-dev
>



-- 
edgar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20150302/6faf6582/attachment.html 


More information about the undertow-dev mailing list