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

statistics: limit the batch size when updating the stats cache #57954

Merged
merged 5 commits into from
Dec 17, 2024

Conversation

winoros
Copy link
Member

@winoros winoros commented Dec 3, 2024

What problem does this PR solve?

Issue Number: close #57953

Problem Summary:

What changed and how does it work?

Add a middle layer to submit the update cache job more quickly.
Also memory is saved.

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

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 3, 2024
@winoros winoros added affects-8.5 This bug affects the 8.5.x(LTS) versions. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. and removed affects-8.5 This bug affects the 8.5.x(LTS) versions. labels Dec 3, 2024
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.1128%. Comparing base (d5b6b69) to head (f4616a4).
Report is 37 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #57954        +/-   ##
================================================
+ Coverage   73.1776%   75.1128%   +1.9352%     
================================================
  Files          1676       1728        +52     
  Lines        461995     475471     +13476     
================================================
+ Hits         338077     357140     +19063     
+ Misses       103156      96071      -7085     
- Partials      20762      22260      +1498     
Flag Coverage Δ
integration 49.2414% <100.0000%> (?)
unit 72.5106% <100.0000%> (+0.2087%) ⬆️

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

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

Options: t.option,
})
t.toUpdate = t.toUpdate[:0]
t.toDelete = t.toDelete[:0]
Copy link
Member

@hawkingrei hawkingrei Dec 4, 2024

Choose a reason for hiding this comment

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

clear(t.toDelete)

Copy link
Member Author

Choose a reason for hiding this comment

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

The clear seems to be reset to zero instead of reset the length.

// The clear built-in function clears maps and slices.
// For maps, clear deletes all entries, resulting in an empty map.
// For slices, clear sets all elements up to the length of the slice
// to the zero value of the respective element type. If the argument
// type is a type parameter, the type parameter's type set must
// contain only map or slice types, and clear performs the operation
// implied by the type argument.

Copy link
Member

@Rustin170506 Rustin170506 left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -65,6 +65,48 @@ func NewStatsCacheImplForTest() (types.StatsCache, error) {
return NewStatsCacheImpl(nil)
}

type tablesToUpdateOrDelete struct {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can call it cacheUpdateBatch?

Copy link
Member

Choose a reason for hiding this comment

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

I guess we can at least add some unit tests for this structure.

tables := make([]*statistics.Table, 0, len(rows))
deletedTableIDs := make([]int64, 0, len(rows))
tblToUpdateOrDelete := tablesToUpdateOrDelete{
toUpdate: make([]*statistics.Table, 0, min(len(rows), 10)),
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can use a const to reuse this magic number.

@winoros winoros force-pushed the small-batchsize-when-update-cache branch from b39b0fa to 875f45e Compare December 12, 2024 00:46
Copy link
Member

@Rustin170506 Rustin170506 left a comment

Choose a reason for hiding this comment

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

Thanks! :shipit:

I think adding tests for it is still valuable. But I think it shouldn't block the PR.

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 16, 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 Dec 16, 2024
Copy link

tiprow bot commented Dec 16, 2024

@winoros: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
fast_test_tiprow f4616a4 link true /test fast_test_tiprow

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

Copy link

ti-chi-bot bot commented Dec 17, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hawkingrei, Rustin170506

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 Dec 17, 2024
Copy link

ti-chi-bot bot commented Dec 17, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-12-16 09:51:45.722633589 +0000 UTC m=+864095.811436117: ☑️ agreed by Rustin170506.
  • 2024-12-17 06:28:57.847674209 +0000 UTC m=+938327.936476750: ☑️ agreed by hawkingrei.

@ti-chi-bot ti-chi-bot bot merged commit 8a80a41 into pingcap:master Dec 17, 2024
24 of 25 checks passed
@ti-chi-bot
Copy link
Member

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

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-8.5 Should cherry pick this PR to release-8.5 branch. release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner 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.

Update the stats cache batch by batch instead of updating once in periodic statistics update worker
4 participants