Repository navigation
Fix memory tracking drift from background schedule pool and executor - #84946
Conversation
It has been reported (and I also noticed it few months ago) that it is possible to see negative MemoryTracking metric, while this should never be possible after bunch of fixes. It is not big, ~100MiB per 1 hour, but it still annoying. But, huge thread pools, that reserve all threads at start may lead to this, since each of them will have a drift up to 4MiB (it is not depends on the `max_untracked_memory`, since we do not apply it for all threads at start). And indeed I've tested this and with background_schedule_pool_size=10000, and I see that MemoryTracking can goes down, while after this patch it is almost constant. **And I hope this is the final bits of memory tracking drift!** Fixes: ClickHouse#82036
|
Workflow [PR], commit [cc1606d] Summary: ❌
|
|
I am going to backport this change |
…hedule pool and executor
…hedule pool and executor
Backport #84946 to 25.7: Fix memory tracking drift from background schedule pool and executor
antonio2368
left a comment
There was a problem hiding this comment.
Good catch but I'm trying to understand this completely.
From what I got, we could leave unflushed untracked_memory and because at the end of BackgroundSchedulePool task we mostly deallocate, it will often go negative. But either way we would leave untracked memory for unspecified amount of time if the thread is idle.
Why don't we do it inside ThreadPool also?
And why isn't it connected to max_untracked_memory?
Not exactly, I saw ~1KiB allocated (positive
Yes, and this problem is bigger if you have bigger pools, since right now random threads will be used to execute job.
We
Because we apply it only on a query level, this is an open question should be do this globally that I'm considering, but we should patches for memory tracking simpler IMHO to avoid possible regressions (or if any revert only relevant part). |
Backport #84946 to 25.6: Fix memory tracking drift from background schedule pool and executor
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix memory tracking drift from background schedule pool and executor
It has been reported (and I also noticed it few months ago) that it is possible to see negative MemoryTracking metric, while this should never be possible after bunch of fixes. It is not big, ~100MiB per 1 hour, but it still annoying.
But, huge thread pools, that reserve all threads at start may lead to this, since each of them will have a drift up to 4MiB (it is not depends on the
max_untracked_memory, since we do not apply it for all threads at start).And indeed I've tested this and with
background_schedule_pool_size=10000, and I see that MemoryTracking can go down, while after this patch, it is almost constant.
And I hope this is the final bits of memory tracking drift!
Note: workaround to mitigate this drift is to decrease background pool sizes, i.e.
background_schedule_pool_size=10, but this is not recommended for production usagescreenshots
memory-tracking-before-docker-vanilla
memory-tracking-before-patch-10k-1h
memory-tracking-after-patch-10k-2h
Fixes: #82036
Cc: @filimonov