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

Storages: limit memory usage of data sharing (#8567) #8573

Merged

Conversation

ti-chi-bot
Copy link
Member

@ti-chi-bot ti-chi-bot commented Dec 22, 2023

This is an automated cherry-pick of #8567

What problem does this PR solve?

Issue Number: close #8564

Problem Summary:
In terms of design, we hope that by scheduling tasks, the shared data will be immediately read and deleted, so under normal circumstances, it will not occupy additional memory.
However, there is a scenario that would break this assumption: If two requests A and B are merged, request A reads faster and request B reads slowly.

A will share the data with B, but request B may skip directly without reading and deleting these shared data, because it finds its queue is full (

if (pool->getFreeBlockSlots() <= 0 || pool->isRUExhausted())
{
continue;
}
), which may result in consuming much more memory than expected.

What is changed and how it works?

This PR adds limitations on the size of shared data. It includes two aspects:

  • Global shared data size limit.
  • Limit on the count of shared data held by each DMFileReader.
    • Why not limit the size of shared data held by each DMFileReader?
    • First, it just holds a smart pointer. This pointer can be shared between multiple requests. How many bytes should it take? That needs some considerations.
    • Second, make changes smaller to pick this PR to other LST branches.
  • Also, it supports disabling data sharing and doesn't affect read thead.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
    • Run a fast tablescanning query and a slow tablescanning query concurrently.
    • In the image below,
      • on the left is the code of this PR, the limitation of shared data size is 1GB.
      • on the right is the code of master.

image

  • 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

Fix a bug that the memory usage rises significantly when there are slow queries

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR. labels Dec 22, 2023
@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 22, 2023
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Dec 22, 2023
@JinheLin
Copy link
Contributor

/run-all-tests

@pingcap pingcap deleted a comment from ti-chi-bot Dec 22, 2023
@JinheLin
Copy link
Contributor

/run-all-tests

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Dec 22, 2023
@ti-chi-bot ti-chi-bot added the cherry-pick-approved Cherry pick PR approved by release team. label Dec 23, 2023
@ti-chi-bot ti-chi-bot bot added the lgtm label Dec 24, 2023
Copy link
Contributor

ti-chi-bot bot commented Dec 24, 2023

[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 removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Dec 24, 2023
Copy link
Contributor

ti-chi-bot bot commented Dec 24, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-12-22 14:47:09.643632379 +0000 UTC m=+1231520.680859301: ☑️ agreed by JinheLin.
  • 2023-12-24 13:08:12.206616901 +0000 UTC m=+1398383.243843827: ☑️ agreed by Lloyd-Pottiger.

@ti-chi-bot ti-chi-bot bot merged commit d3aafae into pingcap:release-6.5 Dec 24, 2023
5 checks passed
@ti-chi-bot ti-chi-bot bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Dec 25, 2023
@ti-chi-bot ti-chi-bot bot removed the release-note-none Denotes a PR that doesn't merit a release note. label Dec 25, 2023
@JaySon-Huang
Copy link
Contributor

Changed to release note to be "Fix a bug that the memory usage rises significantly when there are slow queries"

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 Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants