Yida Wu has uploaded this change for review. ( https://gerrit.cloudera.org/25405
Change subject: IMPALA-15758: Allow early flushes in streaming preaggregations
......................................................................
IMPALA-15758: Allow early flushes in streaming preaggregations
A streaming preaggregation with several grouping sets or distinct
aggregations has one Aggregator for each of them, and they take memory
first come, first served. A low reduction Aggregator keeps adding new
groups, so it can take most of the memory early. A high reduction one
then cannot grow its hash tables and passes its rows through, although
most of them would have matched an existing group.
With the new PREAGG_FLUSH query option, true by default, an Aggregator
(the victim) can flush before its input is done:
- Flush: the victim returns its groups as partial aggregates, like the
rows passed through, so the results don't change. Then it restarts
with empty hash tables.
- Destination: the reservation that the flush frees goes directly to
the destination of the flush, if it has one, and is not released to
the fragment instance, where another operator could take it. A victim
that gave its reservation away doesn't grow its hash tables anymore.
It aggregates the rows that fit and passes the rest through. Without
a destination, the victim keeps its reservation.
The flush doesn't depend on what triggers it, so other triggers can be
added later. This patch adds one for a starved Aggregator, one that
ran out of memory, which becomes the destination:
- When: a window starts when the first Aggregator is starved.
A flush starts once the rows that it passed through in the window,
times its share of rows that hit an existing group, exceed the rows
that the victim absorbed in the window.
- Victim: it must hold at least one buffer above its minimum
reservation. With chained grouping sets (IMPALA-13081), the one
closest to the head of the chain. Each grouping set is a subset of
the previous one, so the head has the most groups, reduces its rows
the least and holds the most memory. Its flushed rows pass through
the rest of the chain to the destination. Otherwise the one that
absorbed the fewest rows in the window.
This trigger only acts when memory is short. With enough memory, no
Aggregator is starved and nothing is flushed. Once one is starved, it
aggressively takes the memory it needs from an Aggregator that reduces
its rows little. The victim reduced its rows little anyway, while the
destination turns many rows into few groups, so fewer rows are passed
through in total. The new profile counters NumFlushes, RowsFlushed and
FlushReservationReceived show the flushes.
Testing:
- Added e2e tests that compare the results with flushes to queries
without grouping sets, and check that the flushes happen and hand
over reservation at low memory, but not with enough memory.
- Added an e2e test that the flush is disabled if the preaggregation
has a non-grouping Aggregator.
Performance:
The queries run with memory short, so without the flush the low
reduction Aggregators hold the memory while the high reduction ones
pass many rows through: Q1 and Q2 are TPC-DS SF10 q67, a ROLLUP over
8 columns, at mem_limit=350m with and without chaining, and Q3 is three
count(distinct) over TPC-H lineitem at mem_limit=90m.
Measured with 3 impalads on a release build (64k spillable buffers,
median of 5 runs, PREAGG_FLUSH=false (NoFlush) vs true (Flush)):
Rows passed through Query time
per instance
NoFlush/Flush NoFlush/Flush
Q1 2.50M/1.38M (-45%) 35.4s/26.4s (-25%)
Q2 1.87M/1.50M (-20%) 32.1s/29.6s (-8%)
Q3 3.22M/2.05M (-36%) 4.3s/3.3s (-23%)
With fewer rows passed through, the exchange and the merge aggregation
do less work. Q1 gains the most because with chaining the victim's
flushed rows also feed the destination.
Change-Id: I26e2a882c1831fcc903a39a3420dc09d79a318f8
Assisted-by: Claude Opus 5.5 (Claude Code)
---
M be/src/exec/grouping-aggregator.cc
M be/src/exec/grouping-aggregator.h
M be/src/exec/streaming-aggregation-node.cc
M be/src/exec/streaming-aggregation-node.h
M be/src/service/query-options.cc
M be/src/service/query-options.h
M common/thrift/ImpalaService.thrift
M common/thrift/Query.thrift
M tests/query_test/test_aggregation.py
9 files changed, 484 insertions(+), 8 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/05/25405/1
--
To view, visit https://gerrit.cloudera.org/25405
To unsubscribe, visit https://gerrit.cloudera.org/settings
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I26e2a882c1831fcc903a39a3420dc09d79a318f8
Gerrit-Change-Number: 25405
Gerrit-PatchSet: 1
Gerrit-Owner: Yida Wu <[email protected]>