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

core/region: use a separate tree to check for overlaps in the subtree #8185

Merged
merged 4 commits into from
May 17, 2024

Conversation

JmPotato
Copy link
Member

@JmPotato JmPotato commented May 16, 2024

What problem does this PR solve?

Issue Number: close #8136, ref #7897.

What is changed and how does it work?

Previously, removing overlapped regions in subtrees required finding overlaps for each subtree individually.
This PR introduces a separate tree specifically for checking overlaps in the subtrees, thereby reducing lookup times and improving performance.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
> go test -timeout=30m -count=3 -benchmem -bench=BenchmarkUpdateSubTreeOrderInsensitive . > new.txt
> git checkout master #59e29cca6a0c1acb191fa50b10ca080971b2a47a
> go test -timeout=30m -count=3 -benchmem -bench=BenchmarkUpdateSubTreeOrderInsensitive . > old.txt
> benchstat old.txt new.txt
goos: darwin
goarch: arm64
pkg: github.com/tikv/pd/pkg/core
                                                                               │    old.txt    │               new.txt               │
                                                                               │    sec/op     │    sec/op     vs base               │
UpdateSubTreeOrderInsensitive/from_empty_with_size_10-8                          10.561µ ±  0%   7.258µ ±  0%  -31.28% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_10-8         10.575µ ±  0%   7.293µ ±  2%  -31.04% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_10-8              20.48µ ± 25%   12.68µ ± 16%  -38.09% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_100-8                          269.2µ ±  1%   161.3µ ±  1%  -40.06% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_100-8         272.5µ ±  2%   161.5µ ±  0%  -40.72% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_100-8             328.5µ ±  7%   181.9µ ± 11%  -44.60% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_1000-8                         3.384m ±  2%   1.975m ±  1%  -41.65% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_1000-8        3.374m ±  0%   1.976m ±  1%  -41.45% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_1000-8            3.644m ±  4%   2.104m ±  1%  -42.27% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_10000-8                        36.38m ±  1%   21.01m ±  4%  -42.25% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_10000-8       36.41m ±  0%   21.03m ±  1%  -42.24% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_10000-8           38.18m ±  4%   21.93m ±  3%  -42.55% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_100000-8                       372.4m ±  2%   215.7m ±  0%  -42.09% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_100000-8      373.2m ±  1%   215.6m ±  0%  -42.24% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_100000-8          386.4m ±  2%   226.5m ±  6%  -41.38% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_1000000-8                       3.874 ±  2%    2.193 ±  1%  -43.39% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_1000000-8      3.886 ±  1%    2.194 ±  0%  -43.53% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_1000000-8          3.962 ±  3%    2.252 ±  2%  -43.17% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_10000000-8                      46.91 ±  6%    29.19 ±  7%  -37.78% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_10000000-8     46.97 ±  1%    29.34 ±  2%  -37.54% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_10000000-8         58.87 ± 17%    36.03 ± 20%  -38.79% (p=0.002 n=6)
geomean                                                                           32.26m         19.20m        -40.49%

                                                                               │    old.txt    │               new.txt                │
                                                                               │     B/op      │     B/op       vs base               │
UpdateSubTreeOrderInsensitive/from_empty_with_size_10-8                           1600.0 ±  0%     904.0 ±  0%  -43.50% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_10-8          1600.0 ±  0%     904.0 ±  0%  -43.50% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_10-8             3.009Ki ± 48%   2.547Ki ± 37%        ~ (p=0.180 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_100-8                         52.86Ki ±  0%   47.65Ki ±  0%   -9.87% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_100-8        52.86Ki ±  0%   47.65Ki ±  0%   -9.86% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_100-8            56.94Ki ± 16%   46.70Ki ± 11%  -17.99% (p=0.015 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_1000-8                        594.2Ki ±  0%   505.7Ki ±  0%  -14.89% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_1000-8       594.2Ki ±  0%   505.7Ki ±  0%  -14.89% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_1000-8           615.6Ki ±  5%   512.5Ki ±  6%  -16.76% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_10000-8                       6.001Mi ±  0%   5.020Mi ±  0%  -16.33% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_10000-8      6.001Mi ±  0%   5.020Mi ±  0%  -16.34% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_10000-8          5.960Mi ±  1%   4.979Mi ±  1%  -16.45% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_100000-8                      60.37Mi ±  0%   49.59Mi ±  0%  -17.86% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_100000-8     60.38Mi ±  0%   49.59Mi ±  0%  -17.86% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_100000-8         60.07Mi ±  1%   49.56Mi ±  1%  -17.49% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_1000000-8                     600.3Mi ±  0%   495.2Mi ±  0%  -17.51% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_1000000-8    600.4Mi ±  0%   495.2Mi ±  0%  -17.52% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_1000000-8        601.9Mi ±  0%   495.8Mi ±  0%  -17.62% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_10000000-8                    5.879Gi ±  0%   4.844Gi ±  0%  -17.61% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_10000000-8   5.879Gi ±  0%   4.844Gi ±  0%  -17.61% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_10000000-8       5.877Gi ±  0%   4.842Gi ±  0%  -17.60% (p=0.002 n=6)
geomean                                                                          4.990Mi         4.027Mi        -19.30%

                                                                               │   old.txt    │               new.txt               │
                                                                               │  allocs/op   │  allocs/op    vs base               │
UpdateSubTreeOrderInsensitive/from_empty_with_size_10-8                          103.00 ±  0%    60.00 ±  0%  -41.75% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_10-8         103.00 ±  0%    60.00 ±  0%  -41.75% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_10-8              198.5 ± 26%    107.0 ± 22%  -46.10% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_100-8                         2.308k ±  0%   1.392k ±  0%  -39.69% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_100-8        2.308k ±  0%   1.392k ±  0%  -39.69% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_100-8            2.671k ±  8%   1.419k ±  4%  -46.90% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_1000-8                        26.98k ±  0%   14.35k ±  0%  -46.82% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_1000-8       26.98k ±  0%   14.35k ±  0%  -46.82% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_1000-8           27.87k ±  4%   14.51k ±  2%  -47.96% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_10000-8                       276.5k ±  0%   145.1k ±  0%  -47.53% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_10000-8      276.5k ±  0%   145.1k ±  0%  -47.53% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_10000-8          275.9k ±  2%   144.9k ±  0%  -47.49% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_100000-8                      2.790M ±  0%   1.448M ±  0%  -48.07% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_100000-8     2.790M ±  0%   1.448M ±  0%  -48.08% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_100000-8         2.784M ±  0%   1.449M ±  0%  -47.93% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_1000000-8                     27.84M ±  0%   14.49M ±  0%  -47.95% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_1000000-8    27.84M ±  0%   14.49M ±  0%  -47.95% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_1000000-8        27.89M ±  0%   14.50M ±  0%  -48.02% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_empty_with_size_10000000-8                    278.9M ±  0%   145.0M ±  0%  -48.02% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_non-overlapped_regions_with_size_10000000-8   278.9M ±  0%   145.0M ±  0%  -48.02% (p=0.002 n=6)
UpdateSubTreeOrderInsensitive/from_overlapped_regions_with_size_10000000-8       278.9M ±  0%   145.0M ±  0%  -48.01% (p=0.002 n=6)
geomean                                                                          243.5k         130.6k        -46.36%

Release note

None.

@JmPotato JmPotato requested review from nolouch and rleungx May 16, 2024 15:42
Copy link
Contributor

ti-chi-bot bot commented May 16, 2024

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • nolouch
  • rleungx

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 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 May 16, 2024
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 16, 2024
Copy link

codecov bot commented May 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.32%. Comparing base (644e904) to head (cfa0d7a).
Report is 1 commits behind head on master.

Current head cfa0d7a differs from pull request most recent head f225511

Please upload reports for the commit f225511 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8185      +/-   ##
==========================================
- Coverage   77.40%   77.32%   -0.08%     
==========================================
  Files         471      471              
  Lines       61387    61354      -33     
==========================================
- Hits        47516    47443      -73     
- Misses      10309    10339      +30     
- Partials     3562     3572      +10     
Flag Coverage Δ
unittests 77.32% <100.00%> (-0.08%) ⬇️

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

// t3: thread-B: update subtree
// t4: thread-A: update region subtree
// to keep region tree consistent with subtree, we need to drop this update.
if tree, ok := r.subRegions[region.GetID()]; ok {
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 use the item or something else instead of a tree?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since there is no need to perform overlap checks on subtrees anymore, it is feasible to abandon the tree structure and adopt other simpler data structures. However, I prefer to carry out this modification separately after merging this PR due to the potentially significant changes.

@JmPotato JmPotato requested a review from rleungx May 17, 2024 06:10
@ti-chi-bot ti-chi-bot bot added the status/LGT1 Indicates that a PR has LGTM 1. label May 17, 2024
@rleungx
Copy link
Member

rleungx commented May 17, 2024

BTW, how much extra memory will it cost?

@JmPotato
Copy link
Member Author

JmPotato commented May 17, 2024

BTW, how much extra memory will it cost?

You can check the benchmark results in the PR description. It does not cause additional memory usage; on the contrary, it significantly reduces memory usage compared to the previous version.

Copy link
Contributor

@nolouch nolouch 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 status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels May 17, 2024
@JmPotato
Copy link
Member Author

/merge

Copy link
Contributor

ti-chi-bot bot commented May 17, 2024

@JmPotato: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

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 ti-community-infra/tichi repository.

Copy link
Contributor

ti-chi-bot bot commented May 17, 2024

This pull request has been accepted and is ready to merge.

Commit hash: aef4a7c

@ti-chi-bot ti-chi-bot bot added the status/can-merge Indicates a PR has been approved by a committer. label May 17, 2024
@nolouch
Copy link
Contributor

nolouch commented May 17, 2024

/merge

Copy link
Contributor

ti-chi-bot bot commented May 17, 2024

@nolouch: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

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 ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot bot merged commit 36a1fa2 into tikv:master May 17, 2024
15 checks passed
@JmPotato JmPotato deleted the sub_tree_overlap branch May 17, 2024 14:57
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/XL Denotes a PR that changes 500-999 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getOverlapRegionFromSubTreeLocked consume many cpu hold lock
4 participants