Skip to content

s3 adaptive timeouts - #56314

Merged
CheSema merged 19 commits into
ClickHouse:masterfrom
CheSema:s3-aggressive-timeouts
Nov 19, 2023
Merged

CheSema merged 19 commits into
ClickHouse:masterfrom
CheSema:s3-aggressive-timeouts

Conversation

@CheSema

@CheSema CheSema commented Nov 3, 2023 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • New Feature

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

S3 adaptive timeout means that first attempt made with low send and receive timeouts.

@CheSema CheSema changed the title aggressive timeout s3 aggressive timeouts Nov 3, 2023
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-feature Pull request with new product feature label Nov 3, 2023
@robot-ch-test-poll4

robot-ch-test-poll4 commented Nov 3, 2023 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit 74a8f31 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
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 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. 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
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
Push to DockerhubThe check for building and pushing the CI related docker images to docker hub✅ 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
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
Check nameDescriptionStatus
Integration testsThe integration tests report. In parenthesis the package type is given, and 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

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Nov 4, 2023
@CheSema
CheSema force-pushed the s3-aggressive-timeouts branch 3 times, most recently from cb9dfd5 to bbc664d Compare November 7, 2023 11:31
@CheSema

CheSema commented Nov 7, 2023

Copy link
Copy Markdown
Member Author

I will be fixing tests for some time. However the code is complete, I think.

@CheSema
CheSema marked this pull request as ready for review November 7, 2023 11:33
@CheSema

CheSema commented Nov 8, 2023 •

Copy link
Copy Markdown
Member Author

There is an interesting case.
Timeouts are set to the socket right after session is connected. CH uses session pool. When session is taken from the pool, it already has some timeouts and new timeouts have no effect on it.

There are 2 posible solution:

  • make several pools for connections with different settings
  • try to reset that timeouts setting for already connected session.

Im choosing second option. It is more simple.

@CheSema

CheSema commented Nov 8, 2023 •

Copy link
Copy Markdown
Member Author

One more issue.

CompleteMultipartUpload works bad with aggressive timeouts. If you get timeout that does not mean that the request is finished. The next retry could see '404' after that. And that means that multipart upload has been completed.

CompleteMultipartUpload -> timeout
retry CompleteMultipartUpload -> 404 'NoSuchUpload' ---- that fails the whole query or merge/mutation
tryToAbortMultipartUpload -> 499 'The specified multipart upload does not exist' 

That issue is present with us regardless this changes. That changes have exposed the problem.

There is no point in trying complete multipart upload with aggressive timeouts. There would be retries 100%. That retries would trigger the case described above.
But that is not enough. Some dedicated solution has to be made here. That PR addresses it #56475

@vitlibar vitlibar Nov 9, 2023 •

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.

You're reading from the config a single uint, why is it "timeouts" and not "timeout"?
UPD: I got it, it's a boolean value, so it's better to use getBool().

@CheSema CheSema Nov 9, 2023 •

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.

I have named the feature flag as s3_aggressive_timeouts. Here I just cut off the s3_ prefix and it becomes aggressive_timeouts.
I could change the feature name in order to keep meaning after cutting s3_ prefix.

What do you like?
s3_aggressive_retries + aggressive_retries,
s3_adaptive_timeouts_when_retries + adaptive_timeouts_when_retries,
s3_adaptive_timeout + adaptive_timeout.

@vitlibar vitlibar Nov 9, 2023 •

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.

For me "adaptive_timeouts" looks better, but maybe there is a well-known name for that. Why did you name them "aggressive" in the beginning?

@vitlibar vitlibar Nov 9, 2023 •

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.

Why don't you want to use the word "use"? The name "use_aggressive_timeouts" immediately makes it clear that it's a boolean. But of course as you already have other settings it's important to follow the existing naming rules.

@CheSema CheSema Nov 9, 2023 •

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.

