Skip to content

Commit

Permalink
exchange round and slowdown in cpu regulator (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
sun-yuliang authored Jun 8, 2023
1 parent 3b403aa commit 697fb6a
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ type CPURegulator struct {
types.ResourceEssentials

// maxRampUpStep is the max cpu cores can be increased during each cpu requirement update
maxRampUpStep float64
maxRampUpStep int

// maxRampDownStep is the max cpu cores can be decreased during each cpu requirement update
maxRampDownStep float64
maxRampDownStep int

// minRampDownPeriod is the min time gap between two consecutive cpu requirement ramp down
minRampDownPeriod time.Duration
Expand Down Expand Up @@ -71,12 +71,12 @@ func (c *CPURegulator) SetLatestCPURequirement(latestCPURequirement int) {
// as the latest cpu requirement value
func (c *CPURegulator) Regulate(cpuRequirement float64) {
cpuRequirementReserved := cpuRequirement + c.ReservedForAllocate
cpuRequirementSlowdown := c.slowdown(cpuRequirementReserved)
cpuRequirementRound := c.round(cpuRequirementSlowdown)
cpuRequirementClamp := c.clamp(cpuRequirementRound)
cpuRequirementRound := c.round(cpuRequirementReserved)
cpuRequirementSlowdown := c.slowdown(cpuRequirementRound)
cpuRequirementClamp := c.clamp(cpuRequirementSlowdown)

klog.Infof("[qosaware-cpu] cpu requirement by policy: %.2f, with reserve: %.2f, after slowdown: %.2f, after round: %d, after clamp: %d",
cpuRequirement, cpuRequirementReserved, cpuRequirementSlowdown, cpuRequirementRound, cpuRequirementClamp)
klog.Infof("[qosaware-cpu] cpu requirement by policy: %.2f, with reserve: %.2f, after round: %d, after slowdown: %d, after clamp: %d",
cpuRequirement, cpuRequirementReserved, cpuRequirementRound, cpuRequirementSlowdown, cpuRequirementClamp)

if cpuRequirementClamp != c.latestCPURequirement {
c.latestCPURequirement = cpuRequirementClamp
Expand All @@ -89,20 +89,19 @@ func (c *CPURegulator) GetCPURequirement() int {
return c.latestCPURequirement
}

func (c *CPURegulator) slowdown(cpuRequirement float64) float64 {
func (c *CPURegulator) slowdown(cpuRequirement int) int {
now := time.Now()
latestCPURequirement := float64(c.latestCPURequirement)

// Restrict ramp down period
if cpuRequirement < latestCPURequirement && now.Before(c.latestRampDownTime.Add(c.minRampDownPeriod)) {
return latestCPURequirement
// Restrict ramp down frequency
if cpuRequirement < c.latestCPURequirement && now.Before(c.latestRampDownTime.Add(c.minRampDownPeriod)) {
return c.latestCPURequirement
}

// Restrict ramp up and down step
if cpuRequirement-latestCPURequirement > c.maxRampUpStep {
cpuRequirement = latestCPURequirement + c.maxRampUpStep
} else if latestCPURequirement-cpuRequirement > c.maxRampDownStep {
cpuRequirement = latestCPURequirement - c.maxRampDownStep
if cpuRequirement-c.latestCPURequirement > c.maxRampUpStep {
cpuRequirement = c.latestCPURequirement + c.maxRampUpStep
} else if c.latestCPURequirement-cpuRequirement > c.maxRampDownStep {
cpuRequirement = c.latestCPURequirement - c.maxRampDownStep
}

return cpuRequirement
Expand Down

0 comments on commit 697fb6a

Please sign in to comment.