forked from TrueCloudLab/frostfs-qos
87 lines
2.3 KiB
Go
87 lines
2.3 KiB
Go
package scheduling
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"math"
|
|
"math/rand/v2"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type noopMClockScheduler struct{}
|
|
|
|
var (
|
|
releaseStub ReleaseFunc = func() {}
|
|
defaultLimit float64 = 100_000
|
|
shortReservation float64 = 1
|
|
medReservation float64 = 100
|
|
largeReservation float64 = 10_000
|
|
)
|
|
|
|
func (s *noopMClockScheduler) RequestArrival(context.Context, string) ReleaseFunc {
|
|
return releaseStub
|
|
}
|
|
|
|
func BenchmarkMClock(b *testing.B) {
|
|
tagsCount := []int{1, 2, 4, 8, 16}
|
|
ioDuration := time.Millisecond
|
|
parallelismValues := []int{1, 8, 32, 64}
|
|
limits := []*float64{nil, &defaultLimit}
|
|
reservations := []*float64{nil, &shortReservation, &medReservation, &largeReservation}
|
|
for _, parallelism := range parallelismValues {
|
|
b.SetParallelism(parallelism)
|
|
|
|
noopMClock := &noopMClockScheduler{}
|
|
b.Run(fmt.Sprintf("impl=noop/parallelism=%d", parallelism), func(b *testing.B) {
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
for pb.Next() {
|
|
release := noopMClock.RequestArrival(context.Background(), "tag")
|
|
time.Sleep(ioDuration)
|
|
release()
|
|
}
|
|
})
|
|
})
|
|
|
|
for _, limit := range limits {
|
|
for _, reservation := range reservations {
|
|
for _, tags := range tagsCount {
|
|
tagInfos := make(map[string]TagInfo)
|
|
for tag := 0; tag < tags; tag++ {
|
|
tagInfos["tag"+strconv.FormatInt(int64(tag), 10)] = TagInfo{Share: 50, LimitIOPS: limit, ReservedIOPS: reservation}
|
|
}
|
|
|
|
mClockQ, _ := NewMClock(math.MaxUint64, math.MaxUint64, tagInfos, time.Hour)
|
|
|
|
resStr := "no"
|
|
if reservation != nil {
|
|
resStr = strconv.FormatFloat(*reservation, 'f', 1, 64)
|
|
}
|
|
limitStr := "no"
|
|
if limit != nil {
|
|
limitStr = strconv.FormatFloat(*limit, 'f', 1, 64)
|
|
}
|
|
b.Run(fmt.Sprintf("impl=mclock/limit=%s/reservation=%s/parallelism=%d/tags=%d", limitStr, resStr, parallelism, tags), func(b *testing.B) {
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
for pb.Next() {
|
|
tag := rand.Int64N(int64(tags))
|
|
release, err := mClockQ.RequestArrival(context.Background(), "tag"+strconv.FormatInt(int64(tag), 10))
|
|
require.NoError(b, err)
|
|
time.Sleep(ioDuration)
|
|
release()
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|