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: small refine of MergedTask. #8512

Merged
merged 3 commits into from
Dec 14, 2023

Conversation

JinheLin
Copy link
Contributor

What problem does this PR solve?

Issue Number: ref #6834

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 ti-chi-bot 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 Dec 13, 2023
@JinheLin
Copy link
Contributor Author

/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 13, 2023
@JinheLin
Copy link
Contributor Author

/run-integration-test

Comment on lines 79 to 82
bool allStreamsFinished() const
{
return std::all_of(units.begin(), units.end(), [](const auto & u) { return u.isFinished(); });
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this cause performance regression when there are multiple MergedUnits? Previously we only compare two size_t, now we need to iterate all units to get the result.

int read_count = 0;
while (!merged_task->allStreamsFinished() && !isStop())
{
auto c = merged_task->readBlock();
read_count += c;
if (c <= 0)
{
break;
}
}
if (read_count <= 0)
{
LOG_DEBUG(log, "All finished, merged_task=<{}> read_count={}", merged_task->toString(), read_count);
}
// If `merged_task` is pushed back to `MergedTaskPool`, it can be accessed by another read thread if it is scheduled.
// So do not push back to `MergedTaskPool` when exception happened since current read thread can still access to this `merged_task` object and set exception message to it.
// If exception happens, `merged_task` will be released by `shared_ptr` automatically.
if (!merged_task->allStreamsFinished())
{
SegmentReadTaskScheduler::instance().pushMergedTask(merged_task);
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Normally, size of units is small, such as 1, 2, or 3... In such cases, no performance hurted.

In extreme cases, its size is 100.

Currently, 100 is the limitation of the total number of merged segments, not for each MergedTask.

I think we should limit the size of each MergedTask too, such 5, because segments of a MergedTask is read sequentially. (This will be considered in another PR.)

if (MergedTask::getPassiveMergedSegments() < 100 || target->second.size() == 1)
{
result = *target;
merging_segments.erase(target);
}
else
{
result = std::pair{target->first, std::vector<uint64_t>(1, pool->pool_id)};
auto itr = std::find(target->second.begin(), target->second.end(), pool->pool_id);
*itr = target->second
.back(); // SegmentReadTaskPool::scheduleSegment ensures `pool->poolId` must exists in `target`.
target->second.resize(target->second.size() - 1);
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

However, keeping finished_count could be more effective in all scenarios. So I have added finished_count back.

@ti-chi-bot ti-chi-bot bot added the lgtm label Dec 14, 2023
Copy link
Contributor

ti-chi-bot bot commented Dec 14, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JaySon-Huang, 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 [JaySon-Huang,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 14, 2023
Copy link
Contributor

ti-chi-bot bot commented Dec 14, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-12-13 07:23:29.699874883 +0000 UTC m=+427300.737101809: ☑️ agreed by Lloyd-Pottiger.
  • 2023-12-14 05:34:07.255632585 +0000 UTC m=+507138.292859497: ☑️ agreed by JaySon-Huang.

@JaySon-Huang
Copy link
Contributor

/run-all-tests

@ti-chi-bot ti-chi-bot bot merged commit cfbf378 into pingcap:master Dec 14, 2023
6 checks passed
yibin87 pushed a commit to yibin87/tiflash that referenced this pull request Dec 15, 2023
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants