Skip to content

Commit 2618812

Browse files
wenyihu6tbg
authored andcommitted
asim: refactor the code to use rebalancing snapshot rate
Previously, asim used ReplicaAddRate for SimulationSettings, which was an artificial approximation and differed from the real cluster behaviour with snapshot-based calculation. This patch refactors it to use the actual snapshot rate instead. There is no behavioral change, since SnapshotRate = AddRate / (1024*1024). So (RangeSize/(1024*1024))/(AddRate)=RangeSize/(1024*1024*AddRate)=RangeSize/SnapshotRate. NB: there's an existing bug here; the calculation is missing a final multiplication by time.Second, and snapshot rate is defined per second. A future commit will address this. Epic: none Release note: none
1 parent 121c393 commit 2618812

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

pkg/kv/kvserver/asim/config/settings.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const (
1111
defaultTickInteval = 500 * time.Millisecond
1212
defaultMetricsInterval = 10 * time.Second
1313
defaultReplicaChangeBaseDelay = 100 * time.Millisecond
14-
defaultReplicaAddDelayFactor = 16
14+
defaultRebalancingSnapshotRate = 16 << 20 // 16MiB/s
1515
defaultSplitQueueDelay = 100 * time.Millisecond
1616
defaultRangeSizeSplitThreshold = 512 * 1024 * 1024 // 512mb
1717
defaultRangeRebalanceThreshold = 0.05
@@ -56,13 +56,11 @@ type SimulationSettings struct {
5656
// (add,remove). It accounts for a fixed overhead of initiating a replica
5757
// movement.
5858
ReplicaChangeBaseDelay time.Duration
59-
// ReplicaAddRate is the factor applied to the range size (MB) when
60-
// calculating how long a replica addition will take for a given range
61-
// size. For adding a replica to a new store, the delay is calculated as
62-
// ReplicaChangeBaseDelay + (RangeSize(MB) * ReplicaAddRate) milliseconds.
63-
// This is analogous to the rate at which a store will ingest snapshots for
64-
// up replication.
65-
ReplicaAddRate float64
59+
// RebalancingSnapshotRate is rate at which newly added replicas will be
60+
// added based on the range size. e.g., When the range size is 16MB, and the
61+
// RebalancingSnapshotRate is 16 << 20, the delay for adding a replica wil be
62+
// 1 second + ReplicaChangeBaseDelay.
63+
RebalancingSnapshotRate int64
6664
// SplitQueueDelay is the delay that range splits take to complete.
6765
SplitQueueDelay time.Duration
6866
// RangeSizeSplitThreshold is the threshold in MB, below which ranges will
@@ -126,7 +124,7 @@ func DefaultSimulationSettings() *SimulationSettings {
126124
MetricsInterval: defaultMetricsInterval,
127125
Seed: defaultSeed,
128126
ReplicaChangeBaseDelay: defaultReplicaChangeBaseDelay,
129-
ReplicaAddRate: defaultReplicaAddDelayFactor,
127+
RebalancingSnapshotRate: defaultRebalancingSnapshotRate,
130128
SplitQueueDelay: defaultSplitQueueDelay,
131129
RangeSizeSplitThreshold: defaultRangeSizeSplitThreshold,
132130
RangeRebalanceThreshold: defaultRangeRebalanceThreshold,
@@ -154,7 +152,7 @@ func (s *SimulationSettings) ReplicaChangeDelayFn() func(rangeSize int64, add bo
154152
return func(rangeSize int64, add bool) time.Duration {
155153
delay := s.ReplicaChangeBaseDelay
156154
if add {
157-
delay += (time.Duration(rangeSize/(1024*1024)) / time.Duration(s.ReplicaAddRate))
155+
delay += (time.Duration(rangeSize) / time.Duration(s.RebalancingSnapshotRate))
158156
}
159157
return delay
160158
}

pkg/kv/kvserver/asim/op/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func TestLeaseTransferOp(t *testing.T) {
141141
func TestRelocateRangeOp(t *testing.T) {
142142
settings := config.DefaultSimulationSettings()
143143
start := settings.StartTime
144-
settings.ReplicaAddRate = 1
144+
settings.RebalancingSnapshotRate = 1 << 20
145145
settings.ReplicaChangeBaseDelay = 5 * time.Second
146146
settings.StateExchangeInterval = 1 * time.Second
147147
settings.StateExchangeDelay = 0

pkg/kv/kvserver/asim/storerebalancer/store_rebalancer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func TestStoreRebalancerBalances(t *testing.T) {
191191
testingStore := state.StoreID(1)
192192
testSettings := config.DefaultSimulationSettings()
193193
start := testSettings.StartTime
194-
testSettings.ReplicaAddRate = 1
194+
testSettings.RebalancingSnapshotRate = 1 << 20
195195
testSettings.ReplicaChangeBaseDelay = 1 * time.Second
196196
testSettings.StateExchangeInterval = 1 * time.Second
197197
testSettings.StateExchangeDelay = 0

0 commit comments

Comments
 (0)