Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions exec/cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ func (ce *cpuExecutor) start(ctx context.Context, cpuList string, cpuCount, cpuP
}
}

slope(ctx, cpuPercent, climbTime, slopePercent, precpu, cpuIndex)
// make CPU slowly climb to some level, to simulate slow resource competition
// which system faults cannot be quickly noticed by monitoring system.
slope(ctx, cpuPercent, climbTime, &slopePercent, precpu, cpuIndex)

quota := make(chan int64, cpuCount)
for i := 0; i < cpuCount; i++ {
Expand All @@ -299,17 +301,17 @@ func (ce *cpuExecutor) start(ctx context.Context, cpuList string, cpuCount, cpuP

const period = int64(1000000000)

func slope(ctx context.Context, cpuPercent int, climbTime int, slopePercent float64, precpu bool, cpuIndex int) {
func slope(ctx context.Context, cpuPercent int, climbTime int, slopePercent *float64, precpu bool, cpuIndex int) {
if climbTime != 0 {
var ticker = time.NewTicker(time.Second)
slopePercent = getUsed(ctx, precpu, cpuIndex)
var startPercent = float64(cpuPercent) - slopePercent
*slopePercent = getUsed(ctx, precpu, cpuIndex)
var startPercent = float64(cpuPercent) - *slopePercent
go func() {
for range ticker.C {
if slopePercent < float64(cpuPercent) {
slopePercent += startPercent / float64(climbTime)
} else if slopePercent > float64(cpuPercent) {
slopePercent -= startPercent / float64(climbTime)
if *slopePercent < float64(cpuPercent) {
*slopePercent += startPercent / float64(climbTime)
} else if *slopePercent > float64(cpuPercent) {
*slopePercent -= startPercent / float64(climbTime)
}
}
}()
Expand Down