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

add support for auxiliary memory bound in mpmc_queue #6820

Merged

Conversation

windtalker
Copy link
Contributor

What problem does this PR solve?

Issue Number: ref #6528

Problem Summary:
In TiFlash runtime, some executors(like ExchangeReceiver, MPPTunnelSender, UnionBlockInputStream) use a MPMC queue to buffer the data, but the queues are only limited by the number of elements. If the element occupies a large amount of memory, the buffer queue may occupy too much memory, this pr add auxiliary_memory_bound to mpmc queue, so the memory usage by the queue can be limited.

What is changed and how it works?

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

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Feb 15, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • SeaRise
  • gengliqi

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@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. labels Feb 15, 2023
@SeaRise SeaRise self-requested a review February 15, 2023 02:43
dbms/src/Common/MPMCQueue.h Show resolved Hide resolved
dbms/src/Common/MPMCQueue.h Outdated Show resolved Hide resolved
dbms/src/Common/MPMCQueue.h Outdated Show resolved Hide resolved
@windtalker windtalker force-pushed the mpmc_queue_support_auxiliary_memory_bound branch from 7383faa to c021cb9 Compare February 15, 2023 03:29
@@ -436,6 +472,7 @@ class MPMCQueue
Int64 write_pos = 0;
Status status = Status::NORMAL;
String cancel_reason;
size_t current_auxiliary_memory_usage = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use Int64 here to avoid incorrect get_auxiliary_memory_usage case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 331 to 332
if (is_timeout)
return Result::TIMEOUT;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (is_timeout)
return Result::TIMEOUT;
if constexpr (need_wait)
{
if (is_timeout)
return Result::TIMEOUT;
}

Comment on lines 379 to 380
if (is_timeout)
return Result::TIMEOUT;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

}
if (!isCancelled() && read_pos < write_pos)
{
auto & obj = getObj(read_pos);
res = std::move(obj);
destruct(obj);
current_auxiliary_memory_usage -= get_auxiliary_memory_usage(res);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a little wasteful to call get_auxiliary_memory_usage twice for one object.
And also it requires that these two return values of get_auxiliary_memory_usage must be the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, save auxiliary_memory in another vector.

@windtalker windtalker force-pushed the mpmc_queue_support_auxiliary_memory_bound branch from c6db9b5 to 3f397ba Compare February 15, 2023 07:21
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 15, 2023
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
Copy link
Contributor

@SeaRise SeaRise left a comment

Choose a reason for hiding this comment

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

Others LGTM

Comment on lines 468 to 469
current_auxiliary_memory_usage -= element_auxiliary_memory[pos % capacity];
element_auxiliary_memory[pos % capacity] = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
current_auxiliary_memory_usage -= element_auxiliary_memory[pos % capacity];
element_auxiliary_memory[pos % capacity] = 0;
auto & elem_value = element_auxiliary_memory[pos % capacity];
current_auxiliary_memory_usage -= elem_value;
elem_value = 0;

dbms/src/Common/MPMCQueue.h Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Feb 16, 2023
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
@windtalker windtalker force-pushed the mpmc_queue_support_auxiliary_memory_bound branch from 8b77e85 to aed9719 Compare February 16, 2023 03:24
@windtalker
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

@windtalker: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

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.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: aed9719

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Feb 16, 2023
@ti-chi-bot ti-chi-bot merged commit f2abf0c into pingcap:master Feb 16, 2023
@windtalker windtalker deleted the mpmc_queue_support_auxiliary_memory_bound branch May 6, 2023 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants