[improve][broker] Trace the asynchronous tasks in logs when loading topics#26163
Conversation
0cf2bee to
7ed63b7
Compare
void-ptr974
left a comment
There was a problem hiding this comment.
Thanks for the improvement! The additional timing details should help with understanding topic-loading latency. I left a couple of minor comments.
|
Hi, @Denovo1998 @void-ptr974 I've addressed your comments in latest commit with a few improvements, PTAL.
|
Denovo1998
left a comment
There was a problem hiding this comment.
Perhaps the implementation can be simpler?
Each time a log or metric needs to be output, call snapshot() once, take the current time as endNs within it, collect only the checkpoints not later than endNs, and then return an immutable LatencySnapshot. Both logs and metrics take values from the same snapshot.
This approach eliminates the need for intermediate states like -1/-2, and reading latency will not inadvertently permanently end the tracer. Even if timeout logs have been printed, the background topic loading can still continue to record subsequent stages.
Additionally, currently, when a timeout occurs, incomplete stages only show something like done: 29999 ms. It's not clear from the logs whether the actual stall is in the system topic, open-ml, or another future. Since the main goal of this PR is to identify which specific stage is consuming time, it's best to record the current action when a future starts and record the end upon completion. This way, the timeout logs can directly indicate at which step the process is stuck.
|
I agree that freezing the end time in |
|
@Denovo1998 I pushed a new commit, which unifies the rule of logging when topic loading fails.
|
Denovo1998
left a comment
There was a problem hiding this comment.
LGTM!
The remaining concerns are limited to diagnostic reliability rather than topical correctness.
|
@void-ptr974 I've used this tracer to follow managed ledger initialization. Because I found after switching to metadata store based topic policies (see PIP-469), the topic loading latency could still be high (1 second or more). The most time consuming part is the managed ledger initialization, where most parts should be ZooKeeper write paths. |
Motivation
The topic loading time could be high with pressure, but it's hard to measure which sub-task takes the most time. This is a follow-up work of #24785 to improve the logs that show topic loading latency.
Modifications
Add a simple tracing class
LatencyTracerand trace asynchronous futures during topic loading. When tracing a future, if the future is already done, skip tracing it because such tasks are usually not CPU-bounded.Verifying this change
LatencyTracerTestcovers functionality of all public methods with injected timestamps. The topic loading logs can be checked by runningtestConcurrentLoadTopicExceedLimitShouldNotBeAutoCreated:Out of scope
In my previous tests, opening managed ledger could also take much time, this
LatencyTracerclass can be used to track managed ledger open process as well.