Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: Jitter the StoreRebalancer loop's timing #31227

Merged
merged 1 commit into from
Oct 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions pkg/storage/store_rebalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package storage
import (
"context"
"math"
"math/rand"
"sort"
"time"

Expand All @@ -27,6 +28,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/metric"
"github.com/cockroachdb/cockroach/pkg/util/stop"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"go.etcd.io/etcd/raft"
)

Expand Down Expand Up @@ -173,16 +175,19 @@ func (sr *StoreRebalancer) Start(ctx context.Context, stopper *stop.Stopper) {
// Start a goroutine that watches and proactively renews certain
// expiration-based leases.
stopper.RunWorker(ctx, func(ctx context.Context) {
ticker := time.NewTicker(storeRebalancerTimerDuration)
defer ticker.Stop()
timer := timeutil.NewTimer()
defer timer.Stop()
timer.Reset(jitteredInterval(storeRebalancerTimerDuration))
for {
// Wait out the first tick before doing anything since the store is still
// starting up and we might as well wait for some qps/wps stats to
// accumulate.
select {
case <-stopper.ShouldQuiesce():
return
case <-ticker.C:
case <-timer.C:
timer.Read = true
timer.Reset(jitteredInterval(storeRebalancerTimerDuration))
}

if !sr.st.Version.IsMinSupported(cluster.VersionLoadBasedRebalancing) {
Expand Down Expand Up @@ -675,3 +680,9 @@ func storeListToMap(sl StoreList) map[roachpb.StoreID]*roachpb.StoreDescriptor {
}
return storeMap
}

// jitteredInterval returns a randomly jittered (+/-25%) duration
// from checkInterval.
func jitteredInterval(interval time.Duration) time.Duration {
return time.Duration(float64(interval) * (0.75 + 0.5*rand.Float64()))
}