Skip to content

FixedHashTable for Key8/Key16 support parallel merge. - #63667

Closed
ucasfl wants to merge 19 commits into
ClickHouse:masterfrom
ucasfl:k16-two-level-hash
Closed

ucasfl wants to merge 19 commits into
ClickHouse:masterfrom
ucasfl:k16-two-level-hash

Conversation

@ucasfl

@ucasfl ucasfl commented May 12, 2024 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

FixedHashTable(Key8/Key16) supports parallel merge in aggregation. Closes #63666.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

Modify your CI run

NOTE: If your merge the PR with modified CI you MUST KNOW what you are doing
NOTE: Checked options will be applied if set before CI RunConfig/PrepareRunConfig step

Include tests (required builds will be added automatically):

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Unit tests
  • Performance tests
  • All with ASAN
  • All with TSAN
  • All with Analyzer
  • All with Azure
  • Add your option here

Exclude tests:

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Performance tests
  • All with ASAN
  • All with TSAN
  • All with MSAN
  • All with UBSAN
  • All with Coverage
  • All with Aarch64
  • Add your option here

Extra options:

  • do not test (only style check)
  • disable merge-commit (no merge from master before tests)
  • disable CI cache (job reuse)

Only specified batches in multi-batch jobs:

  • 1
  • 2
  • 3
  • 4
Details

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-improvement Pull request with some product improvements label May 12, 2024
@robot-clickhouse-ci-2

robot-clickhouse-ci-2 commented May 12, 2024 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit 794ce63 with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Check nameDescriptionStatus
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests❌ failure
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc❌ failure
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors❌ failure
Successful checks
Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integration tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label May 12, 2024
@robot-ch-test-poll4 robot-ch-test-poll4 added pr-performance Pull request with some performance improvements and removed pr-improvement Pull request with some product improvements labels May 12, 2024
@alexey-milovidov

Copy link
Copy Markdown
Member

This looks good!

But it is in question whether we should give up a fixed layout and do a costly conversion to two-level?
I thought about these options:

  1. Even without conversion two-level, we can merge FixedHashMap in parallel. This even makes sense for key8.
  2. Alternatively, we can make the UInt16 hash table two-level by default, where each level is 8 bits.

@nickitat nickitat self-assigned this May 12, 2024
@JackyWoo

Copy link
Copy Markdown
Contributor

hi, I found for simplest aggregation functions such as count, parellel merging may lead performance degredation. I wonder whether we should consider the overload of the aggregation function when we do the conversion. @alexey-milovidov @ucasfl @nickitat

parellel merging

SELECT
    0 + (number % 100000) AS k,
    count(number) AS u
FROM numbers_mt(100000000)
GROUP BY k
ORDER BY u DESC
LIMIT 10

10 rows in set. Elapsed: 0.101 sec. Processed 100.00 million rows, 800.00 MB (986.00 million rows/s., 7.89 GB/s.)

single thread merging

SELECT
    number % 100000 AS k,
    count(number) AS u
FROM numbers_mt(100000000)
GROUP BY k
ORDER BY u DESC
LIMIT 10

10 rows in set. Elapsed: 0.084 sec. Processed 100.00 million rows, 800.00 MB (1.19 billion rows/s., 9.53 GB/s.)

@alexey-milovidov

Copy link
Copy Markdown
Member

@JackyWoo the solution is not to do any conversion at all, but have the data structure mergeable in parallel as is.

@nickitat

Copy link
Copy Markdown
Member

I agree that convertible structure doesn't make a lot of sense for fixed size table.

@alexey-milovidov

Copy link
Copy Markdown
Member

@ucasfl Let's try another way?

@ucasfl
ucasfl marked this pull request as draft June 17, 2024 11:08
@ucasfl
ucasfl marked this pull request as ready for review July 19, 2024 08:36
@ucasfl ucasfl changed the title Key16 support Two-Level Hash aggregation. FixedHashTable for Key8/Key16 support parallel merge. Jul 19, 2024
@ucasfl
ucasfl requested a review from nickitat July 23, 2024 11:56
@ucasfl
ucasfl requested a review from alexey-milovidov July 24, 2024 10:45
@nickitat

Copy link
Copy Markdown
Member

pls review perf test results

@clickhouse-gh

clickhouse-gh Bot commented Sep 3, 2024

Copy link
Copy Markdown
Contributor

Dear @nickitat, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@qoega

qoega commented Mar 1, 2025

Copy link
Copy Markdown
Member

Let's change changelog category to performance, fix conflicts and rerun CI to get full performance check results?

@clickhouse-gh

clickhouse-gh Bot commented Mar 3, 2025

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4596b69]

@nickitat nickitat self-assigned this Mar 4, 2025
@nickitat

nickitat commented Mar 4, 2025

Copy link
Copy Markdown
Member

A couple of suggestions:

  1. we're better off disabling MinMaxOptimization than adding a mutex in the hash table.
  2. I imagine this logic working similarly to normal merging for two-level tables: we create the same merging processors in the pipeline (i.e., don't allocate threads on a thread pool - it is not a good design). Instead of buckets of two-level tables, we merge "buckets" that are actually the original tables, but each thread also has its own filter for the keys it is assigned to merge.

As to a threshold for enabling this versus single-threaded merging - let's settle down on the implementation first and then see what perf tests suggest (including the query provided by JackyWoo@).

@qoega

qoega commented Mar 5, 2025

Copy link
Copy Markdown
Member

And check out degradations as well...
Screenshot 2025-03-05 at 19 10 58

@clickhouse-gh

clickhouse-gh Bot commented Apr 8, 2025

Copy link
Copy Markdown
Contributor

Dear @nickitat, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@alexey-milovidov

Copy link
Copy Markdown
Member

It does not sound too complicated, but the amount of benefits is huge.

@incfly

incfly commented Sep 20, 2025 •

Copy link
Copy Markdown
Contributor

Seeing the PR being here for a while, so I tried to work on this a bit. Roughly following nickitat's suggestion here, #63667 (comment)

we create the same merging processors in the pipeline

My understanding is this needs to create another ISource for ConvertingAggregatedToChunksTransform when condition meets. And adding some method to FixedHashMap to merge via index filtering without locking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

key16 aggregation method should be two level

8 participants