Skip to content

Add HTTP session reuse within a single ReadWriteBufferFromHTTP#49540

Closed
al13n321 wants to merge 1 commit intomasterfrom
pool
Closed

Add HTTP session reuse within a single ReadWriteBufferFromHTTP#49540
al13n321 wants to merge 1 commit intomasterfrom
pool

Conversation

@al13n321
Copy link
Copy Markdown
Member

@al13n321 al13n321 commented May 5, 2023

Changelog category (leave one):

  • Performance Improvement

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

  • Better performance of url() table function in any format (through connection pooling).

Added some limited HTTP session pooling for StorageURL. Sessions are now reused by all (non-concurrent) read operations on the same ReadBuffer. This makes SELECT count(*) from remote (different region) parquet files 2.5x faster!

Inverted how attachSessionData() is used for marking whether HTTP sessions can be reused. Sessions were considered reusable by default, and ReadWriteBufferFromHTTP had to mark them as non-reusable on any error. It was missing some cases because there are lots of them. This PR flips it - the sessions are not reusable unless marked as reusable, which ReadWriteBufferFromHTTP does after receiving full response successfully. It seems silly that any of this needs to be done at all, instead of HTTPClientSession doing this tracking internally; but this was less work than changing HTTPClientSession.

We should add similar pooling for StorageS3, but that'll take more work: there's no simple way to attach the pool to a ReadBufferFromS3 instance, so it's either a global pool (with more care for eviction policy and correctness) or some hacks to indirectly pass a pool pointer to PocoHTTPClient.

@al13n321
Copy link
Copy Markdown
Member Author

al13n321 commented May 5, 2023

(This PR depends on #49539 , so CI doesn't run on it yet. But it's ready for review, and CI ran on an older version of this PR: #49121 )

@qoega
Copy link
Copy Markdown
Member

qoega commented May 8, 2023

As I understand, you have to change base branch to master to run CI.

@al13n321 al13n321 changed the base branch from readat to master May 8, 2023 22:12
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-performance Pull request with some performance improvements submodule changed At least one submodule changed in this PR. labels May 8, 2023
@robot-ch-test-poll2
Copy link
Copy Markdown
Contributor

robot-ch-test-poll2 commented May 8, 2023

This is an automated comment for commit 9a9a117 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🔴 failure
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
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
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

@alexey-milovidov
Copy link
Copy Markdown
Member

Submodule was committed by mistake.

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 removed the submodule changed At least one submodule changed in this PR. label May 11, 2023
@nickitat nickitat self-assigned this May 15, 2023
@al13n321 al13n321 force-pushed the pool branch 2 times, most recently from f0c7991 to bdd6577 Compare May 31, 2023 23:09
@al13n321 al13n321 force-pushed the pool branch 2 times, most recently from 253bc7b to 05bd029 Compare July 17, 2023 15:02
@al13n321 al13n321 force-pushed the pool branch 2 times, most recently from 05bd029 to 596b103 Compare July 18, 2023 15:40
/// The pool must outlive all session pointers created by it.
///
/// Session is only reused if it has HTTPSessionReuseTag attached, see comment in HTTPCommon.h
class LocallyPooledSessionFactory
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.

could we replace it with HTTPSessionPool used for s3 read buffer? it has a mode when new sessions will be allocated without waiting after limit is exceeded, but these excessive sessions will be removed when request is finished. imo it is better behaviour because there is no much sense is keeping bursted session forever - they are likely to expire and do reconnect on the next use anyway.

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 was too afraid to use it here:

  • It never evicts endpoints from endpoints_pool. If the user touches a million different hosts (even invalid ones) without restarting the server, it'll get quite big.
  • For each endpoint, it only evicts sessions when new requests come in. If the user touches 100 K different hosts with 30 sessions each, we'll be holding 300K fds indefinitely, if I'm reading the code right.
  • I don't know enough about HTTP to be confident that matching tuple <host, port, https, proxy_host, proxy_port, proxy_https, max_connections_per_endpoint, resolve_host, wait_on_pool_size_limit> is sufficient for reuse in all cases. Maybe URL can have some other connection settings not listed here? Maybe I'm being too paranoid.

These are all fine for S3, where the URLs are mostly under our control and not very diverse, but for arbitrary URLs from the user I chickened out. Guess I'll change it to use the global pool and add a setting to disable pooling altogether.

Copy link
Copy Markdown
Member

@nickitat nickitat Jul 19, 2023

Choose a reason for hiding this comment

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

If the user touches a million different hosts

you're talking about url() function? indeed, with s3 I don't think it is possible.

@alexey-milovidov
Copy link
Copy Markdown
Member

@al13n321, Please check what is with the test test_redirect_url_storage.

@CheSema
Copy link
Copy Markdown
Member

CheSema commented Feb 12, 2024

That PR is already old. I do not see the reasons to continue it.
Lets close it in favour #58845.

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.

7 participants