Skip to content

Add dynamic untracked memory limits for more precise memory tracking - #64423

Merged
serxa merged 22 commits into
masterfrom
precise-memtracking
Jun 6, 2024
Merged

serxa merged 22 commits into
masterfrom
precise-memtracking

Conversation

@serxa

@serxa serxa commented May 26, 2024 •

Copy link
Copy Markdown
Member

The current memory tracker has an error of up to untracked_memory_limit = 4MB per thread. Consider a ClickHouse server running with 8GB RAM and a standard max_server_memory_usage_to_ram_ratio = 0.9 server setting. If there are 1000 threads (and every thread has 800KB on average) OOM can happen before any query is stopped with MEMORY_LIMIT_EXCEEDED.

We need total untracked memory to be proportional to current memory usage regardless of the number of threads. To make it fit into 10% RAM we want an error to be less than e.g. 6%. To achieve it we need untracked_memory_limit to be updated dynamically and be proportional to current thread memory usage for threads with small memory footprint:
untracked_memory_limit = clamp(already_tracked / 16, 4KB, 4MB).

Changelog category (leave one):

  • Not for changelog

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

This PR was reverted

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/

CI Settings

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

  • Allow: Integration Tests
  • Allow: Stateless tests
  • Allow: Stateful tests
  • Allow: Unit tests
  • Allow: Performance tests
  • Allow: All with aarch64
  • Allow: All with ASAN
  • Allow: All with TSAN
  • Allow: All with Analyzer
  • Allow: All with Azure
  • Allow: Add your option here

  • Exclude: Fast test
  • Exclude: Integration Tests
  • Exclude: Stateless tests
  • Exclude: Stateful tests
  • Exclude: Performance tests
  • Exclude: All with ASAN
  • Exclude: All with TSAN
  • Exclude: All with MSAN
  • Exclude: All with UBSAN
  • Exclude: All with Coverage
  • Exclude: All with Aarch64

  • do not test (only style check)
  • disable merge-commit (no merge from master before tests)
  • disable CI cache (job reuse)
  • allow: batch 1 for multi-batch jobs
  • allow: batch 2
  • allow: batch 3
  • allow: batch 4, 5 and 6

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-feature Pull request with new product feature label May 26, 2024
@robot-clickhouse-ci-1

robot-clickhouse-ci-1 commented May 26, 2024 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit 2c193a7 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
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⏳ pending
Successful checks
Check nameDescriptionStatus
A SyncIf it fails, ask a maintainer for help✅ 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
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
Mergeable CheckChecks if all other necessary checks are successful✅ success
PR CheckChecks correctness of the PR's body✅ 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

@serxa
serxa marked this pull request as ready for review May 31, 2024 08:47
@divanik divanik self-assigned this May 31, 2024
@serxa

serxa commented May 31, 2024 •

Copy link
Copy Markdown
Member Author

I'm not sure what's wrong with the Upgrade check. Does anyone have an idea? I've added a new setting to the history and it does not show up, but the check is still failing.

Changed settings are not reflected in settings changes history (see changed_settings.txt) - FAIL

   ┌─name─────────────────────────────────────┬─new_value─┬─old_value─┐
1. │ enable_vertical_final                    │ 0         │ 1         │
2. │ output_format_parquet_use_custom_encoder │ 1         │ 0         │
   └──────────────────────────────────────────┴───────────┴───────────┘

New settings are not reflected in settings changes history (see new_settings.txt) - FAIL

    ┌─name──────────────────────────────────────────┐
 1. │ azure_max_blocks_in_multipart_upload          │
 2. │ allow_experimental_join_condition             │
 3. │ prefer_external_sort_block_bytes              │
 4. │ cross_join_min_rows_to_compress               │
 5. │ cross_join_min_bytes_to_compress              │
 6. │ cast_string_to_dynamic_use_inference          │
 7. │ allow_experimental_dynamic_type               │
 8. │ allow_deprecated_error_prone_window_functions │
 9. │ input_format_force_null_for_omitted_fields    │
10. │ input_format_tsv_crlf_end_of_line             │
    └───────────────────────────────────────────────┘

@serxa

serxa commented Jun 3, 2024

Copy link
Copy Markdown
Member Author

Okay, merge master and CI tests rerun fixed the problem. Tests 01676_clickhouse_client_autocomplete and 02456_progress_tty seem to be flaky. I think this PR is now ready to be merged.

@serxa
serxa requested a review from divanik June 3, 2024 13:30
Comment thread src/Core/SettingsChangesHistory.h Resolved
Comment thread src/Common/CurrentMemoryTracker.cpp Resolved
@serxa
serxa enabled auto-merge June 6, 2024 12:57
@serxa
serxa added this pull request to the merge queue Jun 6, 2024
Merged via the queue into master with commit 9ec1306 Jun 6, 2024
@serxa
serxa deleted the precise-memtracking branch June 6, 2024 19:02
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 6, 2024
baibaichen added a commit to Kyligence/gluten that referenced this pull request Jun 7, 2024
@Algunenano

Copy link
Copy Markdown
Member

@Algunenano

Copy link
Copy Markdown
Member

It might have also broken test_failed_async_inserts/test.py::test_failed_async_inserts https://s3.amazonaws.com/clickhouse-test-reports/0/2da27f4deeb4141b154f16bf4420a1018a97b610/integration_tests__release__[2_4].html

Integration tests were not run in the last execution, so it's hard to say

baibaichen added a commit to Kyligence/ClickHouse that referenced this pull request Jun 7, 2024
baibaichen added a commit to Kyligence/gluten that referenced this pull request Jun 7, 2024
azat added a commit to azat/ClickHouse that referenced this pull request Mar 31, 2026
The current memory tracker has an error of up to `untracked_memory_limit
= 4MB` per thread. Consider a ClickHouse server running with 8GB RAM and
a standard `max_server_memory_usage_to_ram_ratio = 0.9` server setting.
If there are 1000 threads (and every thread has 800KB on average) OOM
can happen before any query is stopped with `MEMORY_LIMIT_EXCEEDED`.

We need total untracked memory to be proportional to current memory
usage regardless of the number of threads. To make it fit into 10% RAM
we want an error to be less than e.g. 6%. To achieve it we need
`untracked_memory_limit` to be updated dynamically and be proportional
to current thread memory usage for threads with small memory footprint:
`untracked_memory_limit = clamp(already_tracked / 16, 4KB, 4MB)`

Resubmit of: ClickHouse#64423
Co-authored-by: Azat Khuzhin <[email protected]>
azat added a commit to azat/ClickHouse that referenced this pull request Apr 18, 2026
The current memory tracker has an error of up to `untracked_memory_limit
= 4MB` per thread. Consider a ClickHouse server running with 8GB RAM and
a standard `max_server_memory_usage_to_ram_ratio = 0.9` server setting.
If there are 1000 threads (and every thread has 800KB on average) OOM
can happen before any query is stopped with `MEMORY_LIMIT_EXCEEDED`.

We need total untracked memory to be proportional to current memory
usage regardless of the number of threads. To make it fit into 10% RAM
we want an error to be less than e.g. 6%. To achieve it we need
`untracked_memory_limit` to be updated dynamically and be proportional
to current thread memory usage for threads with small memory footprint:
`untracked_memory_limit = clamp(already_tracked / 16, 4KB, 4MB)`

Resubmit of: ClickHouse#64423
Co-authored-by: Azat Khuzhin <[email protected]>
azat added a commit to azat/ClickHouse that referenced this pull request Apr 22, 2026
The current memory tracker has an error of up to `untracked_memory_limit
= 4MB` per thread. Consider a ClickHouse server running with 8GB RAM and
a standard `max_server_memory_usage_to_ram_ratio = 0.9` server setting.
If there are 1000 threads (and every thread has 800KB on average) OOM
can happen before any query is stopped with `MEMORY_LIMIT_EXCEEDED`.

We need total untracked memory to be proportional to current memory
usage regardless of the number of threads. To make it fit into 10% RAM
we want an error to be less than e.g. 6%. To achieve it we need
`untracked_memory_limit` to be updated dynamically and be proportional
to current thread memory usage for threads with small memory footprint:
`untracked_memory_limit = clamp(already_tracked / 16, 4KB, 4MB)`

Resubmit of: ClickHouse#64423
Co-authored-by: Azat Khuzhin <[email protected]>
azat added a commit to azat/ClickHouse that referenced this pull request Apr 22, 2026
The current memory tracker has an error of up to `untracked_memory_limit
= 4MB` per thread. Consider a ClickHouse server running with 8GB RAM and
a standard `max_server_memory_usage_to_ram_ratio = 0.9` server setting.
If there are 1000 threads (and every thread has 800KB on average) OOM
can happen before any query is stopped with `MEMORY_LIMIT_EXCEEDED`.

We need total untracked memory to be proportional to current memory
usage regardless of the number of threads. To make it fit into 10% RAM
we want an error to be less than e.g. 6%. To achieve it we need
`untracked_memory_limit` to be updated dynamically and be proportional
to current thread memory usage for threads with small memory footprint:
`untracked_memory_limit = clamp(already_tracked / 16, 4KB, 4MB)`

Resubmit of: ClickHouse#64423
Co-authored-by: Azat Khuzhin <[email protected]>
azat added a commit to azat/ClickHouse that referenced this pull request Apr 23, 2026
The current memory tracker has an error of up to `untracked_memory_limit
= 4MB` per thread. Consider a ClickHouse server running with 8GB RAM and
a standard `max_server_memory_usage_to_ram_ratio = 0.9` server setting.
If there are 1000 threads (and every thread has 800KB on average) OOM
can happen before any query is stopped with `MEMORY_LIMIT_EXCEEDED`.

We need total untracked memory to be proportional to current memory
usage regardless of the number of threads. To make it fit into 10% RAM
we want an error to be less than e.g. 6%. To achieve it we need
`untracked_memory_limit` to be updated dynamically and be proportional
to current thread memory usage for threads with small memory footprint:
`untracked_memory_limit = clamp(already_tracked / 16, 4KB, 4MB)`

Resubmit of: ClickHouse#64423
Co-authored-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-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants