add batch topic partition offset fetch to reduce the API calls#516
Open
Otiss-pang wants to merge 1 commit intodanielqsj:masterfrom
Open
add batch topic partition offset fetch to reduce the API calls#516Otiss-pang wants to merge 1 commit intodanielqsj:masterfrom
Otiss-pang wants to merge 1 commit intodanielqsj:masterfrom
Conversation
Author
|
@danielqsj could checking this merge when free? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Performance Optimization: Batch Offset Fetching and Negative Lag Handling
Summary
Optimizes kafka_exporter performance by implementing batch offset fetching and proper negative lag handling.
Motivation
The current implementation fetches topic partition offsets one by one, resulting in excessive API calls to Kafka brokers. Additionally, negative lag values can occur when topic offsets update between fetching topic offsets and consumer group offsets, leading to inaccurate metrics.
Key Changes
1. Batch Offset Fetching
e.client.GetOffset()for each partitionbroker.GetAvailableOffsets()2. Three-Phase Collection Strategy
Phase 1: Topic Offset Collection
topicPartitionLeadersmapping for Phase 3Phase 2: Consumer Group Metrics Collection
Phase 3: Negative Lag Resolution
3. Code Improvements
deferredGroupTaskstruct for deferred processingemitGroupMetric(): Handles offset fetching and negative lag detectionreportGroupMetrics(): Unified metric emissionsync.RWMutexfor safe concurrent accessBenefits
Performance
Accuracy
Backward Compatibility
Performance Testing
Example improvements on a cluster with 1k+ topics and 12k+ partitions: