Skip to content

[client] Optimize pause when creating sub consumers in multi-topic consumer - #14566

Merged
Jason918 merged 1 commit into
apache:masterfrom
Jason918:fix-multi-topic-consumer-pasue
Mar 23, 2022
Merged

Jason918 merged 1 commit into
apache:masterfrom
Jason918:fix-multi-topic-consumer-pasue

Conversation

@Jason918

@Jason918 Jason918 commented Mar 5, 2022 •

Copy link
Copy Markdown
Contributor

Motivation

Currently, if we subscribe new partitions/topics when multiTopicConsumer is paused, the sub consumers will start in non-pause mode and then changed to pause.

Modifications

Set startPause config when creating sub consumers.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is already covered by existing tests, such as

  • org.apache.pulsar.client.api.PartitionedProducerConsumerTest#testPauseAndResume
  • org.apache.pulsar.client.api.SimpleProducerConsumerTest#testPauseAndResume
  • org.apache.pulsar.client.impl.ZeroQueueSizeTest#testPauseAndResume

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (no)
  • The schema: (no)
  • The default values of configurations: (no)
  • The wire protocol: (no)
  • The rest endpoints: (no)
  • The admin cli options: (no)
  • Anything that affects deployment: (no)

Documentation

Check the box below and label this PR (if you have committer privilege).

Need to update docs?

  • no-need-doc

Internal optimization.

@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Mar 5, 2022
@Jason918

Jason918 commented Mar 6, 2022

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

2 similar comments
@Jason918

Jason918 commented Mar 7, 2022

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@Jason918

Jason918 commented Mar 7, 2022

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, is it able to add a test?

@codelipenghui codelipenghui added this to the 2.11.0 milestone Mar 15, 2022
@aloyszhang

aloyszhang commented Mar 15, 2022 •

Copy link
Copy Markdown
Contributor

@Jason918
After creating a new ConsumerImpl for a topic partition, before sending FLOW command, client will check

if (!(firstTimeConnect && hasParentConsumer) && getCurrentReceiverQueueSize() != 0) {
                    increaseAvailablePermits(cnx, getCurrentReceiverQueueSize());
                }

hasParentConsumer is always true for multiTopicConsumer, so the new created ConsumerImpl will not send FLOW command to broker.

BTW, #11974 introduce startPaused for creating new ConsumerImpl, so this pull request is a nice optimize for me.

Left a comment, PTAL.

@Jason918

Copy link
Copy Markdown
Contributor Author

After creating a new ConsumerImpl for a topic partition, before sending FLOW command, client will check

if (!(firstTimeConnect && hasParentConsumer) && getCurrentReceiverQueueSize() != 0) {
                    increaseAvailablePermits(cnx, getCurrentReceiverQueueSize());
                }

hasParentConsumer is always true for multiTopicConsumer, so the new created ConsumerImpl will not send FLOW command to broker.

Great point. I have updated the motivation description.

@Jason918
Jason918 merged commit a32edc7 into apache:master Mar 23, 2022
Nicklee007 pushed a commit to Nicklee007/pulsar that referenced this pull request Apr 20, 2022
congbobo184 pushed a commit that referenced this pull request Nov 26, 2022
(cherry picked from commit a32edc7)
@congbobo184 congbobo184 added cherry-picked/branch-2.9 Archived: 2.9 is end of life release/2.9.4 labels Nov 26, 2022
liangyepianzhou pushed a commit that referenced this pull request Jun 29, 2023
(cherry picked from commit a32edc7)
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Jul 3, 2023
(cherry picked from commit a32edc7)
(cherry picked from commit 90369a0)
@lhotari

lhotari commented Nov 21, 2025

Copy link
Copy Markdown
Member

This seems to make the client behave in the wrong way for multi-topic consumer. Before this change, the client would first subscribe to all topics and then send flow permits to the broker in the startReceivingMessages method.
The behavior change is that messages will start flowing from the broker to the client immediately. If subscribing to any of the partitions fails, it will add a lot of extra work to the system and could cause cascading failures when brokers are at their limits. It's better to fix this problem and remove the newConsumer.resume(); lines added in this PR.

@lhotari

lhotari commented Nov 21, 2025

Copy link
Copy Markdown
Member

I created #25005 as a bug

@lhotari

lhotari commented Nov 21, 2025

Copy link
Copy Markdown
Member

It wasn't a bug after all, created a PR to cleanup the code instead, #25009

void-ptr974 added a commit to void-ptr974/pulsar that referenced this pull request Oct 24, 2026
Remove the optional jcstress harness, dependencies and build tasks. Explain
why pause-state reconciliation is necessary and how initial FLOW ordering
is preserved, with references to apache#14566 and apache#25009.

Assisted-by: Codex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants