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

util: add dynamic goroutine pool #37388

Open
wants to merge 117 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
74ec2ac
util: add dynamic goroutine pool
hawkingrei Aug 25, 2022
1d1195e
*: upgrade test
hawkingrei Oct 11, 2022
aad4705
just test
hawkingrei Oct 13, 2022
dbf4b6d
just test
hawkingrei Oct 13, 2022
fb2c495
update
hawkingrei Oct 13, 2022
0bd98ff
*: add AddProduceBySlice
hawkingrei Oct 17, 2022
536edb1
*: add AddProduceBySlice
hawkingrei Oct 17, 2022
fb2955f
tmp save please remove today
hawkingrei Oct 17, 2022
78b0787
tmp save please remove today
hawkingrei Oct 17, 2022
e83e881
*: refactor task options
hawkingrei Oct 18, 2022
e6dd87a
add contextFunc
hawkingrei Oct 18, 2022
b4c991d
add contextFunc
hawkingrei Oct 18, 2022
b3542f2
update
hawkingrei Oct 19, 2022
ef3da03
update
hawkingrei Oct 19, 2022
e9e882e
bazel: update config and nogo
hawkingrei Oct 19, 2022
ea21f40
*: use strings.Cut
hawkingrei Oct 19, 2022
34ed79a
update
hawkingrei Oct 19, 2022
ca8ad28
update
hawkingrei Oct 20, 2022
73c0fb6
update
hawkingrei Oct 20, 2022
24aa78b
add contextFunc to addproduce
hawkingrei Oct 25, 2022
7133d9c
*: fix linter
hawkingrei Oct 25, 2022
a153b58
*: fix linter
hawkingrei Oct 25, 2022
a3b7728
update image 20221025
hawkingrei Oct 25, 2022
743a203
fix create task invaild pointer
hawkingrei Oct 26, 2022
add11ee
*: update spmc pool
hawkingrei Oct 29, 2022
e07af1e
update
hawkingrei Nov 1, 2022
e688d01
update
hawkingrei Nov 1, 2022
9aa5947
update
hawkingrei Nov 1, 2022
e55cece
add register for ResourceManage
hawkingrei Nov 1, 2022
c25694b
u
hawkingrei Nov 1, 2022
efd831d
u
hawkingrei Nov 1, 2022
1a2f67a
u
hawkingrei Nov 2, 2022
f501d5a
refactor again
hawkingrei Nov 3, 2022
569d0ee
refactor again
hawkingrei Nov 3, 2022
2f9cb6a
remove useless log
hawkingrei Nov 10, 2022
666e9a0
update
hawkingrei Nov 10, 2022
77c26c3
update
hawkingrei Nov 10, 2022
ad497ea
upgrade 1.19
hawkingrei Nov 10, 2022
46c90dc
u
hawkingrei Nov 12, 2022
d0d126d
u
hawkingrei Nov 12, 2022
4134500
update
hawkingrei Nov 13, 2022
a57db0f
update
hawkingrei Nov 13, 2022
7d8f4e7
update
hawkingrei Nov 13, 2022
8e7e054
update
hawkingrei Nov 14, 2022
998ab4c
update
hawkingrei Nov 14, 2022
bb63888
update
hawkingrei Nov 14, 2022
279246c
update
hawkingrei Nov 14, 2022
2527a7a
update
hawkingrei Nov 14, 2022
4bd695e
add more static
hawkingrei Nov 17, 2022
732cc1d
add more static
hawkingrei Nov 17, 2022
377acaf
add more static
hawkingrei Nov 17, 2022
50f70ed
add more static
hawkingrei Nov 17, 2022
4ec9f6a
add more static
hawkingrei Nov 17, 2022
b2f31db
add more static
hawkingrei Nov 18, 2022
ea3139e
update resource management
hawkingrei Nov 18, 2022
e075811
improve
hawkingrei Nov 19, 2022
8354555
improve
hawkingrei Nov 20, 2022
3a7be27
improve
hawkingrei Nov 20, 2022
037c998
improve
hawkingrei Nov 20, 2022
25fc83d
improve
hawkingrei Nov 21, 2022
ccb3267
improve
hawkingrei Nov 21, 2022
538b6fe
improve
hawkingrei Nov 21, 2022
92969ad
fix linter
hawkingrei Nov 22, 2022
2edc988
fix linter
hawkingrei Nov 22, 2022
1781d8a
linter: add timeformat for vet
hawkingrei Nov 23, 2022
0ce4169
linter: add timeformat for vet
hawkingrei Nov 23, 2022
70adb79
improve
hawkingrei Nov 24, 2022
8cad3d9
improve
hawkingrei Nov 24, 2022
e8098b4
improve
hawkingrei Nov 24, 2022
cf7fd43
improve
hawkingrei Nov 24, 2022
d367118
update
hawkingrei Nov 30, 2022
f309e8d
update
hawkingrei Nov 30, 2022
5c5bcf7
update
hawkingrei Nov 30, 2022
39b569d
update
hawkingrei Dec 2, 2022
fc941d5
update
hawkingrei Dec 2, 2022
e7555a9
update
hawkingrei Dec 2, 2022
b9f7cad
update
hawkingrei Dec 2, 2022
1c5c37d
update
hawkingrei Dec 2, 2022
4775fc2
update
hawkingrei Dec 2, 2022
a245985
upgrade
hawkingrei Dec 3, 2022
78c4b7a
upgrade
hawkingrei Dec 3, 2022
7edde44
update
hawkingrei Dec 5, 2022
6efe90e
update
hawkingrei Dec 5, 2022
c5127b0
update
hawkingrei Dec 5, 2022
728aabd
update
hawkingrei Dec 5, 2022
35905f5
update
hawkingrei Dec 5, 2022
309ffbc
update
hawkingrei Dec 5, 2022
556b569
update
hawkingrei Dec 5, 2022
77e2088
util: add basic gpool
hawkingrei Dec 8, 2022
852f450
util: add basic gpool
hawkingrei Dec 8, 2022
a75ceb8
util: add basic gpool
hawkingrei Dec 8, 2022
e109ae6
util: add basic gpool
hawkingrei Dec 8, 2022
53962d1
util: add basic gpool
hawkingrei Dec 8, 2022
9b29554
util: add basic gpool
hawkingrei Dec 8, 2022
e145b85
util: add basic gpool
hawkingrei Dec 8, 2022
fd4e347
util: add basic gpool
hawkingrei Dec 8, 2022
cebae69
util: add basic gpool
hawkingrei Dec 8, 2022
fc9369a
update commit
hawkingrei Dec 8, 2022
0e54591
update commit
hawkingrei Dec 8, 2022
b0be7a2
refactor
hawkingrei Dec 8, 2022
248d7b8
refactor
hawkingrei Dec 8, 2022
e38943a
refactor
hawkingrei Dec 8, 2022
fe74705
upgrade
hawkingrei Dec 8, 2022
f02e29d
refactor
hawkingrei Dec 8, 2022
baf94d4
*: close recordset
hawkingrei Dec 9, 2022
7d97636
*: upgrade
hawkingrei Dec 9, 2022
151692f
*: upgrade
hawkingrei Dec 9, 2022
2afd711
update test
hawkingrei Dec 13, 2022
6104a5c
update test
hawkingrei Dec 13, 2022
341c9f3
improve code
hawkingrei Dec 15, 2022
e7a6746
improve code
hawkingrei Dec 22, 2022
ddd75a0
improve code
hawkingrei Dec 22, 2022
d3206a8
bazel update
hawkingrei Jan 4, 2023
0a0d3e7
bazel update
hawkingrei Jan 4, 2023
eaba179
fix bazel
hawkingrei Jan 5, 2023
46456e3
fix bazel
hawkingrei Jan 5, 2023
6e51dbc
fix bazel
hawkingrei Jan 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build/linter/allrevive/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var defaultRules = []lint.Rule{
&rule.TimeNamingRule{},
//&rule.ContextKeysType{},
&rule.ContextAsArgumentRule{},
&rule.ReceiverNamingRule{},
}

