Skip to content

Commit 90d703b

Browse files
Super-longtiny-x
authored andcommitted
fix: Change the value pass in slope to a reference pass. (chaosblade-io#116)
Signed-off-by: Super-long <[email protected]> Co-authored-by: tiny-x <[email protected]> Signed-off-by: hengyoush <[email protected]>
1 parent e2893ec commit 90d703b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

exec/cpu/cpu.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ func (ce *cpuExecutor) start(ctx context.Context, cpuList string, cpuCount, cpuP
282282
}
283283
}
284284

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

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

300302
const period = int64(1000000000)
301303

302-
func slope(ctx context.Context, cpuPercent int, climbTime int, slopePercent float64, percpu bool, cpuIndex int) {
304+
func slope(ctx context.Context, cpuPercent int, climbTime int, slopePercent *float64, precpu bool, cpuIndex int) {
303305
if climbTime != 0 {
304306
var ticker = time.NewTicker(time.Second)
305-
slopePercent = getUsed(ctx, percpu, cpuIndex)
306-
var startPercent = float64(cpuPercent) - slopePercent
307+
*slopePercent = getUsed(ctx, precpu, cpuIndex)
308+
var startPercent = float64(cpuPercent) - *slopePercent
307309
go func() {
308310
for range ticker.C {
309-
if slopePercent < float64(cpuPercent) {
310-
slopePercent += startPercent / float64(climbTime)
311-
} else if slopePercent > float64(cpuPercent) {
312-
slopePercent -= startPercent / float64(climbTime)
311+
if *slopePercent < float64(cpuPercent) {
312+
*slopePercent += startPercent / float64(climbTime)
313+
} else if *slopePercent > float64(cpuPercent) {
314+
*slopePercent -= startPercent / float64(climbTime)
313315
}
314316
}
315317
}()

0 commit comments

Comments
 (0)