Skip to content

Limit memory usage of exchange sender (#10387)#10417

Merged
ti-chi-bot[bot] merged 3 commits intopingcap:release-8.5from
ti-chi-bot:cherry-pick-10387-to-release-8.5
Sep 9, 2025
Merged

Limit memory usage of exchange sender (#10387)#10417
ti-chi-bot[bot] merged 3 commits intopingcap:release-8.5from
ti-chi-bot:cherry-pick-10387-to-release-8.5

Conversation

@ti-chi-bot
Copy link
Member

@ti-chi-bot ti-chi-bot commented Sep 8, 2025

This is an automated cherry-pick of #10387

What problem does this PR solve?

Issue Number: close #10337

Problem Summary:

The root cause is in current implementation, the buffered block number in ExchangeSender can be upto max_threads * max_threads * fine_grain_stream_count, so if max_threads is large, and the size of each row is big, the buffered block can consume very large memory.

This pr limit the memory usage of ExchangeSender by max(MAX_BATCH_SEND_MIN_LIMIT_MEM_SIZE * max_threads, max_buffered_bytes_in_executor)

What is changed and how it works?


Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
    test in 2-tiflash's cluster, with max_threads = 32 and sort memory limit set to 5G
explain analyze select * from (select *, row_number() over(partition by ps_partkey order by ps_suppkey) as rn from test) d where rn = 10;

Where test has 40000000 rows, each row has ~1200 bytes.
Before this pr
peak memory of each TiFlash is about 30G

[2025/09/01 11:47:48.178 +08:00] [DEBUG] [MemoryTracker.cpp:110] ["Peak memory usage (for query): 33.13 GiB."] [source=MemoryTracker] [thread_id=813]
[2025/09/01 11:47:48.178 +08:00] [DEBUG] [MemoryTracker.cpp:110] ["Peak memory usage (total): 33.13 GiB."] [source=MemoryTracker] [thread_id=813]

After this pr
peak memory of each TiFlash is about 10G

[2025/09/01 11:42:28.895 +08:00] [DEBUG] [MemoryTracker.cpp:110] ["Peak memory usage (for query): 9.86 GiB."] [source=MemoryTracker] [thread_id=635]
[2025/09/01 11:42:28.895 +08:00] [DEBUG] [MemoryTracker.cpp:110] ["Peak memory usage (total): 9.86 GiB."] [source=MemoryTracker] [thread_id=635]
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR. labels Sep 8, 2025
@ti-chi-bot
Copy link
Member Author

@windtalker This PR has conflicts, I have hold it.
Please resolve them or ask others to resolve them, then comment /unhold to remove the hold label.

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Sep 8, 2025

@ti-chi-bot: ## If you want to know how to resolve it, please read the guide in TiDB Dev Guide.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Sep 8, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Sep 8, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gengliqi, windtalker

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [gengliqi,windtalker]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Sep 8, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Sep 8, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-09-08 05:03:18.695948727 +0000 UTC m=+251265.255830214: ☑️ agreed by windtalker.
  • 2025-09-08 05:24:02.534547966 +0000 UTC m=+252509.094429473: ☑️ agreed by gengliqi.

@ti-chi-bot ti-chi-bot bot added cherry-pick-approved Cherry pick PR approved by release team. and removed do-not-merge/cherry-pick-not-approved labels Sep 8, 2025
@windtalker
Copy link
Contributor

/hold cancel

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 9, 2025
@windtalker
Copy link
Contributor

/run-all-tests

@windtalker
Copy link
Contributor

/test pull-unit-test

@windtalker
Copy link
Contributor

/test pull-integration-test

@windtalker
Copy link
Contributor

/test pull-unit-test

@windtalker
Copy link
Contributor

/test pull-integration-test

@ti-chi-bot ti-chi-bot bot merged commit ec6b716 into pingcap:release-8.5 Sep 9, 2025
4 checks passed
@ti-chi-bot ti-chi-bot bot deleted the cherry-pick-10387-to-release-8.5 branch September 9, 2025 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved cherry-pick-approved Cherry pick PR approved by release team. lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants