-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[improve] Do not process acks in the Netty thread #22793
Conversation
(cherry picked from commit 5ed7dd1)
// which is the best thread ? | ||
return CompletableFuture.runAsync(() -> { | ||
acknowledgeMessage(positions, ackType, properties); | ||
}, topic.getBrokerService().pulsar().getExecutor()); |
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.
I think that an ordered executor (or pinned single thread executor) should be used so that all acknowledgements for a single subscription/cursor or topic get processed in a single thread.
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.
@lhotari something like topic.getBrokerService().getTopicOrderedExecutor().chooseThread(topicName)
?
I'd love to avoid adding yet another executor.
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.
@dlg99 yes makes sense. I guess that the thread selection should involve the subscription name so that acknowledgements for a single subscription get handled by a single thread so that there would be less contention.
@dlg99 @eolivelli Do you have any performance results to share? What is the improvement when this PR is applied? In what type of use cases does this have an impact? |
I don't have numbers to share because we did this work in the scope of a case in which an application generates huge lists of individuallyDeletedMessages ranges (millions). We have other patches to share that will allow compressing the cursor PositionInfo while writing to BookKeeper as well (and also chunk the payload if it doesn't fit 5MB). As the serialization happens when you call "subscription.acknowledge(xx)" you can see the netty thread blocked for milliseconds. |
@lhotari @eolivelli any objections to merging this? (PR needs an approval) |
I do have concerns. With asynchronous methods, there's usually a problem with back pressure. (another example: #22541 (comment)) Perhaps it's not a real issue for acknowledgements. |
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.
I think the premise that the code is "blocking the IO thread" is not super accurate.
There is no blocking behavior here (eg: waiting for some other operation to complete). It might be doing some significant amount of work and consume non-trivial amount of CPU, though that would be happening anyway in the other thread.
At the same time, this change will introduce an extra context switch for everyone else, even when amount of work to do for the ack is 0.
Motivation
Cherry-picked from internal @eolivelli work.
Do not block netty threads if cursor has a lot of individuallyDeletedMessages or needs to compress the PositionInfo (separate change)
Modifications
Run acks on pulsar executor
Verifying this change
This change is a trivial rework / code cleanup without any test coverage.
Does this pull request potentially affect one of the following parts:
NO
If the box was checked, please highlight the changes
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: dlg99#16