Skip to content

New parallel replicas coordinator implementation - #57968

Merged
nickitat merged 10 commits into
ClickHouse:masterfrom
nickitat:parallel_replicas_new_coordinator
Jan 3, 2024
Merged

nickitat merged 10 commits into
ClickHouse:masterfrom
nickitat:parallel_replicas_new_coordinator

Conversation

@nickitat

@nickitat nickitat commented Dec 17, 2023 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Performance Improvement

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

Default coordinator for parallel replicas is rewritten for better cache locality (same mark ranges are almost always assigned to the same replicas). Consistent hashing is used also during work stealing, so better tail latency is expected.
It has been tested for linear scalability on a hundred of replicas.

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-not-for-changelog This PR should not be mentioned in the changelog label Dec 17, 2023
@robot-clickhouse-ci-2

robot-clickhouse-ci-2 commented Dec 17, 2023 •

Copy link
Copy Markdown
Contributor

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

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

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
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker image for serversThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ 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. Integrational 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
Mergeable CheckChecks if all other necessary checks are successful✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
SQLTestThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
SQLancerFuzzing tests that detect logical bugs with SQLancer tool✅ success
SqllogicRun clickhouse on the sqllogic test set against sqlite and checks that all statements are passed✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stateless testsRuns stateless 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
Check nameDescriptionStatus
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors❌ failure
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❌ failure

@nickitat
nickitat force-pushed the parallel_replicas_new_coordinator branch 2 times, most recently from 13b24db to 8a918ce Compare December 21, 2023 17:05
@nickitat nickitat linked an issue Dec 21, 2023 that may be closed by this pull request
@nickitat nickitat changed the title Test new implementation New parallel replicas coordinator implementation Dec 25, 2023
@nickitat
nickitat requested a review from devcrafter December 25, 2023 16:13
@nickitat
nickitat marked this pull request as ready for review December 25, 2023 16:13
@nickitat
nickitat force-pushed the parallel_replicas_new_coordinator branch from 9306244 to 891357a Compare December 25, 2023 19:11
{
auto result = extension.callback(ParallelReadRequest(
CoordinationMode::Default,
coordination_mode,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the same but done differently. Not clear, what's the point?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initially I planned to choose between old and new based on settings. that is what's left from this code

/// Parts view from the first announcement we received
std::vector<Part> all_parts_to_read;

std::unordered_map<std::string, std::unordered_set<size_t>> part_visibility; /// part_name -> set of replicas announced that part

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't MergeTreePartInfo be used as a key instead of a string id created from it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could make sense to avoid calling getName(), but the hash table itself would store heavier objects. in short, I don't think it matters

@devcrafter

Copy link
Copy Markdown
Member

Still need to check details but some notes:
(1) Specific tests for previous coordinator are removed. AFAIU, current tests cover only cases when part set is the same on all replicas, so there are no tests for stealing behavior. Let's add test(s)
(2) Related to (1). The current way of choosing a working set is non-deterministic. It'd be easier to test different cases if the working set would be taken from the initiator. We've discussed it, but I'm not really convinced that it'd be much more hassle to implement
(3) with current PR, the default coordinator is changed. InOrder coordinators left the same for now. I guess for tables with few big parts, new implementation can outperform InOrder implementation. So, at least it'd be nice to ensure that it's possible to switch to the default coordinator by disabling in order optimization settings

void handleInitialAllRangesAnnouncement(InitialAllRangesAnnouncement announcement) override;
void markReplicaAsUnavailable(size_t replica_number) override;
/// For some ranges their owner and stealer (by consistent hash) cannot read from the given part at all. So this range have to be stolen anyway.
/// Also if those replicas unavailable during the query - segments also will end up here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is misleading. If a part is in set, then a replicas announced it. If the replica becomes unavailable after announcement - currently, the query fails.

@devcrafter devcrafter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, It'd make sense to check that the working set is completely covered by ranges sent to replicas. Probably, it can be disabled in release

{
if (!part_visibility[segment.info.getPartNameV1()].contains(replica_num))
{
chassert(segment.ranges.size() == 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't get it, how it's guaranteed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we always insert RangesInDataPartDescription consisting of an individual segment into these queues. see enqueueSegment

@nickitat

Copy link
Copy Markdown
Member Author

In general, It'd make sense to check that the working set is completely covered by ranges sent to replicas. Probably, it can be disabled in release

maybe, but it won't be always true. e.g. when we have limit.

@nickitat

Copy link
Copy Markdown
Member Author

Stress test (debug) - #58378
Upgrade check (debug) - #57893

@nickitat
nickitat merged commit 66d2db5 into ClickHouse:master Jan 3, 2024
@nickitat
nickitat deleted the parallel_replicas_new_coordinator branch January 3, 2024 23:27
@nickitat nickitat removed the pr-not-for-changelog This PR should not be mentioned in the changelog label Jan 30, 2024
@nickitat nickitat added the pr-performance Pull request with some performance improvements label Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve locality of data distribution for parallel replicas

3 participants