Skip to content

Commit 5abaa70

Browse files
committed
asim: print simulation setting as part of * _setup.txt
This commit includes simulation settings in the setup output. Only values that differ from the default simulation settings are printed. Note that cluster settings and the seed are omitted. The simulation seed is derived from rand.New(rand.NewSource(42)).Int63() by default, while the default simulation setting itself uses 42. Note that we rely on users to explicitly reset cluster settings between runs. It isn’t an issue now, but it may become a potential footgun in the future.
1 parent ba1a3a7 commit 5abaa70

File tree

8 files changed

+160
-44
lines changed

8 files changed

+160
-44
lines changed

pkg/kv/kvserver/asim/gen/generator.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func GenerateSimulation(
7171
s := clusterGen.Generate(seed, &settings)
7272
s, rangeStateStr := rangeGen.Generate(seed, &settings, s)
7373
eventExecutor := eventGen.Generate(seed, &settings)
74-
generateClusterVisualization(buf, s, loadGen, eventGen, rangeStateStr)
74+
generateClusterVisualization(buf, s, loadGen, eventGen, rangeStateStr, settings)
7575
return asim.NewSimulator(
7676
duration,
7777
loadGen.Generate(seed, &settings),
@@ -104,10 +104,7 @@ var _ LoadGen = MultiLoad{}
104104

105105
func (ml MultiLoad) String() string {
106106
var str string
107-
for i, load := range ml {
108-
if i > 0 {
109-
str += "\n"
110-
}
107+
for _, load := range ml {
111108
str += load.String()
112109
}
113110
return str
@@ -164,7 +161,7 @@ func (bl BasicLoad) String() string {
164161
} else {
165162
_, _ = fmt.Fprintf(&buf, "%d-%dB/op, ", bl.MinBlockSize, bl.MaxBlockSize)
166163
}
167-
fmt.Fprintf(&buf, "%gops/s]", bl.Rate)
164+
fmt.Fprintf(&buf, "%gops/s]\n", bl.Rate)
168165
return buf.String()
169166
}
170167

pkg/kv/kvserver/asim/gen/printer.go

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,52 @@ package gen
77

88
import (
99
"fmt"
10+
"reflect"
1011
"strings"
1112

13+
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/config"
1214
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/state"
1315
)
1416

17+
// compareSettingsToDefault compares the given settings against DefaultSimulationSettings
18+
// and returns a string listing the fields that have changed from their default values.
19+
// Returns an empty string if no changes are found.
20+
func compareSettingsToDefault(settings config.SimulationSettings) string {
21+
defaultSettings := config.DefaultSimulationSettings()
22+
var changes []string
23+
24+
// Use reflection to compare all fields
25+
settingsVal := reflect.ValueOf(settings)
26+
defaultVal := reflect.ValueOf(*defaultSettings)
27+
settingsType := reflect.TypeOf(settings)
28+
29+
for i := 0; i < settingsVal.NumField(); i++ {
30+
field := settingsType.Field(i)
31+
settingsFieldVal := settingsVal.Field(i)
32+
defaultFieldVal := defaultVal.Field(i)
33+
34+
// Skip cluster setting ST and seed. The simulation seed is derived from
35+
// rand.New(rand.NewSource(42)).Int63() by default, while the default
36+
// simulation setting itself uses 42.
37+
if field.Name == "ST" || field.Name == "Seed" {
38+
continue
39+
}
40+
41+
if !reflect.DeepEqual(settingsFieldVal.Interface(), defaultFieldVal.Interface()) {
42+
changes = append(changes, fmt.Sprintf("\t%s: %v (default: %v)",
43+
field.Name,
44+
settingsFieldVal.Interface(),
45+
defaultFieldVal.Interface()))
46+
}
47+
}
48+
49+
if len(changes) == 0 {
50+
return ""
51+
}
52+
53+
return strings.Join(changes, "\n")
54+
}
55+
1556
// generateClusterVisualization generates a visualization of the cluster state.
1657
// Example: mma_one_voter_skewed_cpu_skewed_write_setup.txt.
1758
//
@@ -25,9 +66,18 @@ import (
2566
// set LBRebalancingMode to 4
2667
// Workload Set Up
2768
// [1,10000): read-only high-cpu [500.00cpu-us/op, 1B/op, 1000ops/s]
28-
// [10001,20000): write-only large-block [0.00cpu-us/write(raft), 1000B/op, 5000ops/s]
69+
// [10001,20000): write-only large-block [0.00cpu-us/write(raft), 1000B/op, 5000ops/s]Settings
70+
// Changed settings:
71+
// ReplicateQueueEnabled: false (default: true)
72+
// LeaseQueueEnabled: false (default: true)
73+
// SplitQueueEnabled: false (default: true)
2974
func generateClusterVisualization(
30-
buf *strings.Builder, s state.State, loadGen LoadGen, eventGen EventGen, rangeStateStr string,
75+
buf *strings.Builder,
76+
s state.State,
77+
loadGen LoadGen,
78+
eventGen EventGen,
79+
rangeStateStr string,
80+
settings config.SimulationSettings,
3181
) {
3282
if buf == nil {
3383
return
@@ -40,4 +90,9 @@ func generateClusterVisualization(
4090
_, _ = fmt.Fprintf(buf, "Key Space\n%s", rangeStateStr)
4191
_, _ = fmt.Fprintf(buf, "Event\n%s", eventGen.String())
4292
_, _ = fmt.Fprintf(buf, "Workload Set Up\n%s", loadGen.String())
93+
94+
// Only print settings section if there are changes from defaults.
95+
if settingsChanges := compareSettingsToDefault(settings); settingsChanges != "" {
96+
_, _ = fmt.Fprintf(buf, "Changed Settings\n%s\n", settingsChanges)
97+
}
4398
}

pkg/kv/kvserver/asim/tests/testdata/generated/example_rebalancing/example_rebalancing_setup.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ Key Space
1111
Event
1212
set LBRebalancingMode to 2
1313
Workload Set Up
14-
[1,10000): 95%r large-block [128-256B/op, 7000ops/s]
14+
[1,10000): 95%r large-block [128-256B/op, 7000ops/s]
15+
Changed Settings
16+
StateExchangeDelay: 20s (default: 500ms)

pkg/kv/kvserver/asim/tests/testdata/rand/default_settings.txt

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,34 @@ clear
7070
# at each iteration.
7171
eval verbose=(config_gen)
7272
----
73+
----
7374
----------------------------------
7475
sample1: start running
7576
configurations generated using seed 3440579354231278675
7677
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
7778
[0,200000): 10(rf=3), 0MiB
78-
[0,200000): write-only [1B/op, 0ops/s]
79+
[0,200000): write-only [1B/op, 0ops/s]
80+
7981
sample1: pass
8082
----------------------------------
8183
sample2: start running
8284
configurations generated using seed 608747136543856411
8385
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
8486
[0,200000): 10(rf=3), 0MiB
85-
[0,200000): write-only [1B/op, 0ops/s]
87+
[0,200000): write-only [1B/op, 0ops/s]
88+
8689
sample2: pass
8790
----------------------------------
8891
sample3: start running
8992
configurations generated using seed 5571782338101878760
9093
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
9194
[0,200000): 10(rf=3), 0MiB
92-
[0,200000): write-only [1B/op, 0ops/s]
95+
[0,200000): write-only [1B/op, 0ops/s]
96+
9397
sample3: pass
9498
----------------------------------
99+
----
100+
----
95101

96102
clear
97103
----
@@ -154,6 +160,7 @@ clear
154160
# include initial state, test settings, and generated configurations.
155161
eval verbose=(initial_state,test_settings,config_gen)
156162
----
163+
----
157164
test settings
158165
num_iterations=3 duration=10m0s
159166
----------------------------------
@@ -170,7 +177,8 @@ sample1: start running
170177
configurations generated using seed 3440579354231278675
171178
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
172179
[0,200000): 10(rf=3), 0MiB
173-
[0,200000): write-only [1B/op, 0ops/s]
180+
[0,200000): write-only [1B/op, 0ops/s]
181+
174182
initial state at 2022-03-21 11:00:00:
175183
stores(3)=[s1n1=(replicas(10)),s2n2=(replicas(10)),s3n3=(replicas(10))]
176184
sample1: pass
@@ -179,7 +187,8 @@ sample2: start running
179187
configurations generated using seed 608747136543856411
180188
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
181189
[0,200000): 10(rf=3), 0MiB
182-
[0,200000): write-only [1B/op, 0ops/s]
190+
[0,200000): write-only [1B/op, 0ops/s]
191+
183192
initial state at 2022-03-21 11:00:00:
184193
stores(3)=[s1n1=(replicas(10)),s2n2=(replicas(10)),s3n3=(replicas(10))]
185194
sample2: pass
@@ -188,11 +197,14 @@ sample3: start running
188197
configurations generated using seed 5571782338101878760
189198
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
190199
[0,200000): 10(rf=3), 0MiB
191-
[0,200000): write-only [1B/op, 0ops/s]
200+
[0,200000): write-only [1B/op, 0ops/s]
201+
192202
initial state at 2022-03-21 11:00:00:
193203
stores(3)=[s1n1=(replicas(10)),s2n2=(replicas(10)),s3n3=(replicas(10))]
194204
sample3: pass
195205
----------------------------------
206+
----
207+
----
196208

197209
clear
198210
----
@@ -201,6 +213,7 @@ clear
201213
# configurations, initial state, and topology.
202214
eval verbose=(all)
203215
----
216+
----
204217
test settings
205218
num_iterations=3 duration=10m0s
206219
----------------------------------
@@ -217,7 +230,8 @@ sample1: start running
217230
configurations generated using seed 3440579354231278675
218231
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
219232
[0,200000): 10(rf=3), 0MiB
220-
[0,200000): write-only [1B/op, 0ops/s]
233+
[0,200000): write-only [1B/op, 0ops/s]
234+
221235
initial state at 2022-03-21 11:00:00:
222236
stores(3)=[s1n1=(replicas(10)),s2n2=(replicas(10)),s3n3=(replicas(10))]
223237
topology:
@@ -231,7 +245,8 @@ sample2: start running
231245
configurations generated using seed 608747136543856411
232246
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
233247
[0,200000): 10(rf=3), 0MiB
234-
[0,200000): write-only [1B/op, 0ops/s]
248+
[0,200000): write-only [1B/op, 0ops/s]
249+
235250
initial state at 2022-03-21 11:00:00:
236251
stores(3)=[s1n1=(replicas(10)),s2n2=(replicas(10)),s3n3=(replicas(10))]
237252
topology:
@@ -245,7 +260,8 @@ sample3: start running
245260
configurations generated using seed 5571782338101878760
246261
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
247262
[0,200000): 10(rf=3), 0MiB
248-
[0,200000): write-only [1B/op, 0ops/s]
263+
[0,200000): write-only [1B/op, 0ops/s]
264+
249265
initial state at 2022-03-21 11:00:00:
250266
stores(3)=[s1n1=(replicas(10)),s2n2=(replicas(10)),s3n3=(replicas(10))]
251267
topology:
@@ -255,6 +271,8 @@ AU_EAST
255271
no events were scheduled
256272
sample3: pass
257273
----------------------------------
274+
----
275+
----
258276

259277
clear
260278
----

pkg/kv/kvserver/asim/tests/testdata/rand/rand_cluster.txt

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,37 @@ rand_cluster cluster_gen_type=single_region
88

99
eval duration=5m num_iterations=3 verbose=(config_gen)
1010
----
11+
----
1112
----------------------------------
1213
sample1: start running
1314
configurations generated using seed 608747136543856411
1415
cluster: region:US [zone=US_1(nodes=1,stores=5), zone=US_2(nodes=1,stores=5), zone=US_3(nodes=1,stores=5)]
1516
store_disk_capacity=1099511627776 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
1617
[0,200000): 10(rf=3), 0MiB
17-
[0,200000): write-only [1B/op, 0ops/s]
18+
[0,200000): write-only [1B/op, 0ops/s]
19+
1820
sample1: pass
1921
----------------------------------
2022
sample2: start running
2123
configurations generated using seed 1926012586526624009
2224
cluster: region:US [zone=US_1(nodes=5,stores=1), zone=US_2(nodes=5,stores=1), zone=US_3(nodes=5,stores=1)]
2325
store_disk_capacity=1099511627776 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
2426
[0,200000): 10(rf=3), 0MiB
25-
[0,200000): write-only [1B/op, 0ops/s]
27+
[0,200000): write-only [1B/op, 0ops/s]
28+
2629
sample2: pass
2730
----------------------------------
2831
sample3: start running
2932
configurations generated using seed 3534334367214237261
3033
cluster: region:US [zone=US_1(nodes=1,stores=5), zone=US_2(nodes=1,stores=5), zone=US_3(nodes=1,stores=5)]
3134
store_disk_capacity=1099511627776 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
3235
[0,200000): 10(rf=3), 0MiB
33-
[0,200000): write-only [1B/op, 0ops/s]
36+
[0,200000): write-only [1B/op, 0ops/s]
37+
3438
sample3: pass
3539
----------------------------------
40+
----
41+
----
3642

3743
clear
3844
----
@@ -42,6 +48,7 @@ rand_cluster cluster_gen_type=multi_region
4248

4349
eval duration=5m num_iterations=3 verbose=(all)
4450
----
51+
----
4552
test settings
4653
num_iterations=3 duration=5m0s
4754
----------------------------------
@@ -61,7 +68,8 @@ region:US_West [zone=US_West_1(nodes=2,stores=1)]
6168
region:EU [zone=EU_1(nodes=3,stores=1), zone=EU_2(nodes=3,stores=1), zone=EU_3(nodes=4,stores=1)]
6269
store_disk_capacity=2199023255552 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
6370
[0,200000): 10(rf=3), 0MiB
64-
[0,200000): write-only [1B/op, 0ops/s]
71+
[0,200000): write-only [1B/op, 0ops/s]
72+
6573
initial state at 2022-03-21 11:00:00:
6674
stores(28)=[s1n1=(replicas(1)),s2n2=(replicas(1)),s3n3=(replicas(1)),s4n4=(replicas(1)),s5n5=(replicas(1)),s6n6=(replicas(1)),s7n7=(replicas(1)),s8n8=(replicas(1)),s9n9=(replicas(2)),s10n10=(replicas(1)),s11n11=(replicas(1)),s12n12=(replicas(1)),s13n13=(replicas(1)),s14n14=(replicas(1)),s15n15=(replicas(1)),s16n16=(replicas(1)),s17n17=(replicas(1)),s18n18=(replicas(1)),s19n19=(replicas(1)),s20n20=(replicas(1)),s21n21=(replicas(1)),s22n22=(replicas(2)),s23n23=(replicas(1)),s24n24=(replicas(1)),s25n25=(replicas(1)),s26n26=(replicas(1)),s27n27=(replicas(1)),s28n28=(replicas(1))]
6775
topology:
@@ -94,7 +102,8 @@ region:US_West [zone=US_West_1(nodes=4,stores=1), zone=US_West_2(nodes=4,stores=
94102
region:EU [zone=EU_1(nodes=4,stores=1), zone=EU_2(nodes=4,stores=1), zone=EU_3(nodes=4,stores=1)]
95103
store_disk_capacity=2199023255552 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
96104
[0,200000): 10(rf=3), 0MiB
97-
[0,200000): write-only [1B/op, 0ops/s]
105+
[0,200000): write-only [1B/op, 0ops/s]
106+
98107
initial state at 2022-03-21 11:00:00:
99108
stores(36)=[s1n1=(replicas(1)),s2n2=(replicas(1)),s3n3=(replicas(1)),s4n4=(replicas(1)),s5n5=(replicas(1)),s6n6=(replicas(1)),s7n7=(replicas(0)),s8n8=(replicas(1)),s9n9=(replicas(1)),s10n10=(replicas(1)),s11n11=(replicas(1)),s12n12=(replicas(1)),s13n13=(replicas(0)),s14n14=(replicas(1)),s15n15=(replicas(0)),s16n16=(replicas(0)),s17n17=(replicas(1)),s18n18=(replicas(1)),s19n19=(replicas(1)),s20n20=(replicas(1)),s21n21=(replicas(1)),s22n22=(replicas(1)),s23n23=(replicas(1)),s24n24=(replicas(1)),s25n25=(replicas(1)),s26n26=(replicas(1)),s27n27=(replicas(1)),s28n28=(replicas(0)),s29n29=(replicas(1)),s30n30=(replicas(1)),s31n31=(replicas(0)),s32n32=(replicas(1)),s33n33=(replicas(1)),s34n34=(replicas(1)),s35n35=(replicas(1)),s36n36=(replicas(1))]
100109
topology:
@@ -129,7 +138,8 @@ region:US_West [zone=US_West_1(nodes=2,stores=1)]
129138
region:EU [zone=EU_1(nodes=3,stores=1), zone=EU_2(nodes=3,stores=1), zone=EU_3(nodes=4,stores=1)]
130139
store_disk_capacity=2199023255552 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
131140
[0,200000): 10(rf=3), 0MiB
132-
[0,200000): write-only [1B/op, 0ops/s]
141+
[0,200000): write-only [1B/op, 0ops/s]
142+
133143
initial state at 2022-03-21 11:00:00:
134144
stores(28)=[s1n1=(replicas(1)),s2n2=(replicas(1)),s3n3=(replicas(1)),s4n4=(replicas(1)),s5n5=(replicas(1)),s6n6=(replicas(1)),s7n7=(replicas(1)),s8n8=(replicas(1)),s9n9=(replicas(2)),s10n10=(replicas(1)),s11n11=(replicas(1)),s12n12=(replicas(1)),s13n13=(replicas(1)),s14n14=(replicas(1)),s15n15=(replicas(1)),s16n16=(replicas(1)),s17n17=(replicas(1)),s18n18=(replicas(1)),s19n19=(replicas(1)),s20n20=(replicas(1)),s21n21=(replicas(1)),s22n22=(replicas(2)),s23n23=(replicas(1)),s24n24=(replicas(1)),s25n25=(replicas(1)),s26n26=(replicas(1)),s27n27=(replicas(1)),s28n28=(replicas(1))]
135145
topology:
@@ -155,6 +165,8 @@ US_West
155165
no events were scheduled
156166
sample3: pass
157167
----------------------------------
168+
----
169+
----
158170

159171
clear
160172
----
@@ -164,21 +176,24 @@ rand_cluster cluster_gen_type=any_region
164176

165177
eval duration=5m num_iterations=3 verbose=(config_gen)
166178
----
179+
----
167180
----------------------------------
168181
sample1: start running
169182
configurations generated using seed 608747136543856411
170183
cluster: region:US [zone=US_1(nodes=1,stores=5), zone=US_2(nodes=1,stores=5), zone=US_3(nodes=1,stores=5)]
171184
store_disk_capacity=1099511627776 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
172185
[0,200000): 10(rf=3), 0MiB
173-
[0,200000): write-only [1B/op, 0ops/s]
186+
[0,200000): write-only [1B/op, 0ops/s]
187+
174188
sample1: pass
175189
----------------------------------
176190
sample2: start running
177191
configurations generated using seed 1926012586526624009
178192
cluster: region:US [zone=US_1(nodes=5,stores=1), zone=US_2(nodes=5,stores=1), zone=US_3(nodes=5,stores=1)]
179193
store_disk_capacity=1099511627776 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
180194
[0,200000): 10(rf=3), 0MiB
181-
[0,200000): write-only [1B/op, 0ops/s]
195+
[0,200000): write-only [1B/op, 0ops/s]
196+
182197
sample2: pass
183198
----------------------------------
184199
sample3: start running
@@ -188,6 +203,9 @@ region:US_West [zone=US_West_1(nodes=2,stores=1)]
188203
region:EU [zone=EU_1(nodes=3,stores=1), zone=EU_2(nodes=3,stores=1), zone=EU_3(nodes=4,stores=1)]
189204
store_disk_capacity=2199023255552 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
190205
[0,200000): 10(rf=3), 0MiB
191-
[0,200000): write-only [1B/op, 0ops/s]
206+
[0,200000): write-only [1B/op, 0ops/s]
207+
192208
sample3: pass
193209
----------------------------------
210+
----
211+
----

pkg/kv/kvserver/asim/tests/testdata/rand/rand_event.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ region:US_West [zone=US_West_1(nodes=2,stores=1)]
3030
region:EU [zone=EU_1(nodes=3,stores=1), zone=EU_2(nodes=3,stores=1), zone=EU_3(nodes=4,stores=1)]
3131
store_disk_capacity=2199023255552 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
3232
[0,200000): 1(rf=3), 0MiB
33-
[0,200000): write-only [1B/op, 0ops/s] [0000000000,9999999999): 3voters,2nonvoters [replicas:{1:region=US_East}{1:region=US_West}{1:region=EU}] [voters:{0:region=EU}] [lease:{region=EU}]
33+
[0,200000): write-only [1B/op, 0ops/s]
34+
[0000000000,9999999999): 3voters,2nonvoters [replicas:{1:region=US_East}{1:region=US_West}{1:region=EU}] [voters:{0:region=EU}] [lease:{region=EU}]
3435
assertion checking event
3536
1. assertion=conformance unavailable=0 under=0 over=0 violating=0 lease-violating=0 lease-less-preferred=0
3637
passed at 11:05:00

0 commit comments

Comments
 (0)