var allRules = append([]lint.Rule{
Expand Down Expand Up @@ -118,6 +119,7 @@ var allRules = append([]lint.Rule{
&rule.TimeEqualRule{},
//&rule.BannedCharsRule{},
&rule.OptimizeOperandsOrderRule{},
&rule.ReceiverNamingRule{},
}, defaultRules...)

func run(pass *analysis.Pass) (any, error) {
Expand Down
2 changes: 2 additions & 0 deletions build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"util/etcd/": "util/etcd/ code",
"util/expensivequery/": "util/expensivequery/ code",
"util/filter/": "util/filter/ code",
"util/gpool/": "util/gpool/ code",
"util/importer/": "util/importer/ code",
"util/keydecoder/": "util/keydecoder/ code",
"util/kvcache/": "util/kvcache/ code",
Expand Down Expand Up @@ -377,6 +378,7 @@
"dumpling/export": "dumpling/export code",
"lock/": "lock file",
"errno/": "errno code",
"resourcemanage/": "resourcemanage code",
"structure/": "structure code",
"telemetry/": "telemetry code",
"planner/memo": "planner code",
Expand Down
1 change: 1 addition & 0 deletions resourcemanager/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ go_library(
importpath = "github.com/pingcap/tidb/resourcemanager",
visibility = ["//visibility:public"],
deps = [
"//resourcemanager/limiter",
"//resourcemanager/scheduler",
"//resourcemanager/util",
"//util",
Expand Down
15 changes: 15 additions & 0 deletions resourcemanager/limiter/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "limiter",
srcs = [
"bbr_limiter.go",
"limiter.go",
],
importpath = "github.com/pingcap/tidb/resourcemanager/limiter",
visibility = ["//visibility:public"],
deps = [
"//resourcemanager/util",
"//util/cpu",
],
)
66 changes: 66 additions & 0 deletions resourcemanager/limiter/bbr_limiter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2022 PingCAP, Inc.
//
// 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,
// 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 limiter

import (
"time"

"github.com/pingcap/tidb/resourcemanager/util"
"github.com/pingcap/tidb/util/cpu"
)

// BBRLimiter is a limiter based on cpu usage.
type BBRLimiter struct {
cpuThreshold int64
}

// NewBBRLimiter is to create a bbr limiter.
func NewBBRLimiter(cpuThreshold int64) Limiter {
return &BBRLimiter{
cpuThreshold: cpuThreshold,
}
}

// Limit is to limit the goroutine pool.
func (b *BBRLimiter) Limit(_ util.Component, p util.GorotinuePool) bool {
usage := cpu.GetCPUUsage() * 100
if usage < float64(b.cpuThreshold) {
// current cpu payload below the threshold
prevDropTime := p.LastTunerTs()
if prevDropTime.IsZero() {
// haven't start drop,
// accept current request
return false
}
if time.Since(prevDropTime) <= time.Second {
// just start drop one second ago,
// check current inflight count
inFlight := p.InFlight()
return inFlight > 1 && inFlight > p.MaxInFlight()
}
return false
}
// current cpu payload exceeds the threshold
inFlight := p.InFlight()
drop := inFlight > 1 && inFlight > p.MaxInFlight()
if drop {
prevDropTime := p.LastTunerTs()
if prevDropTime.IsZero() {
// already started drop, return directly
return drop
}
}
return drop
}
31 changes: 31 additions & 0 deletions resourcemanager/limiter/limiter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2022 PingCAP, Inc.
//
// 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,
// 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 limiter

import (
"github.com/pingcap/tidb/resourcemanager/util"
)

// Limiter is a limiter interface
type Limiter interface {
Limit(component util.Component, p util.GorotinuePool) bool
}

// NewLimiter is to create a default collection of limiter.
func NewLimiter() []Limiter {
return []Limiter{
NewBBRLimiter(80),
}
}
23 changes: 21 additions & 2 deletions resourcemanager/pooltask/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "pooltask",
srcs = ["task.go"],
srcs = [
"stat.go",
"task.go",
"task_manager.go",
"task_manager_iterator.go",
"task_manager_scheduler.go",
],
importpath = "github.com/pingcap/tidb/resourcemanager/pooltask",
visibility = ["//visibility:public"],
deps = [
"//util",
"//util/mathutil",
"//util/window",
"@org_golang_x_sys//cpu",
"@org_uber_go_atomic//:atomic",
],
)

go_test(
name = "pooltask_test",
srcs = ["task_test.go"],
embed = [":pooltask"],
)
Loading