Fix memory tracking for two-level GROUP BY when not all rows read from Aggregator (TCP)#11022
Conversation
alexey-milovidov
left a comment
There was a problem hiding this comment.
Ok. It fixes the memory tracking issue.
But I don't understand how it fixes the following issues:
- memory leak in the test for uniqState (or is there any memory leak?);
- memory usage that is higher than usual and sustained in about 6x the memory usage of query but with no leak.
Hm, I didn't look carefully at RSS/VIRT, indeed, this is a different issue (will drop fixes tag for the #8995)
This is about #10818 ? Ok, I've forgot to verify with multiple threads: # pwd is hits_100m_obfuscated_v1
docker run --name ch --rm -v $PWD:/var/lib/clickhouse -it yandex/clickhouse-server:20.4 gosu clickhouse:clickhouse clickhouse-server --config=/etc/clickhouse-server/config.xml -- --max_server_memory_usage=$((6<<30))
clickhouse-benchmark --host 172.17.0.2 --max_threads 16 <<< "select WatchID from hits_100m_obfuscated group by WatchID with totals limit 10"Up to this point it is ok. But if I will force more threads: clickhouse-client -q 'select count(*) from (select * from numbers_mt(1000000) settings max_threads=1000)'
clickhouse-benchmark --host 172.17.0.2 --max_threads 16 <<< "select WatchID from hits_100m_obfuscated group by WatchID with totals limit 10"RSS starts growing, indeed looks like memory allocator issues, but in the long-term lots of threads will be used by the aggregator and this issue will arise anyway, no? P.S. playing with jemalloc may helps there, i.e. any of the following may helps:
P.S. I also tried #10956 and now it will help for this issue, RSS is around 6-8GB |
Drop the patch with removing the test |
Can be fixed with some hack, but it will go away anyway after #11029 |
I can rebase against master to make tests green if you not on this right now? And one more questions from the big comment above:
do you still think that making thread pool more predictable instead of random thread get random job worth it? (with taking into account that #10956 may helps in some cases) |
|
@alexey-milovidov also what do you think about enabling |
|
@azat Let's test all three variants. |
Agree P.S. But I don't think that
Ok (although I don't like PR storm :) )
If I did not messed up during testing again, then all three - helps |
|
And what about this PR?
|
…m Aggregator (TCP)
Example of such cases:
- SELECT GROUP BY LIMIT
- SELECT GROUP BY with subsequent MEMORY_LIMIT_EXCEEDED error
And it should be two-level aggregation, since otherwise there will be
only one hashtable which will be cleared correctly, only if you have
two-level GROUP BY some of hashtables will not be cleared since nobody
consume rows.
Before this patch:
09:39.015292 [ 3070801 ] {609a0610-e377-4132-9cf3-f49454cf3c96} <Information> executeQuery: Read 1000000 rows, 7.63 MiB in 0.707 sec., 1413826 rows/sec., 10.79 MiB/sec.
09:39.015348 [ 3070801 ] {609a0610-e377-4132-9cf3-f49454cf3c96} <Debug> MemoryTracker: Peak memory usage (for query): 51.93 MiB.
09:39.015942 [ 3070801 ] {} <Trace> Aggregator: Destroying aggregate states <-- **problem**
09:39.017057 [ 3070801 ] {} <Trace> Aggregator: Destroying aggregate states <--
09:39.017961 [ 3070801 ] {} <Debug> MemoryTracker: Peak memory usage (for query): 51.93 MiB.
09:39.018029 [ 3070801 ] {} <Information> TCPHandler: Processed in 0.711 sec.
After this patch:
16:24.544030 [ 3087333 ] {79da208a-b3c0-48d4-9943-c974a3cbb6ea} <Information> executeQuery: Read 1000000 rows, 7.63 MiB in 0.599 sec., 1670199 rows/sec., 12.74 MiB/sec.
16:24.544084 [ 3087333 ] {79da208a-b3c0-48d4-9943-c974a3cbb6ea} <Debug> MemoryTracker: Peak memory usage (for query): 72.11 MiB.
16:24.544398 [ 3087333 ] {79da208a-b3c0-48d4-9943-c974a3cbb6ea} <Trace> Aggregator: Destroying aggregate states
16:24.545485 [ 3087333 ] {79da208a-b3c0-48d4-9943-c974a3cbb6ea} <Trace> Aggregator: Destroying aggregate states
16:24.547053 [ 3087333 ] {} <Debug> MemoryTracker: Peak memory usage (for query): 72.11 MiB.
16:24.547093 [ 3087333 ] {} <Information> TCPHandler: Processed in 0.603 sec.
- GROUP BY - GROUP BY LIMIT - GROUP BY MEMORY_LIMIT_EXCEEDED
|
Rebased, previous HEAD was 47965fbf5cf2edbdb13c3fd31caceef0cb246ac5 |
|
First for me is to fix unrelated integration test failure... then proceed with PRs. |
While rewriting the test in ClickHouse#11119 it looses LIMIT, which makes the test useless, see details in ClickHouse#11022 Signed-off-by: Azat Khuzhin <[email protected]>
* tests: fix 01281_group_by_limit_memory_tracking flakiness CI: https://s3.amazonaws.com/clickhouse-test-reports/41092/14d8f297d73f9f813c447474310fbfa0c5b18a0f/stateless_tests__debug__[2/3].html Signed-off-by: Azat Khuzhin <[email protected]> * tests: add missing bits into 01281_group_by_limit_memory_tracking While rewriting the test in #11119 it looses LIMIT, which makes the test useless, see details in #11022 Signed-off-by: Azat Khuzhin <[email protected]> Signed-off-by: Azat Khuzhin <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix memory tracking for two-level GROUP BY when not all rows read from Aggregator (TCP)
Detailed description / Documentation draft:
Example of such cases:
And it should be two-level aggregation, since otherwise there will be
only one hashtable which will be cleared correctly, only if you have
two-level GROUP BY some of hashtables will not be cleared since nobody
consume rows.
Before this patch:
After this patch: