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

timer: make sure timer which has a max delay will be scheduled first #57067

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

lcwangchao
Copy link
Collaborator

@lcwangchao lcwangchao commented Nov 1, 2024

What problem does this PR solve?

Issue Number: close #57137

This issue is because a trigger action will be sent to the timer worker via the chan:

select {
case <-rt.ctx.Done():
return false
case worker.ch <- req:
rt.cache.setTimerProcStatus(timer.ID, procTriggering, eventID)
default:
if busyWorkers == nil {
busyWorkers = make(map[string]struct{})
}
busyWorkers[timer.HookClass] = struct{}{}
retryTimerIDs = append(retryTimerIDs, timer.ID)
retryTimerKeys = append(retryTimerKeys, fmt.Sprintf("[%s] %s", timer.Namespace, timer.Key))
}
return true
})

If the chan is full, it will fail and retry after a while. However, some tables always have lower priorities even if they are not triggered for a long time.

What changed and how does it work?

reorder timers by nextEventTime before sending them to workers to make sure the timer which has a max delay will be handled first to avoid starvation

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

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

Please refer to Release Notes Language Style Guide to write a quality release note.

ttl: fix some times TTL job can not be scheduled when there are a lot of TTL tables.

@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. do-not-merge/needs-tests-checked size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 1, 2024
Copy link

tiprow bot commented Nov 1, 2024

Hi @lcwangchao. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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 kubernetes-sigs/prow repository.

@lcwangchao lcwangchao marked this pull request as draft November 1, 2024 07:26
@ti-chi-bot ti-chi-bot bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 1, 2024
@lcwangchao lcwangchao force-pushed the opt_ttl branch 2 times, most recently from f82bd79 to da31f68 Compare November 5, 2024 11:38
@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/needs-linked-issue do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. labels Nov 5, 2024
@lcwangchao lcwangchao changed the title ttl: optimize ttl timer: make sure timer which has a max delay will be scheduled first Nov 5, 2024
@lcwangchao lcwangchao marked this pull request as ready for review November 5, 2024 11:53
@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 Nov 5, 2024
@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 Nov 5, 2024
Copy link

codecov bot commented Nov 5, 2024

Codecov Report

Attention: Patch coverage is 90.90909% with 3 lines in your changes missing coverage. Please review.

Project coverage is 56.7130%. Comparing base (8a62d5a) to head (8fd95e8).
Report is 10 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #57067         +/-   ##
=================================================
- Coverage   73.1889%   56.7130%   -16.4760%     
=================================================
  Files          1655       1783        +128     
  Lines        456297     645164     +188867     
=================================================
+ Hits         333959     365892      +31933     
- Misses       101822     254873     +153051     
- Partials      20516      24399       +3883     
Flag Coverage Δ
integration 37.1327% <12.1212%> (?)
unit 72.6090% <90.9090%> (+0.1383%) ⬆️

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

Components Coverage Δ
dumpling 52.9478% <ø> (ø)
parser ∅ <ø> (∅)
br 52.4466% <ø> (+6.7274%) ⬆️

Copy link
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Nov 6, 2024
Copy link
Member

@YangKeao YangKeao left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

ti-chi-bot bot commented Nov 6, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bb7133, YangKeao

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:

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 Nov 6, 2024
Copy link

ti-chi-bot bot commented Nov 6, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-11-06 03:02:46.569458133 +0000 UTC m=+1010079.408613678: ☑️ agreed by bb7133.
  • 2024-11-06 04:15:32.10079388 +0000 UTC m=+1014444.939949418: ☑️ agreed by YangKeao.

@ti-chi-bot ti-chi-bot bot merged commit 69e8fdb into pingcap:master Nov 6, 2024
23 checks passed
@lcwangchao lcwangchao deleted the opt_ttl branch November 6, 2024 05:44
@lcwangchao lcwangchao added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Nov 6, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #57157.

@ti-chi-bot ti-chi-bot bot added needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. labels Nov 6, 2024
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Nov 6, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #57158.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #57159.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TTL table may not have change to schedule when the whole TTL schedule is heavy
4 participants