-
Notifications
You must be signed in to change notification settings - Fork 725
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
resource_manager: implement token assignment in server #5809
Merged
ti-chi-bot
merged 12 commits into
tikv:master
from
CabinfeverB:resource-manager/server_part3
Jan 10, 2023
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ca83b1d
impl token request
CabinfeverB 321c2ad
impl token request and fix update bug
CabinfeverB 0fc2ca5
add test
CabinfeverB ef25725
address comment
CabinfeverB 6a13cab
address comment
CabinfeverB 2d2fc55
merge master
CabinfeverB 887d221
merge master
CabinfeverB d5aa646
address comment
CabinfeverB 5fb09c9
address comment
CabinfeverB fc04c44
address comment
CabinfeverB 3896b95
address comment
CabinfeverB 3865ab3
Merge branch 'master' into resource-manager/server_part3
ti-chi-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2022 TiKV Project Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS,g | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package server | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
"time" | ||
|
||
rmpb "github.com/pingcap/kvproto/pkg/resource_manager" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGroupTokenBucketUpdateAndPatch(t *testing.T) { | ||
re := require.New(t) | ||
tbSetting := &rmpb.TokenBucket{ | ||
Tokens: 200000, | ||
Settings: &rmpb.TokenLimitSettings{ | ||
FillRate: 2000, | ||
BurstLimit: 20000000, | ||
}, | ||
} | ||
|
||
tb := NewGroupTokenBucket(tbSetting) | ||
time1 := time.Now() | ||
tb.request(time1, 0, 0) | ||
re.LessOrEqual(math.Abs(tbSetting.Tokens-tb.Tokens), 1e-7) | ||
re.Equal(tbSetting.Settings.FillRate, tb.Settings.FillRate) | ||
|
||
tbSetting = &rmpb.TokenBucket{ | ||
Tokens: -100000, | ||
Settings: &rmpb.TokenLimitSettings{ | ||
FillRate: 1000, | ||
BurstLimit: 10000000, | ||
}, | ||
} | ||
tb.patch(tbSetting) | ||
|
||
time2 := time.Now() | ||
tb.request(time2, 0, 0) | ||
re.LessOrEqual(math.Abs(100000-tb.Tokens), time2.Sub(time1).Seconds()*float64(tbSetting.Settings.FillRate)+1e7) | ||
re.Equal(tbSetting.Settings.FillRate, tb.Settings.FillRate) | ||
} | ||
|
||
func TestGroupTokenBucketRequest(t *testing.T) { | ||
re := require.New(t) | ||
tbSetting := &rmpb.TokenBucket{ | ||
Tokens: 200000, | ||
Settings: &rmpb.TokenLimitSettings{ | ||
FillRate: 2000, | ||
BurstLimit: 20000000, | ||
}, | ||
} | ||
|
||
gtb := NewGroupTokenBucket(tbSetting) | ||
time1 := time.Now() | ||
tb, trickle := gtb.request(time1, 100000, uint64(time.Second)*10/uint64(time.Millisecond)) | ||
re.LessOrEqual(math.Abs(tb.Tokens-100000), 1e-7) | ||
re.Equal(trickle, int64(0)) | ||
// need to lend token | ||
tb, trickle = gtb.request(time1, 101000, uint64(time.Second)*10/uint64(time.Millisecond)) | ||
re.LessOrEqual(math.Abs(tb.Tokens-101000), 1e-7) | ||
re.Equal(trickle, int64(time.Second)*10/int64(time.Millisecond)) | ||
tb, trickle = gtb.request(time1, 35000, uint64(time.Second)*10/uint64(time.Millisecond)) | ||
re.LessOrEqual(math.Abs(tb.Tokens-35000), 1e-7) | ||
re.Equal(trickle, int64(time.Second)*10/int64(time.Millisecond)) | ||
tb, trickle = gtb.request(time1, 60000, uint64(time.Second)*10/uint64(time.Millisecond)) | ||
re.LessOrEqual(math.Abs(tb.Tokens-22000), 1e-7) | ||
re.Equal(trickle, int64(time.Second)*10/int64(time.Millisecond)) | ||
tb, trickle = gtb.request(time1, 3000, uint64(time.Second)*10/uint64(time.Millisecond)) | ||
re.LessOrEqual(math.Abs(tb.Tokens-2000), 1e-7) | ||
re.Equal(trickle, int64(time.Second)*10/int64(time.Millisecond)) | ||
tb, trickle = gtb.request(time1, 3000, uint64(time.Second)*10/uint64(time.Millisecond)) | ||
re.LessOrEqual(math.Abs(tb.Tokens-1000), 1e-7) | ||
re.Equal(trickle, int64(time.Second)*10/int64(time.Millisecond)) | ||
time2 := time1.Add(10 * time.Second) | ||
tb, trickle = gtb.request(time2, 20000, uint64(time.Second)*10/uint64(time.Millisecond)) | ||
re.LessOrEqual(math.Abs(tb.Tokens-19000), 1e-7) | ||
re.Equal(trickle, int64(time.Second)*10/int64(time.Millisecond)) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.