Before Creating the Enhancement Request
Summary
LiteConsumerLagCalculator.getLagCountTopK currently calls getStoreTimestamp() (disk I/O) for every offset entry during full-table traversal, creates a LiteLagInfo object for each entry regardless of whether it enters the topK heap, and uses String.split() for key parsing. These cause unnecessary overhead when the offset table is large.
Motivation
In production with thousands of lite topics per group, the current implementation issues N getStoreTimestamp calls (each hitting the message store), allocates N intermediate objects, and performs N string splits — but only K (topK, typically small) results are actually needed. This wastes CPU and I/O, especially under periodic metric collection.
Describe the Solution You'd Like
- Defer
getStoreTimestamp to topK results only: Accumulate consumerOffset in LiteLagInfo during traversal, then compute timestamps for the final topK entries after heap filtering — reducing N expensive calls to K.
- Lazy object creation: Only instantiate
LiteLagInfo when the entry qualifies for heap insertion (size < topK || diff > peek), avoiding N-K wasted allocations.
- Replace
split() with indexOf(): Parse topicAtGroup key via indexOf + substring, avoiding array allocation; check lite prefix before any string extraction.
- Replace
AtomicLong with long[]: The traversal is single-threaded; atomic overhead is unnecessary.
Describe Alternatives You've Considered
- Caching store timestamps in memory: adds complexity and staleness risk without proportional benefit.
- Parallel timestamp lookup: over-engineering for a metric query that is already fast after deferral.
Additional Context
Files changed: LiteConsumerLagCalculator.java, LiteLagInfo.java.
Before Creating the Enhancement Request
Summary
LiteConsumerLagCalculator.getLagCountTopKcurrently callsgetStoreTimestamp()(disk I/O) for every offset entry during full-table traversal, creates aLiteLagInfoobject for each entry regardless of whether it enters the topK heap, and usesString.split()for key parsing. These cause unnecessary overhead when the offset table is large.Motivation
In production with thousands of lite topics per group, the current implementation issues N
getStoreTimestampcalls (each hitting the message store), allocates N intermediate objects, and performs N string splits — but only K (topK, typically small) results are actually needed. This wastes CPU and I/O, especially under periodic metric collection.Describe the Solution You'd Like
getStoreTimestampto topK results only: AccumulateconsumerOffsetinLiteLagInfoduring traversal, then compute timestamps for the final topK entries after heap filtering — reducing N expensive calls to K.LiteLagInfowhen the entry qualifies for heap insertion (size < topK || diff > peek), avoiding N-K wasted allocations.split()withindexOf(): ParsetopicAtGroupkey viaindexOf+substring, avoiding array allocation; check lite prefix before any string extraction.AtomicLongwithlong[]: The traversal is single-threaded; atomic overhead is unnecessary.Describe Alternatives You've Considered
Additional Context
Files changed:
LiteConsumerLagCalculator.java,LiteLagInfo.java.