Skip to content

Improve reading with prefetch#49732

Merged
alexey-milovidov merged 11 commits intoClickHouse:masterfrom
nickitat:impr_prefetch
Jul 9, 2023
Merged

Improve reading with prefetch#49732
alexey-milovidov merged 11 commits intoClickHouse:masterfrom
nickitat:impr_prefetch

Conversation

@nickitat
Copy link
Copy Markdown
Member

@nickitat nickitat commented May 10, 2023

Changelog category (leave one):

  • Performance Improvement

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

Now we use fixed-size tasks in MergeTreePrefetchedReadPool as in MergeTreeReadPool. Also from now we use connection pool for S3 requests.


Logical continuation of #49287.

@nickitat nickitat marked this pull request as draft May 10, 2023 11:57
@nickitat nickitat changed the title Improve prefetch Improve reading with prefetch May 10, 2023
@nickitat nickitat changed the title Improve reading with prefetch [WIP] Improve reading with prefetch May 10, 2023
@ClickHouse ClickHouse deleted a comment from clickhouse-ci bot May 10, 2023
@ClickHouse ClickHouse deleted a comment from clickhouse-ci bot May 10, 2023
@kssenii kssenii self-assigned this May 10, 2023
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-performance Pull request with some performance improvements label May 10, 2023
@robot-ch-test-poll1
Copy link
Copy Markdown
Contributor

robot-ch-test-poll1 commented May 10, 2023

This is an automated comment for commit 63b9c1a with description of existing statuses. It's updated for the latest CI running
The full report is available here
The overall status of the commit is 🔴 failure

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
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
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🔴 failure
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
Push to DockerhubThe check for building and pushing the CI related docker images to docker hub🟢 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🔴 failure
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors🟢 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

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.

this is to actually have moderate const-size tasks. and when we will have code to start new prefetch as soon as some of the previous completed, all tasks will be prefetched as soon as max_streams tasks fit in limits.

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 doesn't look necessary and to my taste it is fairly fairly random logic

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.

changed to debug because on test level we now have literally tons of log messages per query

@nickitat nickitat changed the title [WIP] Improve reading with prefetch Improve reading with prefetch May 10, 2023
@nickitat nickitat force-pushed the impr_prefetch branch 3 times, most recently from bc1bf81 to eef6f32 Compare May 20, 2023 21:16
@nickitat nickitat force-pushed the impr_prefetch branch 4 times, most recently from 1802fb7 to f9c1f09 Compare May 29, 2023 13:30
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.

How about different model here?
Soft and hard limit.
If pool is under soft limit, it allocates more. When some connection if freed, pool closes excess connections.
If pool is close to hard limit. It waits no more than connection timeout when limit hits hard level.

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.

what advantages it would have? from perf standpoint any waiting is bad I think.

Copy link
Copy Markdown
Member

@CheSema CheSema Jun 7, 2023

Choose a reason for hiding this comment

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

With those 2 values you are able to configure system in more than two ways: when it waits a vacant connection, when it doesn't wait any and any option between this extremes. However the most important part that you will never go into infinite connections count. That part is worth the efforts.

from perf standpoint any waiting is bad I think.
What do you have as alternative way?

Ofcourse you could fail request instantly. But it is unlogical, since there is a setting connection_timeout.

Imagine that there are a lot of requests to the S3. If you just fail all the requests above the limit the cluster would stop unable to do a progress, that would be denial of service problem. If you slow down the progress by waiting the connections the progress will continue (there would be the brown zone before the black), that would be performance issue with some ways how to mitigate it by changing load pattern from user side or by changing settings from our side. Sounds like gracefull degradation.

@nickitat nickitat force-pushed the impr_prefetch branch 3 times, most recently from 9e8f03c to af59841 Compare June 10, 2023 21:03
@nickitat nickitat marked this pull request as ready for review June 13, 2023 22:56
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.

did not understand why second condition is needed, add a comment?

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.

done

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.

But AsynchronousBoundedReadBuffer has the same check, which means that for the last read range we will never get to this point (as well as to line 178) in code even though the range was all read successfully. I think we can add the same check in destructor before resetting the session and update read_all_range_successfully?

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.

yep, it is a good idea

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.

with_cache can now be make const in .h file )

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.

done

Comment on lines 1089 to 1090
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.

ok, I need not to forget to change this a bit in PR with background download in cache :) because with background download we should not reset the implementation_buffer if file_segment is in PARTAILLY_DOWNLOADED state.

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.

not necessary to keep it

@qoega
Copy link
Copy Markdown
Member

qoega commented Jun 20, 2023

Integration tests are related and potentially have to be updated to reflect current behaviour

@nickitat
Copy link
Copy Markdown
Member Author

@nickitat nickitat marked this pull request as draft July 3, 2023 09:29
@nickitat nickitat force-pushed the impr_prefetch branch 3 times, most recently from 5bd2a08 to f6e4cb3 Compare July 4, 2023 12:44
@nickitat nickitat marked this pull request as ready for review July 7, 2023 19:53
@alexey-milovidov alexey-milovidov merged commit 3d48009 into ClickHouse:master Jul 9, 2023
explicit MemoryTrackerSwitcher(MemoryTracker * new_tracker)
{
if (!current_thread)
throw Exception(ErrorCodes::LOGICAL_ERROR, "current_thread is not initialized");
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.

This breaks clickhouse-disks for S3 disks

Failed to make request to: http://localhost:11111/test?list-type=2&max-keys=1&prefix=clickhouse-disks%2Fdefault%2Ftest.copy: Code: 49. DB::Exception: current_thread is not initialized. (LOGICAL_ERROR), Stack trace (when copying this message, always include the lines below):

So after this change it is not possible to do some operations that requires pools from the main thread.

I will fix it here - b2ea45b (#51448)

azat added a commit to azat/ClickHouse that referenced this pull request Jul 13, 2023
Otherwise "current_thread is not initialized" error, that had been
introduced in ClickHouse#49732, since it is possible to run this code from
non-ClickHouse thread pools.

Fixes: ClickHouse#52013
Signed-off-by: Azat Khuzhin <[email protected]>
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created-cloud deprecated label, NOOP label Jul 27, 2023
azat added a commit to azat/ClickHouse that referenced this pull request Mar 25, 2024
The code that it uses had been removed in ClickHouse#58845.
Introduced in ClickHouse#49732

Signed-off-by: Azat Khuzhin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created-cloud deprecated label, NOOP pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants