github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/replica_split_load.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package kvserver 12 13 import ( 14 "context" 15 16 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/spanset" 17 "github.com/cockroachdb/cockroach/pkg/roachpb" 18 "github.com/cockroachdb/cockroach/pkg/settings" 19 "github.com/cockroachdb/cockroach/pkg/util/timeutil" 20 ) 21 22 // SplitByLoadEnabled wraps "kv.range_split.by_load_enabled". 23 var SplitByLoadEnabled = settings.RegisterPublicBoolSetting( 24 "kv.range_split.by_load_enabled", 25 "allow automatic splits of ranges based on where load is concentrated", 26 true, 27 ) 28 29 // SplitByLoadQPSThreshold wraps "kv.range_split.load_qps_threshold". 30 var SplitByLoadQPSThreshold = settings.RegisterPublicIntSetting( 31 "kv.range_split.load_qps_threshold", 32 "the QPS over which, the range becomes a candidate for load based splitting", 33 2500, // 2500 req/s 34 ) 35 36 // SplitByLoadQPSThreshold returns the QPS request rate for a given replica. 37 func (r *Replica) SplitByLoadQPSThreshold() float64 { 38 return float64(SplitByLoadQPSThreshold.Get(&r.store.cfg.Settings.SV)) 39 } 40 41 // SplitByLoadEnabled returns whether load based splitting is enabled. 42 // Although this is a method of *Replica, the configuration is really global, 43 // shared across all stores. 44 func (r *Replica) SplitByLoadEnabled() bool { 45 return SplitByLoadEnabled.Get(&r.store.cfg.Settings.SV) && 46 !r.store.TestingKnobs().DisableLoadBasedSplitting 47 } 48 49 // recordBatchForLoadBasedSplitting records the batch's spans to be considered 50 // for load based splitting. 51 func (r *Replica) recordBatchForLoadBasedSplitting( 52 ctx context.Context, ba *roachpb.BatchRequest, spans *spanset.SpanSet, 53 ) { 54 if !r.SplitByLoadEnabled() { 55 return 56 } 57 shouldInitSplit := r.loadBasedSplitter.Record(timeutil.Now(), len(ba.Requests), func() roachpb.Span { 58 return spans.BoundarySpan(spanset.SpanGlobal) 59 }) 60 if shouldInitSplit { 61 r.store.splitQueue.MaybeAddAsync(ctx, r, r.store.Clock().Now()) 62 } 63 }