Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KVStore: Reduce the memory before and after a large txn is committed #9707

Merged
merged 24 commits into from
Dec 30, 2024

Conversation

CalvinNeo
Copy link
Member

@CalvinNeo CalvinNeo commented Dec 6, 2024

What problem does this PR solve?

Issue Number: ref #9722

Problem Summary:

What is changed and how it works?

There are two ideas:

  1. The first idea is to reduce the memory after a large txn is commmitted. The mechanism is introduced in Support arena.i.purge and malloc_stats_print when jemalloc is used tidb-engine-ext#402. Merged in update proxy of master to raftstore-proxy for memory purge and memory status #9721
  2. The second idea is to reduce the memory before a large txn is committed. The idea is based on the observation that the DecodedLockCFValue has the size of 128 bytes. Given a txn that updates 15m rows, the memory cost is 1.8G

The idea is that we won't store the built(parsed) DecodedLockCFValue if the lock belongs to a large txn. So everytime we scan the locks of large txns, we will parse it again.

Avoid store the built DecodedLockCFValue

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • 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: Calvin Neo <[email protected]>
@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 6, 2024
Signed-off-by: Calvin Neo <[email protected]>
Signed-off-by: Calvin Neo <[email protected]>
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 10, 2024
Signed-off-by: Calvin Neo <[email protected]>
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 10, 2024
@CalvinNeo CalvinNeo changed the title dnm investigate oom txn commit Reduce the memory before and after a large txn is committed Dec 11, 2024
@CalvinNeo CalvinNeo changed the title Reduce the memory before and after a large txn is committed DNM Reduce the memory before and after a large txn is committed Dec 11, 2024
Signed-off-by: Calvin Neo <[email protected]>
@CalvinNeo CalvinNeo changed the title DNM Reduce the memory before and after a large txn is committed Reduce the memory before and after a large txn is committed Dec 25, 2024
@ti-chi-bot ti-chi-bot bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Dec 25, 2024
@CalvinNeo
Copy link
Member Author


Benchmark Time CPU Iterations

parseTest 126 ns 125 ns 5612257
parseTest 129 ns 129 ns 5612257
parseTest_mean 127 ns 127 ns 2
parseTest_median 127 ns 127 ns 2
parseTest_stddev 2.56 ns 2.56 ns 2
parseTest_cv 2.01 % 2.02 % 2

Signed-off-by: Calvin Neo <[email protected]>
dbms/src/Storages/KVStore/Decode/PartitionStreams.cpp Outdated Show resolved Hide resolved
dbms/src/Storages/KVStore/Decode/PartitionStreams.cpp Outdated Show resolved Hide resolved
dbms/src/Storages/KVStore/Decode/PartitionStreams.cpp Outdated Show resolved Hide resolved
dbms/src/Storages/KVStore/Decode/PartitionStreams.cpp Outdated Show resolved Hide resolved
dbms/src/Storages/KVStore/Decode/PartitionStreams.cpp Outdated Show resolved Hide resolved
Comment on lines 238 to 239
should_continue = true;
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

bool withInner(std::function<bool(const Inner &)> f) const; may be better?

Copy link
Member Author

Choose a reason for hiding this comment

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

Similar, I can move it into the DecodedLockCfValue

@CalvinNeo CalvinNeo changed the title Reduce the memory before and after a large txn is committed KVStore: Reduce the memory before and after a large txn is committed Dec 27, 2024
CalvinNeo and others added 2 commits December 27, 2024 18:06
@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 30, 2024
Copy link
Contributor

ti-chi-bot bot commented Dec 30, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JinheLin, Lloyd-Pottiger

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

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [JinheLin,Lloyd-Pottiger]

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 Dec 30, 2024
Copy link
Contributor

ti-chi-bot bot commented Dec 30, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-12-30 02:56:27.236155449 +0000 UTC m=+319122.592159989: ☑️ agreed by Lloyd-Pottiger.
  • 2024-12-30 05:41:18.201466888 +0000 UTC m=+329013.557471454: ☑️ agreed by JinheLin.

@ti-chi-bot ti-chi-bot bot merged commit 08abd71 into pingcap:master Dec 30, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants