Skip to content

Optimized ConsumerOffsetManager for Faster Topic & Group Lookups#9251

Closed
DivyanshIITB wants to merge 2 commits intoapache:developfrom
DivyanshIITB:fix/optimize-consumer-offset
Closed

Optimized ConsumerOffsetManager for Faster Topic & Group Lookups#9251
DivyanshIITB wants to merge 2 commits intoapache:developfrom
DivyanshIITB:fix/optimize-consumer-offset

Conversation

@DivyanshIITB
Copy link
Copy Markdown
Contributor

This PR enhances the performance of ConsumerOffsetManager by reducing unnecessary iterations and optimizing key lookups in offset-related methods.

Key Optimizations :

  1. Faster Lookups
  • Replaced O(N) iterations in whichTopicByConsumer() and whichGroupByTopic() with O(1) HashMap lookups using precomputed mappings (groupToTopics & topicToGroups).
  1. Efficient Cleanup Methods
  • cleanOffset() and cleanOffsetByTopic() now use temporary HashSets to track keys to remove, preventing concurrent modification issues.
  • Eliminated incorrect matches caused by contains() checks.

3)Optimized Offset Scanning

  • scanUnsubscribedTopic() avoids unnecessary split() calls and uses bulk removal instead of modifying offsetTable inside the loop.

4)Maintains Offset-Topic Consistency

  • Added updateOffsetTable() to ensure groupToTopics & topicToGroups mappings stay in sync with offsetTable.

This results in faster topic-group lookups, reduced memory overhead, and improved efficiency when managing consumer offsets.

Fixes #9240

@DivyanshIITB
Copy link
Copy Markdown
Contributor Author

Just a gentle reminder

@lizhimins lizhimins marked this pull request as draft March 20, 2025 06:03
@lizhimins
Copy link
Copy Markdown
Member

Need to pass all test cases first

@DivyanshIITB
Copy link
Copy Markdown
Contributor Author

I have made the necessary changes.
@lizhimins

@lizhimins lizhimins marked this pull request as ready for review March 25, 2025 09:21
@lizhimins
Copy link
Copy Markdown
Member

You can trigger the test by rebasing master.

@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open for 365 days with no activity. It will be closed in 3 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this PR.

@github-actions github-actions Bot added the stale label Mar 26, 2026
@github-actions
Copy link
Copy Markdown

This PR was closed because it has been inactive for 3 days since being marked as stale.

@github-actions github-actions Bot closed this Mar 29, 2026
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.

[Enhancement] Improving Broker Performance: Optimizing the whichTopicByConsumer Method Query Efficiency

2 participants