mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
scheduler: make schedtag prefer and avoid strategy work
This commit is contained in:
@@ -27,7 +27,7 @@ func (p *AvoidSameHostPriority) Map(u *core.Unit, c core.Candidater) (core.HostP
|
||||
|
||||
ownerTenantID := u.SchedData().OwnerTenantID
|
||||
if count, ok := hc.Tenants[ownerTenantID]; ok && count > 0 {
|
||||
h.SetScore(-50 * int(count))
|
||||
h.SetFrontRawScore(-1 * int(count))
|
||||
}
|
||||
|
||||
return h.GetResult()
|
||||
|
||||
@@ -21,7 +21,7 @@ func (p *CapacityPriority) Map(u *core.Unit, c core.Candidater) (core.HostPriori
|
||||
h := priorities.NewPriorityHelper(p, u, c)
|
||||
|
||||
capacity := u.GetCapacity(c.IndexKey())
|
||||
h.SetScore(50 * int(capacity))
|
||||
h.SetRawScore(int(capacity))
|
||||
|
||||
return h.GetResult()
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ func (p *CreatingPriority) Map(u *core.Unit, c core.Candidater) (core.HostPriori
|
||||
}
|
||||
|
||||
if hc.CreatingGuestCount > 0 {
|
||||
score := -int(hc.CreatingGuestCount) * 20
|
||||
h.SetScore(score)
|
||||
score := -int(hc.CreatingGuestCount)
|
||||
h.SetFrontScore(score)
|
||||
}
|
||||
|
||||
return h.GetResult()
|
||||
|
||||
@@ -3,6 +3,7 @@ package guest
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/scheduler/algorithm/priorities"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/core"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/core/score"
|
||||
)
|
||||
|
||||
type LowLoadPriority struct {
|
||||
@@ -28,8 +29,12 @@ func (p *LowLoadPriority) Map(u *core.Unit, c core.Candidater) (core.HostPriorit
|
||||
cpuCommitRate := float64(hc.RunningCPUCount) / float64(hc.TotalCPUCount)
|
||||
memCommitRate := float64(hc.RunningMemSize) / float64(hc.TotalMemSize)
|
||||
if cpuCommitRate < 0.5 && memCommitRate < 0.5 {
|
||||
score := 20 * (1 - cpuCommitRate - memCommitRate)
|
||||
score := 10 * (1 - cpuCommitRate - memCommitRate)
|
||||
h.SetScore(int(score))
|
||||
}
|
||||
return h.GetResult()
|
||||
}
|
||||
|
||||
func (p *LowLoadPriority) ScoreIntervals() score.Intervals {
|
||||
return score.NewIntervals(0, 1, 5)
|
||||
}
|
||||
|
||||
@@ -1,23 +1,18 @@
|
||||
package priorities
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/scheduler/algorithm"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/cache/candidate"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/core"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/core/score"
|
||||
)
|
||||
|
||||
func aggPriority(x float64) float64 {
|
||||
return math.Log(x + math.Sqrt(x*x+1))
|
||||
}
|
||||
|
||||
// PriorityHelper is a struct that as a base interface for all priorities.
|
||||
type PriorityHelper struct {
|
||||
priority core.Priority
|
||||
unit *core.Unit
|
||||
Candidate core.Candidater
|
||||
score int
|
||||
score score.SScore
|
||||
err error
|
||||
}
|
||||
|
||||
@@ -29,9 +24,38 @@ func NewPriorityHelper(p core.Priority, u *core.Unit, c core.Candidater) *Priori
|
||||
}
|
||||
}
|
||||
|
||||
func (h *PriorityHelper) SetScore(score int) {
|
||||
h.score = score
|
||||
h.unit.SetScore(h.Candidate.IndexKey(), h.priority.Name(), score)
|
||||
func (h *PriorityHelper) setIntervalScore(val int) score.SScore {
|
||||
h.score = score.NewScore(
|
||||
h.priority.ScoreIntervals().ToScore(int64(val)),
|
||||
h.priority.Name())
|
||||
return h.score
|
||||
}
|
||||
|
||||
func (h *PriorityHelper) setRawScore(val int) score.SScore {
|
||||
h.score = score.NewScore(
|
||||
score.TScore(val),
|
||||
h.priority.Name())
|
||||
return h.score
|
||||
}
|
||||
|
||||
func (h *PriorityHelper) SetScore(val int) {
|
||||
h.setIntervalScore(val)
|
||||
h.unit.SetScore(h.Candidate.IndexKey(), h.score)
|
||||
}
|
||||
|
||||
func (h *PriorityHelper) SetFrontScore(val int) {
|
||||
h.setIntervalScore(val)
|
||||
h.unit.SetFrontScore(h.Candidate.IndexKey(), h.score)
|
||||
}
|
||||
|
||||
func (h *PriorityHelper) SetRawScore(val int) {
|
||||
h.setRawScore(val)
|
||||
h.unit.SetScore(h.Candidate.IndexKey(), h.score)
|
||||
}
|
||||
|
||||
func (h *PriorityHelper) SetFrontRawScore(val int) {
|
||||
h.setRawScore(val)
|
||||
h.unit.SetFrontScore(h.Candidate.IndexKey(), h.score)
|
||||
}
|
||||
|
||||
func (h *PriorityHelper) SetError(err error) {
|
||||
@@ -41,7 +65,6 @@ func (h *PriorityHelper) SetError(err error) {
|
||||
func (h *PriorityHelper) GetResult() (core.HostPriority, error) {
|
||||
return core.HostPriority{
|
||||
Host: h.Candidate.IndexKey(),
|
||||
Score: h.score,
|
||||
Candidate: h.Candidate,
|
||||
}, h.err
|
||||
}
|
||||
@@ -71,3 +94,7 @@ func (b *BasePriority) Name() string {
|
||||
func (b *BasePriority) HostCandidate(c core.Candidater) (*candidate.HostDesc, error) {
|
||||
return algorithm.ToHostCandidate(c)
|
||||
}
|
||||
|
||||
func (b *BasePriority) ScoreIntervals() score.Intervals {
|
||||
return score.NewIntervals(0, 1, 2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user