Skip to content

[improve][client] Add independent multiTopicsSinglePartitionReceiverQueueSize config for single partition consumer in multi-topics consumer to reduce memory consumption#7

Open
oneby-wang wants to merge 5 commits into
masterfrom
multi_topics_consumer_receiver_queue_size
Open

[improve][client] Add independent multiTopicsSinglePartitionReceiverQueueSize config for single partition consumer in multi-topics consumer to reduce memory consumption#7
oneby-wang wants to merge 5 commits into
masterfrom
multi_topics_consumer_receiver_queue_size

Conversation

@oneby-wang

@oneby-wang oneby-wang commented Oct 17, 2025

Copy link
Copy Markdown
Owner

Motivation

There no independent receiverQueueSize config for single partition consumer in MultiTopicsConsumerImpl and PatternMultiTopicsConsumerImpl. Although maxTotalReceiverQueueSizeAcrossPartitions config can limit in-memory messages of a single topic with multi-partitions, but it can't limit in-memory messages of multi-topics.

For example, if we subscribe to a regex pattern that matches 1000 non-partitioned topics. Before this PR, each non-partitioned topic consumer's receiverQueueSize is 1000(ConsumerImpl uses the same receiverQueueSize value as PatternMultiTopicsConsumerImpl), the max messages in memory is 1000 + 1000 * 1000 = 1001000. Let's ignore the insignificant number 1000, if each message size is 8Kb, then we need 1000000 * 8Kb = 7,812.5MB memory to boot our application in catch-up read situation, which is unnecessary.

https://github.com/apache/pulsar/blob/e6560657e20d30103f2f01c3a24600dad1ba9ab6/pulsar-client/src/main/java/org/apache/pulsar/client/impl/MultiTopicsConsumerImpl.java#L236-L249

For backward compatibility, add multiTopicsSinglePartitionReceiverQueueSizeEnable switch, the default value is set to false.

Modifications

Add independent multiTopicsSinglePartitionReceiverQueueSize config for single consumer in MultiTopicsConsumerImpl to reduce memory consumption.

Verifying this change

  • Make sure that the change passes the CI checks.

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

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

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

Matching PR in forked repository

PR in forked repository:

@oneby-wang oneby-wang changed the title [improve][client] add independent multiTopicsSingleConsumerReceiverQueueSize config for single consumer in MultiTopicsConsumerImpl to reduce memory consumption [improve][client] add independent multiTopicsSinglePartitionReceiverQueueSize config for single consumer in MultiTopicsConsumerImpl to reduce memory consumption Oct 17, 2025
@oneby-wang oneby-wang changed the title [improve][client] add independent multiTopicsSinglePartitionReceiverQueueSize config for single consumer in MultiTopicsConsumerImpl to reduce memory consumption [improve][client] add independent multiTopicsSinglePartitionReceiverQueueSize config for single partition consumer in multi-topics consumer to reduce memory consumption Oct 17, 2025
@oneby-wang oneby-wang changed the title [improve][client] add independent multiTopicsSinglePartitionReceiverQueueSize config for single partition consumer in multi-topics consumer to reduce memory consumption [improve][client] Add independent multiTopicsSinglePartitionReceiverQueueSize config for single partition consumer in multi-topics consumer to reduce memory consumption Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant