Browse Source

update strategy

undefined
tzwang 11 months ago
parent
commit
d7b03ce173
3 changed files with 15 additions and 10 deletions
  1. +2
    -2
      internal/logic/schedule/schedulecreatetasklogic.go
  2. +12
    -7
      internal/scheduler/strategy/leastLoadFirst.go
  3. +1
    -1
      internal/scheduler/strategy/strategy.go

+ 2
- 2
internal/logic/schedule/schedulecreatetasklogic.go View File

@@ -90,8 +90,8 @@ func (l *ScheduleCreateTaskLogic) ScheduleCreateTask(req *types.CreateTaskReq) (
func getClusterInfosByStrategy(resources *types.JobResources) ([]*types.JobClusterInfo, error) {
var clusterInfos []*types.JobClusterInfo
switch resources.ScheduleStrategy {
case strategy.LOADPRIORITY:
_ = strategy.NewLoadPriority(TRAINNING_TASK_REPLICA, nil)
case strategy.LEASTLOADFIRST:
_ = strategy.NewLeastLoadFirst(TRAINNING_TASK_REPLICA, nil)
}

return clusterInfos, nil


internal/scheduler/strategy/loadPriority.go → internal/scheduler/strategy/leastLoadFirst.go View File

@@ -9,10 +9,11 @@ import (
)

const (
RUNNING_TASK_WEIGHT = 10
RUNNING_TASK_WEIGHT = 200
TASK_PREDICTED_WEIGHT = 0.03
)

type LoadPriority struct {
type LeastLoadFirst struct {
replicas int32
clusters []*CLusterLoad
}
@@ -23,7 +24,7 @@ type CLusterLoad struct {
TaskPredictedNum int64
}

func NewLoadPriority(replicas int32, resources []*collector.ResourceSpec) *LoadPriority {
func NewLeastLoadFirst(replicas int32, resources []*collector.ResourceSpec) *LeastLoadFirst {
var clusters []*CLusterLoad

for _, resource := range resources {
@@ -53,7 +54,7 @@ func NewLoadPriority(replicas int32, resources []*collector.ResourceSpec) *LoadP
continue
}
balance = b
case storeLink.RATE:
case strings.ToUpper(storeLink.RATE):
rt, ok := r.Total.Value.(float64)
if !ok {
continue
@@ -73,17 +74,21 @@ func NewLoadPriority(replicas int32, resources []*collector.ResourceSpec) *LoadP
clusters = append(clusters, cluster)
}

return &LoadPriority{replicas: replicas, clusters: clusters}
return &LeastLoadFirst{replicas: replicas, clusters: clusters}
}

func (l *LoadPriority) Schedule() ([]*AssignedCluster, error) {
func (l *LeastLoadFirst) Schedule() ([]*AssignedCluster, error) {
if l.replicas < 1 {
return nil, errors.New("replicas must be greater than 0")
}

swMap := make(map[string]int32, 0)
for _, cluster := range l.clusters {
weight := cluster.TaskRunningNum*RUNNING_TASK_WEIGHT + cluster.TaskPredictedNum
var runningTaskWeight int64
if cluster.TaskRunningNum != 0 {
runningTaskWeight = RUNNING_TASK_WEIGHT / cluster.TaskRunningNum
}
weight := runningTaskWeight + int64(float64(cluster.TaskPredictedNum)*TASK_PREDICTED_WEIGHT)
swMap[cluster.ClusterId] = int32(weight)
}


+ 1
- 1
internal/scheduler/strategy/strategy.go View File

@@ -8,7 +8,7 @@ const (
RANDOM = "random"
DATA_LOCALITY = "dataLocality" //感知数据位置,数据调度和计算调度协同,近数据调度
ENERGY_CONSUMPTION = "energyConsumption" //根据各集群总体能耗水平调度作业,优先选择能耗低的集群调度作业
LOADPRIORITY = "loadPriority"
LEASTLOADFIRST = "leastLoadFirst"
)

var (


Loading…
Cancel
Save