Skip to content
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][broker] Choose random thread for consumerFlow in PersistentDispatcherSingleActiveConsumer #20522

Merged
merged 1 commit into from
Jun 12, 2023

Conversation

AnonHxy
Copy link
Contributor

@AnonHxy AnonHxy commented Jun 7, 2023

Motivation

Currently, all subscriptions of one topic will do consuemrFlow action in a single thread, which is chosen by topicName:

this.topicExecutor = topic.getBrokerService().getTopicOrderedExecutor().chooseThread(topicName);

If there is a large number of subscriptions in a topic, all the work will focus on one thread ---- the chosen thread, which will reduce the consume performance. So this this patch , I'd like to choose a ramdom thread for consumerFlow in PersistentDispatcherSingleActiveConsumer to improve the consume performance.

Modifications

  • topic.getBrokerService().getTopicOrderedExecutor().chooseThread(topicName); -> topic.getBrokerService().getTopicOrderedExecutor().chooseThread();
  • this.topicExecutor -> this.executor

Verifying this change

  • Make sure that the change passes the CI checks.

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: AnonHxy#42

@AnonHxy AnonHxy self-assigned this Jun 7, 2023
@AnonHxy AnonHxy requested review from merlimat and congbobo184 June 7, 2023 06:55
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Jun 7, 2023
Copy link
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason we chooseThread(topicName) is that we'd like to order all tasks of the same topics.

This patch can introduce new race conditions that different consumers of the same topics now submit tasks that can be run concurrently. Please provide more details on how this patch won't cause such regressions.

@congbobo184
Copy link
Contributor

congbobo184 commented Jun 7, 2023

The reason we chooseThread(topicName) is that we'd like to order all tasks of the same topics.

why we need to use the same thread with the different sub in the same topic?
https://github.com/apache/pulsar/blob/master/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java#L544
It does not use this thread with the same sub in a topic

#1522 only to mmon thread for frequence operations, don't need to promise the different dispatcher with the same topic need to use the same thread

@tisonkun
Copy link
Member

tisonkun commented Jun 7, 2023

@congbobo184 Thank you! This is the evidence I ask for fulfilling the description :D

@tisonkun tisonkun dismissed their stale review June 7, 2023 13:21

resolved

@AnonHxy
Copy link
Contributor Author

AnonHxy commented Jun 8, 2023

Copy link
Contributor

@gaoran10 gaoran10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@HQebupt HQebupt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@congbobo184 congbobo184 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@AnonHxy AnonHxy force-pushed the single_dispatcher_thread_optimize branch from 725d1b9 to 2c8bc30 Compare June 10, 2023 16:04
@AnonHxy AnonHxy merged commit 51c2bb4 into apache:master Jun 12, 2023
Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnonHxy - do you have any metrics to show how this affects performance?

For what it's worth, I see that the PersistentDispatcherMultipleConsumers uses this same logic and that the primary synchronization withinPersistentDispatcherSingleActiveConsumer is on the object itself, so I don't see any reason that we shouldn't make this change.

@AnonHxy
Copy link
Contributor Author

AnonHxy commented Jun 14, 2023

do you have any metrics to show how this affects performance?

There is no specific metrcs for this, but this patch solves the problem that too many subscriptions in one topic will consume slow in my in production environment. @michaeljmarshall

@Technoboy- Technoboy- added this to the 3.1.0 milestone Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-not-needed Your PR changes do not impact docs ready-to-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants