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

filter: replace region.Clone in filter #2794

Merged
merged 5 commits into from
Aug 19, 2020

Conversation

Yisaer
Copy link
Contributor

@Yisaer Yisaer commented Aug 18, 2020

Signed-off-by: Song Gao disxiaofei@163.com

What problem does this PR solve?

ref #2783

region.Clone consumes too much cpu resources.

What is changed and how it works?

replace region.Clone with a self-maintained clone function as FitRegion only need partial information of a region.

BenchmarkCloneRegionTest is using new clone method and BenchmarkCloneRegionTest2 is using region.Clone

$ go test -bench=. -run=none
goos: darwin
goarch: amd64
pkg: github.com/tikv/pd/server/schedule/filter
BenchmarkCloneRegionTest-4       4356267               267 ns/op
BenchmarkCloneRegionTest2-4       316604              3292 ns/op
PASS
ok      github.com/tikv/pd/server/schedule/filter       2.555s

Check List

Tests

  • Unit test

Related changes

  • Need to cherry-pick to the release branch

Release note

Signed-off-by: Song Gao <disxiaofei@163.com>
@Yisaer Yisaer added component/scheduler Scheduler logic. needs-cherry-pick-release-4.0 The PR needs to cherry pick to release-4.0 branch. labels Aug 18, 2020
@Yisaer Yisaer marked this pull request as draft August 18, 2020 13:37
Signed-off-by: Song Gao <disxiaofei@163.com>
@Yisaer Yisaer marked this pull request as ready for review August 18, 2020 13:43

// cloneRegion is used to replace region.Clone in filter which call the FitRegion,
// as FitRegion only needs partial information(startKey, endKey, peers, leader peer)
func cloneRegion(region *core.RegionInfo, opts ...core.RegionCreateOption) *core.RegionInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not clone the downPeers, pendingPeers? maybe rename to a suitable name?

Copy link
Contributor

Choose a reason for hiding this comment

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

How about createRegionForRuleFit(peers []*metapb.Peer, leader *metapb.Peer) *core.RegionInfo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nolouch currently FitRegion didn't consider the downPeers and pending peers, after discussed with @disksing , I create a tracking issue #2796

@disksing good advice, updated.

Signed-off-by: Song Gao <disxiaofei@163.com>
@Yisaer Yisaer requested a review from nolouch August 19, 2020 04:50
StoreId: leader.StoreId,
Role: leader.Role,
}
copyPeers := make([]*metapb.Peer, 0, len(peers))
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems we don't have to copy leader. And if the peer list is untouched, we don't need to copy it either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think for both ruleFitFilter and ruleLeaderFitFilter, they will both touch peers and leaders. I think it is necessary to copy peers and leaders either.

Copy link
Contributor

Choose a reason for hiding this comment

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

It makes sense.

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Aug 19, 2020
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.
BTW, How about the benchmark result?

@ti-srebot ti-srebot removed the status/LGT1 Indicates that a PR has LGTM 1. label Aug 19, 2020
@ti-srebot ti-srebot added the status/LGT2 Indicates that a PR has LGTM 2. label Aug 19, 2020
@Yisaer
Copy link
Contributor Author

Yisaer commented Aug 19, 2020

LGTM.
BTW, How about the benchmark result?

I updated the benchmark result in the description.

@ti-srebot ti-srebot added status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Aug 19, 2020
@lhy1024
Copy link
Contributor

lhy1024 commented Aug 19, 2020

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Aug 19, 2020
@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit a0eba9b into tikv:master Aug 19, 2020
ti-srebot pushed a commit to ti-srebot/pd that referenced this pull request Aug 19, 2020
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #2801

howardlau1999 pushed a commit to howardlau1999/pd that referenced this pull request Aug 20, 2020
Signed-off-by: Song Gao <disxiaofei@163.com>
ZenoTan pushed a commit to ZenoTan/pd that referenced this pull request Aug 24, 2020
Signed-off-by: Song Gao <disxiaofei@163.com>
Signed-off-by: ZenoTan <zenotan1998@gmail.com>
jyz0309 pushed a commit to jyz0309/pd that referenced this pull request Aug 24, 2020
Signed-off-by: Song Gao <disxiaofei@163.com>
jyz0309 pushed a commit to jyz0309/pd that referenced this pull request Aug 24, 2020
Signed-off-by: Song Gao <disxiaofei@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/scheduler Scheduler logic. needs-cherry-pick-release-4.0 The PR needs to cherry pick to release-4.0 branch. status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants