forked from TrueCloudLab/frostfs-qos
[#1] mclock: Use time.Duration
for idle timeout
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
47559a8d16
commit
f1cb5b40d5
3 changed files with 10 additions and 9 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"errors"
|
||||
"math"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -74,11 +75,11 @@ type MClock struct {
|
|||
// waitLimit maximum allowed count of waiting requests
|
||||
// for tags specified by tagInfo. The value of idleTimeout defines
|
||||
// the difference between the current time and the time of
|
||||
// the previous request in seconds, at which the tag considered idle.
|
||||
// the previous request, at which the tag considered idle.
|
||||
// If idleTimeout is negative, it means that there is no idle tags allowed.
|
||||
// If waitLimit equals zero, it means that there is no limit on the
|
||||
// number of waiting requests.
|
||||
func NewMClock(runLimit, waitLimit uint64, tagInfo map[string]TagInfo, idleTimeout float64) (*MClock, error) {
|
||||
func NewMClock(runLimit, waitLimit uint64, tagInfo map[string]TagInfo, idleTimeout time.Duration) (*MClock, error) {
|
||||
if err := validateParams(runLimit, tagInfo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -86,7 +87,7 @@ func NewMClock(runLimit, waitLimit uint64, tagInfo map[string]TagInfo, idleTimeo
|
|||
runLimit: runLimit,
|
||||
waitLimit: int(waitLimit),
|
||||
clock: newSystemClock(),
|
||||
idleTimeout: idleTimeout,
|
||||
idleTimeout: idleTimeout.Seconds(),
|
||||
tagInfo: tagInfo,
|
||||
|
||||
reservationQueue: &queue{},
|
||||
|
|
|
@ -56,7 +56,7 @@ func BenchmarkMClock(b *testing.B) {
|
|||
tagInfos["tag"+strconv.FormatInt(int64(tag), 10)] = TagInfo{Share: 50, LimitIOPS: limit, ReservedIOPS: reservation}
|
||||
}
|
||||
|
||||
mClockQ, _ := NewMClock(math.MaxUint64, math.MaxUint64, tagInfos, math.MaxFloat64)
|
||||
mClockQ, _ := NewMClock(math.MaxUint64, math.MaxUint64, tagInfos, time.Hour)
|
||||
|
||||
resStr := "no"
|
||||
if reservation != nil {
|
||||
|
|
|
@ -275,7 +275,7 @@ func TestMClockReservationScheduling(t *testing.T) {
|
|||
func TestMClockIdleTag(t *testing.T) {
|
||||
t.Parallel()
|
||||
reqCount := 100
|
||||
idleTimeout := 2.0
|
||||
idleTimeout := 2 * time.Second
|
||||
cl := &noopClock{}
|
||||
q, err := NewMClock(1, math.MaxUint64, map[string]TagInfo{
|
||||
"class1": {Share: 1},
|
||||
|
@ -287,7 +287,7 @@ func TestMClockIdleTag(t *testing.T) {
|
|||
var requests []*request
|
||||
tag := "class1"
|
||||
for i := 0; i < reqCount/2; i++ {
|
||||
cl.v += idleTimeout / 2
|
||||
cl.v += idleTimeout.Seconds() / 2
|
||||
req, _, err := q.pushRequest(tag)
|
||||
require.NoError(t, err)
|
||||
requests = append(requests, req)
|
||||
|
@ -295,7 +295,7 @@ func TestMClockIdleTag(t *testing.T) {
|
|||
|
||||
// class1 requests have shares [1.0; 2.0; 3.0; ... ]
|
||||
|
||||
cl.v += 2 * idleTimeout
|
||||
cl.v += 2 * idleTimeout.Seconds()
|
||||
|
||||
tag = "class2"
|
||||
req, _, err := q.pushRequest(tag)
|
||||
|
@ -424,7 +424,7 @@ func TestMClockParameterValidation(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
_, err = NewMClock(1, 1, map[string]TagInfo{
|
||||
"class1": {Share: 1},
|
||||
}, float64(0))
|
||||
}, 0)
|
||||
require.NoError(t, err)
|
||||
negativeValue := -1.0
|
||||
zeroValue := float64(0)
|
||||
|
@ -466,7 +466,7 @@ func TestMClockTimeBasedSchedule(t *testing.T) {
|
|||
limit := 1.0 // 1 request per second allowed
|
||||
cl := &noopClock{v: float64(1.5)}
|
||||
q, err := NewMClock(100, math.MaxUint64, map[string]TagInfo{
|
||||
"class1": {Shares: 1, Limit: &limit},
|
||||
"class1": {Share: 1, LimitIOPS: &limit},
|
||||
}, 100)
|
||||
require.NoError(t, err)
|
||||
defer q.Close()
|
||||
|
|
Loading…
Add table
Reference in a new issue