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

Optimize heartbeat - async process statistics #7898

Closed
wants to merge 1 commit into from

Conversation

nolouch
Copy link
Contributor

@nolouch nolouch commented Mar 7, 2024

What problem does this PR solve?

Issue Number: Ref #7897

What is changed and how does it work?

Optimize heartbeat process
- Introduce `SyncRunner` and `AsyncRunner`
- Async the statics updates on subtree

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

Before:
image
image

After:
image
image

The duration of the pending state on tikvs has been reduced from 10 minutes to 3 minutes

Release note

None.

Copy link
Contributor

ti-chi-bot bot commented Mar 7, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Mar 7, 2024
Copy link
Contributor

ti-chi-bot bot commented Mar 7, 2024

[REVIEW NOTIFICATION]

This pull request has not been approved.

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 bot requested review from disksing and rleungx March 7, 2024 17:44
@ti-chi-bot ti-chi-bot bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Mar 7, 2024
@nolouch nolouch force-pushed the optmize-heartbeat branch 2 times, most recently from 193c2b5 to b3c59b1 Compare March 20, 2024 10:15
@nolouch nolouch marked this pull request as ready for review March 20, 2024 10:18
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 20, 2024
@nolouch nolouch changed the title [Draft] Optimize heartbeat - async process statistics Optimize heartbeat - async process statistics Mar 20, 2024
@nolouch nolouch requested review from JmPotato and CabinfeverB and removed request for disksing March 20, 2024 10:34
@nolouch nolouch force-pushed the optmize-heartbeat branch 3 times, most recently from 0ef7f0d to 25e0c99 Compare March 21, 2024 02:43
Copy link

codecov bot commented Mar 21, 2024

Codecov Report

Merging #7898 (ac40311) into master (1331148) will increase coverage by 0.11%.
Report is 7 commits behind head on master.
The diff coverage is 82.42%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7898      +/-   ##
==========================================
+ Coverage   73.47%   73.58%   +0.11%     
==========================================
  Files         436      437       +1     
  Lines       48349    48642     +293     
==========================================
+ Hits        35523    35793     +270     
- Misses       9765     9787      +22     
- Partials     3061     3062       +1     
Flag Coverage Δ
unittests 73.58% <82.42%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Comment on lines +65 to +67
if opt.Limit != nil {
token, err = opt.Limit.Acquire(ctx)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if opt.Limit != nil {
token, err = opt.Limit.Acquire(ctx)
}
token, err = opt.Limit.Acquire(ctx)

runner.RunTask(
ctx,
ratelimit.TaskOpts{
TaskName: "UpdateSubTree",
Copy link
Member

Choose a reason for hiding this comment

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

Should we put all the tasknames into a constant list?


func (s *AsyncRunner) recover() {
if r := recover(); r != nil {
log.Error("panic in runner", zap.Any("error", r))
Copy link
Member

Choose a reason for hiding this comment

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

Should we add more information? such as task name.

return overlaps, nil
}

// CheckAndPutSupTree checks if the region is valid to put to the root, if valid then return error.
// Usually used with CheckAndPutSubTree together.
func (r *RegionsInfo) CheckAndPutSupTree(ctx context.Context, region *RegionInfo) ([]*RegionInfo, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func (r *RegionsInfo) CheckAndPutSupTree(ctx context.Context, region *RegionInfo) ([]*RegionInfo, error) {
func (r *RegionsInfo) CheckAndPutSubTree(ctx context.Context, region *RegionInfo) ([]*RegionInfo, error) {

l.mu.RLock()
defer l.mu.RUnlock()
func (l *ConcurrencyLimiter) getCurrent() uint64 {
l.mu.Lock()
Copy link
Member

Choose a reason for hiding this comment

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

why change it?


// GetWaitingTasksNum returns the number of waiting tasks.
func (l *ConcurrencyLimiter) GetWaitingTasksNum() uint64 {
l.mu.Lock()
Copy link
Member

Choose a reason for hiding this comment

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

rlock?

@@ -0,0 +1,114 @@
// Copyright 2022 TiKV Project Authors.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Copyright 2022 TiKV Project Authors.
// Copyright 2024 TiKV Project Authors.

if opt.Limit != nil && atomic.LoadInt64(&s.numTasks) >= int64(s.maxPendingTasks) {
return ErrMaxWaitingTasksExceeded
}
s.addTask(1)
Copy link
Member

Choose a reason for hiding this comment

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

Will it keep adding without executing the defer?

@nolouch
Copy link
Contributor Author

nolouch commented Apr 9, 2024

will split this pr, close.

@nolouch nolouch closed this Apr 9, 2024
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants