diff --git a/pkg/kv/kvserver/store_rebalancer.go b/pkg/kv/kvserver/store_rebalancer.go index 48153d077f25..395f025d17b8 100644 --- a/pkg/kv/kvserver/store_rebalancer.go +++ b/pkg/kv/kvserver/store_rebalancer.go @@ -117,6 +117,17 @@ const ( RebalanceTargetFound ) +const ( + // minLeaseLoadFraction is the minimum fraction of the local store's load a + // lease must contribute, in order to consider it worthwhile rebalancing when + // overfull. + minLeaseLoadFraction = 0.005 + // minReplicaLoadFraction is the minimum fraction of the local store's load a + // replica (lease included) must contribute, in order to consider it + // worthwhile rebalancing when overfull. + minReplicaLoadFraction = 0.02 +) + // StoreRebalancer is responsible for examining how the associated store's load // compares to the load on other stores in the cluster and transferring leases // or replicas away if the local store is overloaded. @@ -716,9 +727,8 @@ func (sr *StoreRebalancer) chooseLeaseToTransfer( // Don't bother moving leases whose load is below some small fraction of the // store's load. It's just unnecessary churn with no benefit to move leases // responsible for, for example, 1 load unit on a store with 5000 load units. - const minLoadFraction = .001 if candidateReplica.RangeUsageInfo().TransferImpact().Dim(rctx.loadDimension) < - rctx.LocalDesc.Capacity.Load().Dim(rctx.loadDimension)*minLoadFraction { + rctx.LocalDesc.Capacity.Load().Dim(rctx.loadDimension)*minLeaseLoadFraction { log.KvDistribution.VEventf(ctx, 3, "r%d's %s load is too little to matter relative to s%d's %s total load", candidateReplica.GetRangeID(), candidateReplica.RangeUsageInfo().TransferImpact(), rctx.LocalDesc.StoreID, rctx.LocalDesc.Capacity.Load()) @@ -838,9 +848,8 @@ func (sr *StoreRebalancer) chooseRangeToRebalance( // Don't bother moving ranges whose load is below some small fraction of the // store's load. It's just unnecessary churn with no benefit to move ranges // responsible for, for example, 1 load unit on a store with 5000 load units. - const minLoadFraction = .001 if candidateReplica.RangeUsageInfo().Load().Dim(rctx.loadDimension) < - rctx.LocalDesc.Capacity.Load().Dim(rctx.loadDimension)*minLoadFraction { + rctx.LocalDesc.Capacity.Load().Dim(rctx.loadDimension)*minReplicaLoadFraction { log.KvDistribution.VEventf( ctx, 5, diff --git a/pkg/kv/kvserver/store_rebalancer_test.go b/pkg/kv/kvserver/store_rebalancer_test.go index d3e68d0c14d4..97b96a097473 100644 --- a/pkg/kv/kvserver/store_rebalancer_test.go +++ b/pkg/kv/kvserver/store_rebalancer_test.go @@ -746,28 +746,30 @@ func TestChooseLeaseToTransfer(t *testing.T) { expectTarget: 5, }, + // NB: The lease has just enough load to be worthwhile rebalancing. { storeIDs: []roachpb.StoreID{1, 4}, - qps: 1.5, - reqCPU: 1.5 * float64(time.Millisecond), + qps: minLeaseLoadFraction * localDesc.Capacity.QueriesPerSecond, + reqCPU: minLeaseLoadFraction * localDesc.Capacity.CPUPerSecond, expectTarget: 4, }, { storeIDs: []roachpb.StoreID{1, 5}, - qps: 1.5, - reqCPU: 1.5 * float64(time.Millisecond), + qps: minLeaseLoadFraction * localDesc.Capacity.QueriesPerSecond, + reqCPU: minLeaseLoadFraction * localDesc.Capacity.CPUPerSecond, expectTarget: 5, }, + // NB: The lease is no longer worth rebalancing. { storeIDs: []roachpb.StoreID{1, 4}, - qps: 1.49, - reqCPU: 1.49 * float64(time.Millisecond), + qps: minLeaseLoadFraction*localDesc.Capacity.QueriesPerSecond - 1, + reqCPU: minLeaseLoadFraction*localDesc.Capacity.CPUPerSecond - 1, expectTarget: 0, }, { storeIDs: []roachpb.StoreID{1, 5}, - qps: 1.49, - reqCPU: 1.49 * float64(time.Millisecond), + qps: minLeaseLoadFraction*localDesc.Capacity.QueriesPerSecond - 1, + reqCPU: minLeaseLoadFraction*localDesc.Capacity.CPUPerSecond - 1, expectTarget: 0, }, {