I like it
s3_use_adaptive_timeouts + use_adaptive_timeouts.
Will change in that way.

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.

The naming is most procrastinating part, thanks.

@CheSema CheSema changed the title s3 aggressive timeouts s3 adaptive timeouts Nov 9, 2023
@CheSema
CheSema force-pushed the s3-aggressive-timeouts branch 2 times, most recently from cdb183b to 6be57e5 Compare November 9, 2023 23:28
@CheSema

CheSema commented Nov 10, 2023 •

Copy link
Copy Markdown
Member Author

Good test test_storage_s3/test.py::test_storage_s3_get_unstable shows the next interesting issue.

CH reads some key. First attempt. Timeouts are low. The first byte is fast. CH creates ReadBufferFromS3 and tries to read the rest. In the middle S3 has spike in latency. Timeout happends.
CH make retries that itself. S3::Client receives new request. And again. First attempt. Timeouts are low. Any spike in latency leads to failing the request. Because there no build-in in S3::Client retries when CH read from stream.

I'm going to increase receive timeout for the next calls after first byte has been received.
Also I need to track retries from ReadBufferFromS3.

@CheSema
CheSema force-pushed the s3-aggressive-timeouts branch from 6e16f28 to caf03d5 Compare November 10, 2023 16:03
@CheSema
CheSema force-pushed the s3-aggressive-timeouts branch 5 times, most recently from 51655d8 to dd01fa7 Compare November 13, 2023 22:41
@CheSema
CheSema force-pushed the s3-aggressive-timeouts branch from dd01fa7 to 3075bd9 Compare November 14, 2023 10:34
Comment thread src/Core/Settings.h Resolved
Comment thread src/IO/S3/PocoHTTPClient.h Resolved
Comment thread base/poco/Net/src/HTTPSession.cpp Outdated
{
_sendTimeout = sendTimeout;

if (connected())

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.

strictly speaking not any option cannot be set on an already connected socket.

EISCONN
The socket is already connected, and a specified option cannot be set while the socket is connected.

maybe we could wrap this code in a try-catch just in case we run in some interesting system. also may be that I overcomplicate everything or timeout options are guaranteed to work.

@CheSema CheSema Nov 16, 2023 •

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.

Well, timeouts options are always set after connection are established. The point was that it was done only at connection, but it was omitted at reusing already established connection from the pool .
If we are not able to modify that options our connections would work unpredictably.
I did not find any mention that SO_SNDTIMEO could be end up with EISCONN.
But any way I can add try catch.

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.

I added try catch which mutes exceptions in release build from setTimeout

Comment thread src/IO/ConnectionTimeouts.cpp Resolved
Comment thread src/IO/S3/PocoHTTPClient.h Resolved
Comment thread base/poco/Net/src/HTTPSession.cpp Resolved
Comment thread src/IO/ConnectionTimeouts.cpp Resolved
@CheSema
CheSema merged commit a950595 into ClickHouse:master Nov 19, 2023
@tavplubix

Copy link
Copy Markdown
Member

@CheSema, please don't forget to check failed tests before mering even if failures seem to be unrelated to changes. Looks like this PR breaks test_merge_tree_s3/test.py::test_s3_engine_heavy_write_check_mem[in_flight_memory0-node], let's revert it.

@CheSema

CheSema commented Nov 20, 2023

Copy link
Copy Markdown
Member Author

@CheSema, please don't forget to check failed tests before mering even if failures seem to be unrelated to changes. Looks like this PR breaks test_merge_tree_s3/test.py::test_s3_engine_heavy_write_check_mem[in_flight_memory0-node], let's revert it.

That test is flaky. I was going to deal with that flakiness aside that PR. That is why I ignored it.
But your are right. That changes made that test not flaky but totally broken.

@CheSema

CheSema commented Jan 20, 2024

Copy link
Copy Markdown
Member Author

GCP affected by this PR, the fix here #59015

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-backports-created-cloud deprecated label, NOOP pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants