|
|
@@ -9,10 +9,11 @@ import ( |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
const ( |
|
|
const ( |
|
|
RUNNING_TASK_WEIGHT = 10 |
|
|
|
|
|
|
|
|
RUNNING_TASK_WEIGHT = 200 |
|
|
|
|
|
TASK_PREDICTED_WEIGHT = 0.03 |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type LoadPriority struct { |
|
|
|
|
|
|
|
|
type LeastLoadFirst struct { |
|
|
replicas int32 |
|
|
replicas int32 |
|
|
clusters []*CLusterLoad |
|
|
clusters []*CLusterLoad |
|
|
} |
|
|
} |
|
|
@@ -23,7 +24,7 @@ type CLusterLoad struct { |
|
|
TaskPredictedNum int64 |
|
|
TaskPredictedNum int64 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NewLoadPriority(replicas int32, resources []*collector.ResourceSpec) *LoadPriority { |
|
|
|
|
|
|
|
|
func NewLeastLoadFirst(replicas int32, resources []*collector.ResourceSpec) *LeastLoadFirst { |
|
|
var clusters []*CLusterLoad |
|
|
var clusters []*CLusterLoad |
|
|
|
|
|
|
|
|
for _, resource := range resources { |
|
|
for _, resource := range resources { |
|
|
@@ -53,7 +54,7 @@ func NewLoadPriority(replicas int32, resources []*collector.ResourceSpec) *LoadP |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
|
balance = b |
|
|
balance = b |
|
|
case storeLink.RATE: |
|
|
|
|
|
|
|
|
case strings.ToUpper(storeLink.RATE): |
|
|
rt, ok := r.Total.Value.(float64) |
|
|
rt, ok := r.Total.Value.(float64) |
|
|
if !ok { |
|
|
if !ok { |
|
|
continue |
|
|
continue |
|
|
@@ -73,17 +74,21 @@ func NewLoadPriority(replicas int32, resources []*collector.ResourceSpec) *LoadP |
|
|
clusters = append(clusters, cluster) |
|
|
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 { |
|
|
if l.replicas < 1 { |
|
|
return nil, errors.New("replicas must be greater than 0") |
|
|
return nil, errors.New("replicas must be greater than 0") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
swMap := make(map[string]int32, 0) |
|
|
swMap := make(map[string]int32, 0) |
|
|
for _, cluster := range l.clusters { |
|
|
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) |
|
|
swMap[cluster.ClusterId] = int32(weight) |
|
|
} |
|
|
} |
|
|
|
|
|
|