-
Notifications
You must be signed in to change notification settings - Fork 6k
disttask: task executor slot manager #49136
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
Changes from 26 commits
6295f58
eae2e5e
45e4b72
26e6254
66c50ed
bfc0084
6df88d1
908b65c
59db269
ff93eab
b69f291
f54e5d7
8809905
b57efc6
133f34b
e6006d1
0a72a54
4a0ef07
3c1beb9
8cc2e33
c640046
c442754
3781105
6392faf
7d9f45e
2003d2a
a34651f
06422f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,7 +267,8 @@ tools/bin/vfsgendev: | |
tools/bin/gotestsum: | ||
GOBIN=$(shell pwd)/tools/bin $(GO) install gotest.tools/[email protected] | ||
|
||
tools/bin/mockgen: | ||
# [email protected] is imcompatible with v0.3.0, so install it always. | ||
mockgen: | ||
GOBIN=$(shell pwd)/tools/bin $(GO) install go.uber.org/mock/[email protected] | ||
|
||
# Usage: | ||
|
@@ -375,17 +376,17 @@ br_compatibility_test_prepare: | |
br_compatibility_test: | ||
@cd br && tests/run_compatible.sh run | ||
|
||
mock_s3iface: tools/bin/mockgen | ||
mock_s3iface: mockgen | ||
tools/bin/mockgen -package mock github.com/aws/aws-sdk-go/service/s3/s3iface S3API > br/pkg/mock/s3iface.go | ||
|
||
# mock interface for lightning and IMPORT INTO | ||
mock_lightning: tools/bin/mockgen | ||
mock_lightning: mockgen | ||
tools/bin/mockgen -package mock github.com/pingcap/tidb/br/pkg/lightning/backend Backend,EngineWriter,TargetInfoGetter,ChunkFlushStatus > br/pkg/mock/backend.go | ||
tools/bin/mockgen -package mock github.com/pingcap/tidb/br/pkg/lightning/backend/encode Encoder,EncodingBuilder,Rows,Row > br/pkg/mock/encode.go | ||
tools/bin/mockgen -package mocklocal github.com/pingcap/tidb/br/pkg/lightning/backend/local DiskUsage,TiKVModeSwitcher > br/pkg/mock/mocklocal/local.go | ||
tools/bin/mockgen -package mock github.com/pingcap/tidb/br/pkg/utils TaskRegister > br/pkg/mock/task_register.go | ||
|
||
gen_mock: tools/bin/mockgen | ||
gen_mock: mockgen | ||
tools/bin/mockgen -package mock github.com/pingcap/tidb/pkg/disttask/framework/taskexecutor TaskTable,Pool,TaskExecutor,Extension > pkg/disttask/framework/mock/task_executor_mock.go | ||
tools/bin/mockgen -package mock github.com/pingcap/tidb/pkg/disttask/framework/scheduler Scheduler,CleanUpRoutine,TaskManager > pkg/disttask/framework/mock/scheduler_mock.go | ||
tools/bin/mockgen -package mock github.com/pingcap/tidb/pkg/disttask/framework/scheduler Extension > pkg/disttask/framework/scheduler/mock/scheduler_mock.go | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2023 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 taskexecutor | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/pingcap/tidb/pkg/disttask/framework/proto" | ||
) | ||
|
||
// slotManager is used to manage the slots of the executor. | ||
type slotManager struct { | ||
sync.RWMutex | ||
// taskID -> slotInfo | ||
executorSlotInfos map[int64]*slotInfo | ||
|
||
// The number of slots that can be used by the executor. | ||
// It is always equal to CPU cores of the instance. | ||
available int | ||
} | ||
|
||
type slotInfo struct { | ||
taskID int | ||
// priority will be used in future | ||
priority int | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better store task itself, priority itself cannot determine task order. ok to do it later |
||
slotCount int | ||
} | ||
|
||
func (sm *slotManager) alloc(task *proto.Task) { | ||
sm.Lock() | ||
defer sm.Unlock() | ||
sm.executorSlotInfos[task.ID] = &slotInfo{ | ||
taskID: int(task.ID), | ||
priority: task.Priority, | ||
slotCount: task.Concurrency, | ||
} | ||
|
||
sm.available -= task.Concurrency | ||
} | ||
|
||
func (sm *slotManager) free(taskID int64) { | ||
sm.Lock() | ||
defer sm.Unlock() | ||
|
||
slotInfo, ok := sm.executorSlotInfos[taskID] | ||
if ok { | ||
delete(sm.executorSlotInfos, taskID) | ||
sm.available += slotInfo.slotCount | ||
} | ||
} | ||
|
||
// canReserve is used to check whether the instance has enough slots to run the task. | ||
func (sm *slotManager) canAlloc(task *proto.Task) bool { | ||
sm.RLock() | ||
defer sm.RUnlock() | ||
|
||
return sm.available >= task.Concurrency | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sm.RLock? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} |
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.
if it's moved out, we have to free on error
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.
yes👍
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.
06422f4