-
Notifications
You must be signed in to change notification settings - Fork 566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of ResponseWriter using pooled Netty buffers #2805
Implementation of ResponseWriter using pooled Netty buffers #2805
Conversation
Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
…it tests are passing. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
…d up release logic to avoid warnings in logs. Better implementation of isFlushChunk. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
…nstream using a semaphore and volatiles. Ensure onComplete is called at most once. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
req.next(); | ||
}); | ||
return new OutputStream() { | ||
@Override | ||
public void write(int b) throws IOException { | ||
public void write(int b) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This could be a static class.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be OutputStream.nullOutputStream();
while (len > 0) { | ||
if (byteBuf == null) { | ||
awaitRequest(); | ||
byteBuf = PooledByteBufAllocator.DEFAULT.buffer(BYTEBUF_DEFAULT_SIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spericas This was what I was asking about earlier today. This will not make use of direct buffers, and perhaps that is just fine. On the other hand, if you use ByteBufAllocator.DEFAULT
you'll get some perhaps useful behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry; I got slightly confused here. PooledByteBufAllocator
will indeed use direct buffers. I guess my comment is more: if you simply use ByteBufAllocator.DEFAULT
you pick up whatever default behavior Netty wants in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But If we use ByteBufAllocator
today, are we guaranteed to get a pooled buffer now? After all, that is the whole point of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you see https://github.com/netty/netty/blob/1529ef1794e0a6654fa4334fd979b769d6940e61/buffer/src/main/java/io/netty/buffer/ByteBufUtil.java#L77-L93 you can see what it does. In terms of guarantees, there is very little documentation so effectively no contract as to what you can expect or depend upon.
webserver/webserver/src/main/java/io/helidon/webserver/ByteBufDataChunk.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about merging ByteBufDataChunk and ByteBufRequestChunk ?
That class includes the reference queue's logic. Perhaps we can connect the two at some point, but that's a task for a different day in my view. |
@Override | ||
public int remaining() { | ||
int remaining = 0; | ||
for (ByteBuf byteBuf : byteBufs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're going to do stuff with multiple ByteBuf
instances, consider Netty's built-in CompositeByteBuf
. It may or may not suit your needs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; I made a note about Netty's built-in CompositeByteBuf
.
* Initial prototype based on Netty buffers. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Revised implementation of ByteBufDataChunk and ResponseWriter. All unit tests are passing. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Removed test. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Checkstyle problems. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Ensure proper release of buffers. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Renamed DataChunkImpl as we now have multiple implementations. Cleaned up release logic to avoid warnings in logs. Better implementation of isFlushChunk. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Fixed checkstyle. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Fixed checkstyle. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Copyright in module-info. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Lazy creation of DataChunkOutputStream publisher. Guard access to downstream using a semaphore and volatiles. Ensure onComplete is called at most once. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Implement old method in new ByteBufDataChunk class for testing purposes. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Use a static create() method instead of a public constructor. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
…io#2805) * Initial prototype based on Netty buffers. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Revised implementation of ByteBufDataChunk and ResponseWriter. All unit tests are passing. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Removed test. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Checkstyle problems. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Ensure proper release of buffers. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Renamed DataChunkImpl as we now have multiple implementations. Cleaned up release logic to avoid warnings in logs. Better implementation of isFlushChunk. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Fixed checkstyle. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Fixed checkstyle. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Copyright in module-info. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Lazy creation of DataChunkOutputStream publisher. Guard access to downstream using a semaphore and volatiles. Ensure onComplete is called at most once. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Implement old method in new ByteBufDataChunk class for testing purposes. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Use a static create() method instead of a public constructor. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
Changes in this PR:
With all these changes, the DataChunk's passed from Jersey/Helidon's layer are now backed by pooled Netty's ByteBufs. This should reduced the amount of time spent running GC's in MP applications.