[improve][broker,proxy] Use ChannelVoidPromise to avoid useless promise objects creation - #19141
Conversation
|
Maybe you should move the |
|
@nodece done, PTAL again |
|
Related to #16113. |
There was a problem hiding this comment.
Really great improvement. The only small nag is about naming. writeAndFlushVoidPromise is a very clumsy name. I don't have a good name to suggest immediately, but perhaps we could think about something.
It's not only the "useless promise objects creation" that is the reason to use voidPromise. Another reason to use a ctx.voidPromise() is because it adds proper error handling. Exceptions won't be propagated in Netty 4.x unless the the ChannelFuture's listener handles errors or something like ctx.voidPromise() is used.
(Related to SO Q&A https://stackoverflow.com/q/54169262 and https://stackoverflow.com/a/9030420 .)
I think renaming writeAndFlushVoidPromise in PulsarCommandSender and ServerCnx to writeAndFlush would simplify naming. Renaming writeAndFlushVoidPromise to writeAndFlushWithVoidPromise in the utility class would improve the naming.
| * Contains utility methods for working with Netty Channels. | ||
| */ | ||
| public class NettyChannelUtil { | ||
|
|
There was a problem hiding this comment.
Add proper javadoc to this method. I'd suggest explaining that besides reducing unnecessary object creation, using ctx.voidPromise() will propagate exceptions properly. Related to SO Q&A https://stackoverflow.com/q/54169262 and https://stackoverflow.com/a/9030420 .
lhotari
left a comment
There was a problem hiding this comment.
Please also replace any occurrences of .addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE) with the use of ctx.voidPromise() solution. I realised that I had added .addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE) in #14713 based on SO answer https://stackoverflow.com/a/54377238 . (I added a new answer to SO with the voidPromise solution.)
…se objects creation
…se objects creation
703e38c to
88f3dc4
Compare
|
Thanks @lhotari Lastly, I've also added a convenience method for closing the channel after the write. |
|
/pulsarbot rerun-failure-checks |
| } | ||
|
|
||
| private void writeAndFlush(ByteBuf cmd) { | ||
| NettyChannelUtil.writeAndFlushWithVoidPromise(outboundChannel, cmd); |
There was a problem hiding this comment.
Do you miss FIRE_EXCEPTION_ON_FAILURE?
There was a problem hiding this comment.
@nodece VoidChannelPromise will propagate exceptions.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #19141 +/- ##
============================================
- Coverage 47.22% 47.13% -0.10%
+ Complexity 10713 10672 -41
============================================
Files 713 713
Lines 69697 69703 +6
Branches 7485 7485
============================================
- Hits 32914 32854 -60
- Misses 33096 33143 +47
- Partials 3687 3706 +19
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Motivation
In the broker and proxy most of the writes callback are not considered. In those cases we can save useless allocations of default channel promises by using the
voidPromise()method.Modifications
VoidChannelPromiseif the promise result is never checkedVerifying this change
Documentation
docdoc-requireddoc-not-neededdoc-complete