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

executor: tiny optimize index-lookup query performance by reuse lite-cop-worker. #58586

Merged
merged 5 commits into from
Dec 31, 2024

Conversation

crazycs520
Copy link
Contributor

@crazycs520 crazycs520 commented Dec 27, 2024

What problem does this PR solve?

Issue Number: ref #56649

Problem Summary:

What changed and how does it work?

Try to reuse lite-cop-worker.

Before this PR

image

This PR, the tableWorker of IndexLookUpExecutor can use lite-cop-worker to reduce consumption.

image
version workload thread QPS QPS Increase
master oltp_index_lookup 100 26522  
This PR oltp_index_lookup 100 27158 2.4%
master oltp_index_lookup 150 26985  
This PR oltp_index_lookup 150 28290 4.8%

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.

None

Signed-off-by: crazycs520 <[email protected]>
@crazycs520 crazycs520 added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 27, 2024
@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Dec 27, 2024
Copy link

tiprow bot commented Dec 27, 2024

Hi @crazycs520. 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.

Copy link

codecov bot commented Dec 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.0188%. Comparing base (fc3c894) to head (cc6e30b).
Report is 40 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #58586        +/-   ##
================================================
+ Coverage   73.5297%   74.0188%   +0.4890%     
================================================
  Files          1680       1680                
  Lines        464567     469898      +5331     
================================================
+ Hits         341595     347813      +6218     
+ Misses       102120     101239       -881     
+ Partials      20852      20846         -6     
Flag Coverage Δ
integration 43.4604% <100.0000%> (?)
unit 72.7562% <100.0000%> (+0.4897%) ⬆️

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

Components Coverage Δ
dumpling 52.6910% <ø> (ø)
parser ∅ <ø> (∅)
br 45.8329% <ø> (+0.0763%) ⬆️

@crazycs520 crazycs520 changed the title executor: tiny optimize index-lookup query performance executor: tiny optimize index-lookup query performance by reuse lite-cop-worker. Dec 27, 2024
Signed-off-by: crazycs520 <[email protected]>
@ti-chi-bot ti-chi-bot bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 27, 2024
Signed-off-by: crazycs520 <[email protected]>
// Only one cop-reader can use lite worker. Using lite-worker in multiple readers will affect the concurrent execution of readers.
TryCopLiteWorker uint32
// Only one cop-reader can use lite worker at the same time. Using lite-worker in multiple readers will affect the concurrent execution of readers.
TryCopLiteWorker atomic.Uint32
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't use sync/atomic here, since

nogo: errors found by nogo during build-time code analysis:

pkg/distsql/context/context.go:105:12: assignment copies lock value to newCtx: github.com/pingcap/tidb/pkg/distsql/context.DistSQLContext contains sync/atomic.Uint32 contains sync/atomic.noCopy (copylocks)

Signed-off-by: crazycs520 <[email protected]>
Signed-off-by: crazycs520 <[email protected]>
@crazycs520 crazycs520 requested review from zyguan and you06 December 27, 2024 11:10
Copy link
Contributor

@zyguan zyguan left a comment

Choose a reason for hiding this comment

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

Great!

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Dec 27, 2024
@@ -1195,6 +1198,10 @@ func (w *liteCopIteratorWorker) liteSendReq(ctx context.Context, it *copIterator
} else {
it.tasks = it.tasks[1:]
}
if len(it.tasks) == 0 {
// if all tasks are finished, reset tryCopLiteWorker to 0 to make future request can reuse copLiteWorker.
w.tryCopLiteWorker.Store(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should CAS operation be used here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no need, just reset here.

@ti-chi-bot ti-chi-bot bot added approved lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 31, 2024
Copy link

ti-chi-bot bot commented Dec 31, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-12-27 12:02:17.532591247 +0000 UTC m=+92672.888595788: ☑️ agreed by zyguan.
  • 2024-12-31 07:35:35.963206695 +0000 UTC m=+422271.319211264: ☑️ agreed by cfzjywxk.

Copy link

ti-chi-bot bot commented Dec 31, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, hawkingrei, zyguan

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 merged commit de2b7ac into pingcap:master Dec 31, 2024
24 checks passed
@crazycs520 crazycs520 deleted the opt-index-lookup branch December 31, 2024 10:57
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/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants