[#1] mclock: Use time.Duration
for idle timeout
All checks were successful
DCO action / DCO (pull_request) Successful in 28s
Vulncheck / Vulncheck (pull_request) Successful in 28s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m4s
Tests and linters / gopls check (pull_request) Successful in 1m3s
Tests and linters / Tests (pull_request) Successful in 1m8s
Tests and linters / Lint (pull_request) Successful in 1m18s
Tests and linters / Run gofumpt (pull_request) Successful in 1m16s
Tests and linters / Staticcheck (pull_request) Successful in 1m18s
Tests and linters / Tests with -race (pull_request) Successful in 1m19s
All checks were successful
DCO action / DCO (pull_request) Successful in 28s
Vulncheck / Vulncheck (pull_request) Successful in 28s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m4s
Tests and linters / gopls check (pull_request) Successful in 1m3s
Tests and linters / Tests (pull_request) Successful in 1m8s
Tests and linters / Lint (pull_request) Successful in 1m18s
Tests and linters / Run gofumpt (pull_request) Successful in 1m16s
Tests and linters / Staticcheck (pull_request) Successful in 1m18s
Tests and linters / Tests with -race (pull_request) Successful in 1m19s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
e9b244cb9a
commit
20a882fc37
3 changed files with 10 additions and 9 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"math"
|
"math"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -74,11 +75,11 @@ type MClock struct {
|
||||||
// waitLimit maximum allowed count of waiting requests
|
// waitLimit maximum allowed count of waiting requests
|
||||||
// for tags specified by tagInfo. The value of idleTimeout defines
|
// for tags specified by tagInfo. The value of idleTimeout defines
|
||||||
// the difference between the current time and the time of
|
// 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 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
|
// If waitLimit equals zero, it means that there is no limit on the
|
||||||
// number of waiting requests.
|
// 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 {
|
if err := validateParams(runLimit, tagInfo); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -86,7 +87,7 @@ func NewMClock(runLimit, waitLimit uint64, tagInfo map[string]TagInfo, idleTimeo
|
||||||
runLimit: runLimit,
|
runLimit: runLimit,
|
||||||
waitLimit: int(waitLimit),
|
waitLimit: int(waitLimit),
|
||||||
clock: newSystemClock(),
|
clock: newSystemClock(),
|
||||||
idleTimeout: idleTimeout,
|
idleTimeout: idleTimeout.Seconds(),
|
||||||
tagInfo: tagInfo,
|
tagInfo: tagInfo,
|
||||||
|
|
||||||
reservationQueue: &queue{},
|
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}
|
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"
|
resStr := "no"
|
||||||
if reservation != nil {
|
if reservation != nil {
|
||||||
|
|
|
@ -275,7 +275,7 @@ func TestMClockReservationScheduling(t *testing.T) {
|
||||||
func TestMClockIdleTag(t *testing.T) {
|
func TestMClockIdleTag(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
reqCount := 100
|
reqCount := 100
|
||||||
idleTimeout := 2.0
|
idleTimeout := 2 * time.Second
|
||||||
cl := &noopClock{}
|
cl := &noopClock{}
|
||||||
q, err := NewMClock(1, math.MaxUint64, map[string]TagInfo{
|
q, err := NewMClock(1, math.MaxUint64, map[string]TagInfo{
|
||||||
"class1": {Share: 1},
|
"class1": {Share: 1},
|
||||||
|
@ -287,7 +287,7 @@ func TestMClockIdleTag(t *testing.T) {
|
||||||
var requests []*request
|
var requests []*request
|
||||||
tag := "class1"
|
tag := "class1"
|
||||||
for i := 0; i < reqCount/2; i++ {
|
for i := 0; i < reqCount/2; i++ {
|
||||||
cl.v += idleTimeout / 2
|
cl.v += idleTimeout.Seconds() / 2
|
||||||
req, _, err := q.pushRequest(tag)
|
req, _, err := q.pushRequest(tag)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
requests = append(requests, req)
|
requests = append(requests, req)
|
||||||
|
@ -295,7 +295,7 @@ func TestMClockIdleTag(t *testing.T) {
|
||||||
|
|
||||||
// class1 requests have shares [1.0; 2.0; 3.0; ... ]
|
// class1 requests have shares [1.0; 2.0; 3.0; ... ]
|
||||||
|
|
||||||
cl.v += 2 * idleTimeout
|
cl.v += 2 * idleTimeout.Seconds()
|
||||||
|
|
||||||
tag = "class2"
|
tag = "class2"
|
||||||
req, _, err := q.pushRequest(tag)
|
req, _, err := q.pushRequest(tag)
|
||||||
|
@ -424,7 +424,7 @@ func TestMClockParameterValidation(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = NewMClock(1, 1, map[string]TagInfo{
|
_, err = NewMClock(1, 1, map[string]TagInfo{
|
||||||
"class1": {Share: 1},
|
"class1": {Share: 1},
|
||||||
}, float64(0))
|
}, 0)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
negativeValue := -1.0
|
negativeValue := -1.0
|
||||||
zeroValue := float64(0)
|
zeroValue := float64(0)
|
||||||
|
@ -466,7 +466,7 @@ func TestMClockTimeBasedSchedule(t *testing.T) {
|
||||||
limit := 1.0 // 1 request per second allowed
|
limit := 1.0 // 1 request per second allowed
|
||||||
cl := &noopClock{v: float64(1.5)}
|
cl := &noopClock{v: float64(1.5)}
|
||||||
q, err := NewMClock(100, math.MaxUint64, map[string]TagInfo{
|
q, err := NewMClock(100, math.MaxUint64, map[string]TagInfo{
|
||||||
"class1": {Shares: 1, Limit: &limit},
|
"class1": {Share: 1, LimitIOPS: &limit},
|
||||||
}, 100)
|
}, 100)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer q.Close()
|
defer q.Close()
|
||||||
|
|
Loading…
Add table
Reference in a new issue