Repository navigation
Add processor memory allocated and freed columns to processors profile log - #106263
alexandrefimov wants to merge 10 commits into
Conversation
|
Workflow [PR], commit [82adf86] Summary: ❌
AI ReviewSummaryThis PR adds Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit 82adf86.
Changed lines: Changed C/C++ lines covered: 66/67 (98.51%) · Uncovered code |
|
I looked through the two failed jobs on this run and they look unrelated to this PR.
I did not find sanitizer reports or stack traces involving the changed processor/profile-log code ( |
Fgrtue
left a comment
There was a problem hiding this comment.
Hi @alexandrefimov , thank you for contribution. It seems that RFC requires a different way of tracking memory. With these deltas we track something else instead of allocated/freed memory in a processor.
|
Thanks, I agree. The previous version measured the current memory before/after I updated the patch to use the RFC-style direction: |
|
Public CI is green on 5e46d23, but |
|
@Fgrtue, could you please rerun failed check?) |
|
@alexandrefimov I checked the CI, this is some internal testing and it is not related to your changes. I will take a look at them. |
|
Thanks! |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 84/84 (100.00%) · Uncovered code |
|
Dear @Fgrtue, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
@alexey-milovidov, the implementation now follows the RFC direction and the previous review thread is resolved. Since the previous reviewer was unassigned due to inactivity, could you please suggest another reviewer or take a look when convenient? CI status for clarity: CH Inc sync is green, but the overall public PR CI is still red. The three primary failures appear unrelated to this change: amd_asan_ubsan failed a hung/deadlock check, amd_tsan hit an or_argument_nodes.size() > 1 assertion, and the performance shard completed its tests successfully but failed while building the report. A rerun of the failed checks should be sufficient. |
|
@Fgrtue, you previously confirmed that the failing CI was unrelated to this change and planned to review it, but the inactivity bot has since unassigned you. Would you be able to continue the review, or suggest another appropriate reviewer? Thanks! |
Fgrtue
left a comment
There was a problem hiding this comment.
Hi @alexandrefimov, sorry for late response. Its unpleasant to say, but after internal discussion we are still in doubt about the details of implementation for memory tracking. The current infrastructure is a bit clumsy regarding the memory tracking per processor and some work is currently going on to improve it. Since the current implementation uses the only possible methods that are available, we are hesitant to add it, because it might be confusing for the users. The reason is that most of the memory is allocated during Reading, and then freed further in the pipeline. This might make most of the processors have negative memory delta, and at the same time that still won't allow to track real issues like OOM during Hash Table built in Joins.
Anyways, during the week I will take a look at the code, and try to test it on real life queries that cause high memory consumption. Then I'll discuss with the collegues if this approach of memory tracking gives more pros than cons and will be useful for our users.
Sorry again for the wait, it was a few busy months, so I did not have a proper chance to get back to this PR.
|
Thanks for the update. Your point about allocations and frees happening in different processors is fair. If the net delta turns out to be misleading on real queries, we could record allocated and freed bytes separately. That would show allocation/free activity while each processor was running without implying that the processor owns the memory. It still would not solve retained-memory or OOM attribution. Let’s see what the real-query tests show before changing the patch. |
`master` moved the documentation from the Docusaurus tree under `docs/en/**/*.md` to the Mintlify tree at `docs/**/*.mdx`, deleting every file this branch edits. The edits are replayed at the new paths: - `docs/en/operations/system-tables/processors_profile_log.md` -> `docs/reference/system-tables/processors_profile_log.mdx`
|
Hi @Fgrtue, following up on the real-query tests you mentioned. Did they show whether the signed per-processor delta is useful, or whether allocation and freeing in different processors makes it too misleading? If the current direction is not acceptable, a short conclusion on whether to close this PR or what measurement would be meaningful would help me avoid pushing the wrong model. Thanks! |
|
Rather than ask a third time, let me put a plan on it. The patch records a signed net delta per processor. Your point on Aug 3 was that allocations and frees land in different processors, which can make that misleading, and that the per-processor memory tracking infrastructure is being reworked anyway. If that is where things stand, this PR is not useful to anyone sitting open against infrastructure that is about to change. So unless you would rather keep it, I will close it at the end of the week. The analysis stays in the thread, and I am glad to redo it against the new infrastructure once it lands — either as the signed delta or as allocated and freed recorded separately, whichever turns out to measure something real. |
|
Dear @Fgrtue, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
Hi @alexandrefimov. Sorry for the wait, I was PTO. Here are the result of the testing: I did the testing using TPC-H scale 30 and ClickBench 100 million rows on machine with 32 cores, 61 GB RAM.
When spilling is turned on, the aggregation's figure collapses as it should, and the new top
The third is
What happened in each case:
So a negative number has two possible meanings. In case 2 it means "this processor released
Query peak: 2.58 GiB.
All 32 The aggregation holds ~850 MiB of group states. It is reported as the single biggest memory Anyone triaging an OOM in this query reads that row and concludes the aggregation is not the
12 of 16 land in 0.05–1.2 × peak and name a sensible operator. The 4 outliers are all Across all 16 queries: 103 processor/query rows positive, 52 negative, 67 exactly zero. A |
Fgrtue
left a comment
There was a problem hiding this comment.
For the implementation, we want the smallest possible change the following approach:
-
Two columns instead of one. Replace
memory_usage_deltawithmemory_allocated_bytesandmemory_freed_bytes(UInt64) inIProcessor,ProcessorsProfileLogInfo, the log element, the table columns and
the docs. Users can compute the difference themselves. -
Two plain counters in
ThreadStatus. Add twoUInt64fields next tountracked_memorythat only grow. InCurrentMemoryTracker::allocImplandCurrentMemoryTracker::free, addsizeto the matching field
after the tracker call has succeeded. Keep the current rule: allocations blocked atVariableContext::Processor lower are not counted. Removecurrent_processor_memory_usage_deltaand
addCurrentProcessorMemoryUsageDelta. The memory tracker must not know about processors. -
Snapshot in
executeTask. Do not changeexecuteJob. Read the two thread counters before the existingexecuteJobcall, and after it add the differences to the processor. Put this under the same
profile_processorscheck that already guardsexecution_time_watch. Please revert theexecuteJobrewrite, theProcessorMemoryUsageScopeclass, the new declaration in the header and the comment edits in
IProcessor.h. -
Tests. The functional test is the main one. Keep
max_untracked_memory = 0andmax_threads = 1. Check only that both columns are> 0for a processor that must allocate, such asAggregatingTransform. Do
not compare exact byte counts. The gtest can stay in a short form: check the two thread counters afterallocandfree, and check that aMemoryTrackerBlockerInThreadatProcesslevel does not change them. No
integration test is needed.
Replace `memory_usage_delta` in `system.processors_profile_log` with `memory_allocated_bytes` and `memory_freed_bytes`. A signed net value hides who owns the memory: a processor that frees what another one allocated shows up as the biggest releaser in the query. `ThreadStatus` now keeps two monotonic counters that `CurrentMemoryTracker` advances on alloc and free, and `ExecutionThreadContext::executeTask` takes their difference around `executeJob`. The memory tracker no longer knows about processors. Memory blocked at `VariableContext::Process` or lower is still not counted.
…ory' into query-doctor-70587-processor-memory # Conflicts: # docs/en/operations/system-tables/processors_profile_log.md # docs/reference/system-tables/processors_profile_log.mdx
`master` moved `ExecutionThreadContext` into `src/Processors/Executors/Runtime/` and pulled `ProcessorsProfileLogInfo` out of `IProcessor.h`, so the change is replayed at the new locations. The documentation edit is dropped. The column list in `docs/reference/system-tables/processors_profile_log.mdx` sits between `AUTOGENERATED_START` and `AUTOGENERATED_END`, and `check_autogenerated_regions` rejects direct edits there without the `pr-autogenerated-docs` label. The column descriptions in `ProcessorsProfileLog.cpp` are what that region is generated from.
|
Done, all four points. Master is merged in, so the conflicts are gone. Two things differ from what you described:
|
A processor that runs an inner pipeline through `PullingAsyncPipelineExecutor` allocates on a thread from the global pool, and that pipeline never reaches `logProcessorProfile`, so none of its memory lands in any row.
|
The two columns miss processors that run an inner pipeline through The limitation is now in the column descriptions in |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1231 translation units recompiled, 7722 s compile time in total, 1231 of them have a recent master baseline. |
Fgrtue
left a comment
There was a problem hiding this comment.
LGTM, I will ask another colleague to take a look in order to make sure that this won't affect other work on memory tracking.
allocated and freed columns to processors profile log
Thanks! |
azat
left a comment
There was a problem hiding this comment.
I also have concerns about introducing allocation throughput per processor, as it might add noise and confusion rather than actionable diagnostics.
Concerns/[Existing] Alternatives:
- Knowing which processor performed an allocation is usually not enough, typically need call stacks. We already have detailed profiling options for this, such as
Memory,MemorySample,JemallocSampleand others, but yes not all of this is enabled by default because it is more heavy (we can add processor information into trace_log btw) - Processors that actually consume significant memory (e.g., JOIN, Sort, Aggregating) already expose dedicated interfaces for tracked memory usage, and #119443 will extend this coverage to disk spilling
- Minor, but AFAICS, entries in
system.processors_profile_logare written only when a query finishes successfully. Queries that fail with MEMORY_LIMIT_EXCEEDED won't be captured here anyway, while those are the most interesting. - Regarding the original RFC #70587, likely it will require significant work and I am not sure that it worth implementing
Maybe you can describe some examples where this can be useful, and we can discuss, does it worth it or maybe there are better alternatives or some of existing introspection can cover them
P.S. sorry for the delay and that it took so many rounds
|
Thanks, fair points. I checked the third one: Tagging |
To add processor to trace_log? I am actually not sure that it will be useful either, I don't remember a case when I was needed this But what definitely make sense is to add entries for |
|
Makes sense. I'll close this one and open a new PR that logs |
|
Sure, feel free to ping me there. |
…exception Until now `processors_profile_log` was written only from the query finish path, so queries ending with `ExceptionWhileProcessing` (for example `MEMORY_LIMIT_EXCEPTION`) had no entries. `BlockIO::onException` now passes the pipeline, which is not reset yet, to the exception callbacks, and the callback from `executeQuery` logs its processors. `LocalConnection` kept its executors alive during `onException`, so their threads could still write the processors' counters. It now stops them first, as `finishQuery` does before `onFinish`. Related: ClickHouse#106263
Related: #70587
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added
memory_allocated_bytesandmemory_freed_bytestosystem.processors_profile_log, showing how much memory each processor allocated and freed while executing its work.ThreadStatuskeeps two monotonic counters thatCurrentMemoryTrackeradvances on allocation and free, andExecutionThreadContext::executeTasktakes their difference aroundexecuteJob. The columns exclude processor preparation, scheduling and destruction, and memory blocked atVariableContext::Processor lower is not counted.A single signed delta was the earlier shape of this change. It was replaced after testing on TPC-H and ClickBench showed a processor that frees what another one allocated coming out as the biggest memory releaser in the query, which reads as the opposite of what it is.
Workflow [PR]
Sync PR [sync-upstream/pr/106263]