Skip to content

Commit

Permalink
Add benchmark for getPlannedRateChanges and perf improvement
Browse files Browse the repository at this point in the history
The results are:
benchmark                            old ns/op     new ns/op     delta
BenchmarkGetPlannedRateChanges-4     4140227       2710011       -34.54%
BenchmarkGetPlannedRateChanges-4     3531805       2397757       -32.11%
BenchmarkGetPlannedRateChanges-4     3337196       2277776       -31.75%
BenchmarkGetPlannedRateChanges-4     2984674       2192676       -26.54%
BenchmarkGetPlannedRateChanges-4     2900849       2492187       -14.09%

benchmark                            old allocs     new allocs   delta
BenchmarkGetPlannedRateChanges-4     72977          56205        -22.98%
BenchmarkGetPlannedRateChanges-4     72977          56205        -22.98%
BenchmarkGetPlannedRateChanges-4     72977          56205        -22.98%
BenchmarkGetPlannedRateChanges-4     72977          56205        -22.98%
BenchmarkGetPlannedRateChanges-4     72977          56205        -22.98%

benchmark                            old bytes     new bytes     delta
BenchmarkGetPlannedRateChanges-4     1503784       1254588       -16.57%
BenchmarkGetPlannedRateChanges-4     1503780       1254585       -16.57%
BenchmarkGetPlannedRateChanges-4     1503780       1254588       -16.57%
BenchmarkGetPlannedRateChanges-4     1503771       1254584       -16.57%
BenchmarkGetPlannedRateChanges-4     1503775       1254588       -16.57%
  • Loading branch information
mstoykov committed Oct 11, 2019
1 parent 9939752 commit 9999f0d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/executor/variable_arrival_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,16 @@ func (varc VariableArrivalRateConfig) getPlannedRateChanges(segment *lib.Executi
// nanosecond precision, so there isn't any actual loss of precision...
stepNumber := (stageDuration / minIntervalBetweenRateAdjustments)
if stepNumber > 1 {
rateDiff := new(big.Rat).Sub(stageTargetRate, currentRate)
stepInterval := stageDuration / stepNumber
for t := stepInterval; ; t += stepInterval {
if stageDuration-t < minIntervalBetweenRateAdjustments {
break
}

rateDiff := new(big.Rat).Sub(stageTargetRate, currentRate)
tArrivalRate := new(big.Rat).Add(
currentRate,
rateDiff.Mul(rateDiff, big.NewRat(int64(t), int64(stageDuration))),
new(big.Rat).Mul(rateDiff, big.NewRat(int64(t), int64(stageDuration))),
)

rateChanges = append(rateChanges, rateChange{
Expand Down
31 changes: 31 additions & 0 deletions lib/executor/variable_arrival_rate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,37 @@ func TestGetPlannedRateChanges(t *testing.T) {
}
}

func BenchmarkGetPlannedRateChanges(b *testing.B) {
var config = VariableArrivalRateConfig{
TimeUnit: types.NullDurationFrom(time.Second),
StartRate: null.IntFrom(0),
Stages: []Stage{
{
Duration: types.NullDurationFrom(5 * time.Minute),
Target: null.IntFrom(5000),
},
{
Duration: types.NullDurationFrom(50 * time.Minute),
Target: null.IntFrom(5000),
},
{
Duration: types.NullDurationFrom(5 * time.Minute),
Target: null.IntFrom(0),
},
},
}

var v *lib.ExecutionSegment
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
changes := config.getPlannedRateChanges(v)

require.Equal(b, time.Duration(0),
changes[0].timeOffset%minIntervalBetweenRateAdjustments, "%+v", changes[0])
}
})
}

func initializeVUs(
ctx context.Context, t testing.TB, logEntry *logrus.Entry, es *lib.ExecutionState, number int,
) {
Expand Down

0 comments on commit 9999f0d

Please sign in to comment.