[undertow-dev] Questions about Undertow's ByteBufferPool

Stuart Douglas sdouglas at redhat.com
Sun Jun 18 19:24:54 EDT 2017


Looking at the Netty code it does not pool arbitrary sized buffers,
but has a few predefined sizes, and if a buffer that is larger than
supported is requested it will be allocated directly.

Why do you need arbitrary sized buffers? Anything smaller than the
pool size is obviously not a problem, but for anything larger you can
just allocate multiple buffers (generally up to some sort of limit).
An example of Undertow code that does this is in ServletOutputStream,
which if the provided byte[] array is too large we attempt to allocate
more buffers, and if it still does not fit utilise multiple gathering
writes:

https://github.com/undertow-io/undertow/blob/master/servlet/src/main/java/io/undertow/servlet/spec/ServletOutputStreamImpl.java#L154

(although without knowing exactly what your use case is it is hard to
say how relevant this is to you).


Stuart

On Fri, Jun 16, 2017 at 4:35 PM, Violeta Georgieva <milesg78 at gmail.com> wrote:
> Hi Stuart,
>
> Spring Framework 5 uses Undertow APIs directly, i.e. not going through the
> Servlet API.
> When reading the request the ByteBufferPool is obtained from the connection
> and then the PooledByteBuffer is allocated and used [1].
> Also the PooledByteBuffer is closed in ExchangeCompletionListener [2].
>
> So currently the usage is limited only to the request reading.
> In order to extend the usage of the ByteBufferPool we need to be able to
> allocate buffers with a concrete size.
> At the moment (what I saw in the sources) the ByteBufferPool is created with
> a specific buffer size
> and the pooled buffers are created with exactly this size.
>
> For comparison see the io.netty.buffer.PooledByteBufAllocator in Netty
> which provides a functionality to allocated buffers with a specific size
> [3], [4], [5].
>
> So is it possible to achieve the same with the Undertow's ByteBufferPool?
> If such functionality is not existing do you think it is feasible to add
> such API?
>
> Thanks,
> Violeta
>
> [1]
> https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java#L144-L148
> [2]
> https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java#L127-L133
> [3]
> https://github.com/netty/netty/blob/4.1/buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java#L107-L112
> [4]
> https://github.com/netty/netty/blob/4.1/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java#L301
> [5]
> https://github.com/netty/netty/blob/4.1/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java#L318
>
>
> 2017-06-14 3:21 GMT+03:00 Stuart Douglas <sdouglas at redhat.com>:
>>
>> It should be used anytime you require a large direct buffer (generally
>> for IO operations). Depending on your app you may not need to use them
>> directly at all, although Undertow will always use them internally.
>>
>> The buffers are fixed size which is determined dynamically (unless
>> explicitly specified), generally they will be 16kb as this seems to
>> give optimal IO performance.
>>
>> Stuart
>>
>> On Mon, Jun 12, 2017 at 11:06 AM, Violeta Georgieva <milesg78 at gmail.com>
>> wrote:
>> > Hi,
>> >
>> > I have few questions about Undertow's ByteBufferPool.
>> > Are there any best practices how it should be used?
>> > Also are the ByteBuffers always fixed in size?
>> >
>> > Thanks,
>> > Violeta
>> >
>> > _______________________________________________
>> > undertow-dev mailing list
>> > undertow-dev at lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/undertow-dev
>
>


More information about the undertow-dev mailing list