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] Make Consumer#equals more effective #18662

Merged

Conversation

Shawyeok
Copy link
Contributor

@Shawyeok Shawyeok commented Nov 28, 2022

Motivation

It's from a production case in my org, one of our consumer application constantly create consumer instance after increase topic partition due to old pulsar-client bug. The application got OOM eventually and broker publish latency goes more than 30s, so many publish requests timeout, broker latency go back normal after application restart.

It could be reproduce below:

pulsar-admin namespaces create -b 128 public/perf
pa namespaces set-max-consumers-per-topic -c 0 public/perf
pa namespaces set-max-consumers-per-subscription -c 0 public/perf
pulsar-perf produce -r 1000 persistent://public/perf/perf
pulsar-perf consume -st Shared -n 100000 persistent://public/perf/perf

After stop consume program, pulsar-io thread will be block for a while, publish latency will be very high (35s+ in my case).

It's a cpu profile during consumer stops:
image
image

The time complexity of CopyOnWriteList.remove is O(n), so Consumer#equals method is a hot method.
https://github.com/apache/pulsar/blob/master/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java#L192

Modifications

Flip && expression

Verifying this change

  • Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.

Documentation

  • doc-not-needed

Matching PR in forked repository

PR in forked repository: Shawyeok#5

Copy link
Contributor

@hangc0276 hangc0276 left a comment

Choose a reason for hiding this comment

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

Nice catch!

@codelipenghui codelipenghui added this to the 2.12.0 milestone Nov 29, 2022
@codelipenghui codelipenghui added type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages area/broker release/2.11.1 release/2.10.3 release/2.9.5 labels Nov 29, 2022
@Technoboy- Technoboy- closed this Nov 29, 2022
@Technoboy- Technoboy- reopened this Nov 29, 2022
@tisonkun
Copy link
Member

Thank you! Merging...

@tisonkun tisonkun merged commit 9e821b0 into apache:master Nov 29, 2022
lifepuzzlefun pushed a commit to lifepuzzlefun/pulsar that referenced this pull request Dec 9, 2022
liangyepianzhou pushed a commit that referenced this pull request Dec 14, 2022
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Jan 10, 2023
(cherry picked from commit 9e821b0)
(cherry picked from commit d2b3986)
lifepuzzlefun pushed a commit to lifepuzzlefun/pulsar that referenced this pull request Jan 10, 2023
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Jan 11, 2023
(cherry picked from commit 9e821b0)
(cherry picked from commit d2b3986)
coderzc pushed a commit that referenced this pull request Feb 28, 2023
@coderzc coderzc added the cherry-picked/branch-2.9 Archived: 2.9 is end of life label Mar 1, 2023
Annavar-satish pushed a commit to pandio-com/pulsar that referenced this pull request Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/broker cherry-picked/branch-2.9 Archived: 2.9 is end of life cherry-picked/branch-2.10 cherry-picked/branch-2.11 doc-not-needed Your PR changes do not impact docs ready-to-test release/2.9.5 release/2.10.3 release/2.11.1 type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants