Skip to content

RFC: Optimize MarkRanges by using devector over deque - #86933

Merged
azat merged 2 commits into
ClickHouse:masterfrom
azat:optimize-marks-ranges
Sep 11, 2025
Merged

azat merged 2 commits into
ClickHouse:masterfrom
azat:optimize-marks-ranges

Conversation

@azat

@azat azat commented Sep 10, 2025 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Performance Improvement

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

Improves performance of fast queries with lots of parts in table (by optimizing MarkRanges by using devector over deque)

While reviewing #85535 I noticed that MarkRanges copying is very slow, let's try to replace it with more efficient container (hope that we do not rely on iterators guarantees anywhere in the code)

Test

create or replace table data (key Int, part Int) engine=MergeTree() order by key partition by part;
insert into data select *, *%10000 from numbers(10000) settings max_partitions_per_insert_block=10000;
clickhouse-benchmark -q 'select * from data where key = 1' -i 100

Results

  • Before - localhost:9000, queries: 100, QPS: 11.763, RPS: 11.763, MiB/s: 0.000, result RPS: 11.763, result MiB/s: 0.000.
  • After - localhost:9000, queries: 100, QPS: 16.347, RPS: 16.347, MiB/s: 0.000, result RPS: 16.347, result MiB/s: 0.000.

And when #85535 will be merged this will be moved to INSERT side:

@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ba7d70e]

Summary: ❌

job_name test_name status info comment
Build (arm_v80compat) error
Build (amd_compat) error
Build (amd_musl) error
Build (fuzzers) error
Stress test (amd_debug) failure
Server died FAIL
Hung check failed, possible deadlock found (see hung_check.log) FAIL
Killed by signal (in clickhouse-server.log) FAIL
Fatal message in clickhouse-server.log (see fatal_messages.txt) FAIL
Killed by signal (output files) FAIL
Found signal in gdb.log FAIL
Stress test (amd_ubsan) failure
Server died FAIL
Hung check failed, possible deadlock found (see hung_check.log) FAIL
Killed by signal (in clickhouse-server.log) FAIL
Fatal message in clickhouse-server.log (see fatal_messages.txt) FAIL
Killed by signal (output files) FAIL
Found signal in gdb.log FAIL

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Sep 10, 2025
@azat azat changed the title Optimize MarkRanges by using devector over deque RFC: Optimize MarkRanges by using devector over deque Sep 10, 2025
@azat

azat commented Sep 11, 2025 •

Copy link
Copy Markdown
Member Author
[14270/14281] Building CXX object programs/server/CMakeFiles/clickhouse-server-lib.dir/Server.cpp.o
[ERROR chcache] Failed to upload to ClickHouse: network error: client error (SendRequest)

And also:

[ERROR chcache] Failed to upload to ClickHouse: bad response: Code: 241. DB::Exception: (total) memory limit exceeded: would use 15.43 GiB (attempt to allocate chunk of 5.02 MiB bytes), current RSS: 15.42 GiB, maximum: 14.40 GiB. (MEMORY_LIMIT_EXCEEDED) (version 25.6.2.6054 (official build))

@thevar1able maybe we need some retries?

@Algunenano Algunenano self-assigned this Sep 11, 2025
@azat

azat commented Sep 11, 2025

Copy link
Copy Markdown
Member Author

Even perf tests shows the difference:

  • json_shared_data_compact is not related likely
  • alter_select has 5K partitions, so it is expected
  • parallel_final - replacing_final_1024p_rnd - has 1K partitions - expected as well
  • merge_tree_many_partitions - 10K partitions
image image

@Algunenano Algunenano 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.

LGTM. I assume memory usage might be slightly higher but I don't see how that can be impactful

@azat

azat commented Sep 11, 2025

Copy link
Copy Markdown
Member Author

LGTM. I assume memory usage might be slightly higher but I don't see how that can be impactful

I thought about this as well, but, I am not sure that this is even the case, since with deque the memory fragmentation is higher as well

@azat
azat enabled auto-merge September 11, 2025 10:40
@azat
azat added this pull request to the merge queue Sep 11, 2025
Merged via the queue into ClickHouse:master with commit 2f4d931 Sep 11, 2025
@azat
azat deleted the optimize-marks-ranges branch September 11, 2025 11:00
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 11, 2025
mkmkme added a commit to Altinity/ClickHouse that referenced this pull request Oct 24, 2026
Stable 25.8 Backport of ClickHouse#86933 - RFC: Optimize MarkRanges by using devector over deque
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Oct 25, 2026
Antalya 25.8 Backport of ClickHouse#86933 - RFC: Optimize MarkRanges by using devector over deque
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 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.

3 participants