# Walk through the basics of the datadriven syntax. Create a state generator
# where there are 7 stores, 7 ranges and initially the replicas are placed
# following a skewed distribution (where s1 has the most replicas, s2 has half
# as many as s1...).
gen_cluster nodes=7
----

gen_ranges ranges=7 placement_skew=true
----

# Create a load generator, where there are 7k ops/s and the access follows a
# zipfian distribution on the keyspace.
gen_load rate=7000 rw_ratio=0.95 access_skew=false min_block=128 max_block=256
----

# Add two assertions, the first is a balance assertion. The balance assertion
# requires that when simulation is evaluated that during last 6 ticks (60
# seconds) the max/mean QPS of the cluster does not exceed 1.15.
assertion stat=qps type=balance ticks=6 upper_bound=1.15
----

# The second is a steady state assertion. The steady state assertion requires
# that during the last 6 ticks (60 seconds), the value of QPS per-store doesn't
# increase or decrease by more than 5% of the mean. This type of assertion is
# useful when a stat is balanced but not necessarily stable.
assertion stat=qps type=steady ticks=6 upper_bound=0.05
----

# The generators are then called and 2 simulation runs, named samples are
# created and evaluated. Each sample has a fixed duration of 5 minutes.
# Following the evaluation, the samples are checked individually against the
# existing assertions, added above. If any assertion fails, the reason is
# printed. If no assertions fail, then OK is printed.
eval duration=3m samples=2 seed=42
----
OK

# It is possible to plot the output of a stat, of a selected sample run. Below
# the last sample run is selected and the QPS is plotted per store. This is
# useful to determine the QPS matches out expectations - it should be balanced
# and stable. This should only be done for tests where the seed is given, so
# the output is identical..
plot stat=qps sample=2
----
----

 5021 ┤ ╭╮
 4686 ┤ ││
 4351 ┤ │╰╮
 4017 ┤ │ ╰──────────────────────╮
 3682 ┤ │                        │
 3347 ┤ │                        │
 3013 ┤ │                        │
 2678 ┤ │                        │
 2343 ┤ │                        ╰╮
 2008 ┤ │                         │ ╭───────────────────────╮
 1674 ┤ │                         │╭╯                       │
 1339 ┤ │                         ││                        │
 1004 ┤ │ ╭────────────────────────╯╭─────────────────────────────────────────────────
  669 ┤ │╭│ │                       │                         │
  335 ┤ │││ │                       │                         │
    0 ┼─────────────────────────────╯─────────────────────────╯
                                             qps
----
----

# The cluster settings and simulation variables can be modified to examine how
# allocation behaves during uncommon scenarios. Update the gossip delay to be
# unreasonably long (default 500ms).
setting gossip_delay=20s
----

# Evaluate with the updated gossip setting but otherwise identical generators
# and seed. Here we see that neither the balance assertion nor steady state
# assertion is reached due to how the system reacts to the long gossip delays.
eval duration=5m samples=2 seed=42
----
OK

# To investigate further, plot the QPS output again. The plotted output matches
# expectations given the assertion failed, The system exhibits thrashing as
# rebalancing occurs frequently but without actually achieving convergence.
plot stat=qps sample=3
----
----

 7000 ┤ ╭───╮
 6533 ┤ │   │
 6067 ┤ │   │
 5600 ┤ │   ╰╮
 5133 ┤ │    │
 4667 ┤ │    │
 4200 ┤ │    │
 3733 ┤ │    │
 3267 ┤ │    │
 2800 ┤ │    ╰╮╭────╮╭─╮ ╭────────────╮ ╭─────────────╮
 2333 ┤ │     ││    ││ │ │            ╰╮│             │
 1867 ┤ │     ╭╯╭───│╯─│─╯─────╮ ╭─────╮│             ╰╮
 1400 ┤ │     │ │   │ ││ │     │ │     ││              │
  933 ┤ │    ╭│╭╯   │╭╯╰╭───────────────│──────────────╰──────────────────────────────
  467 ┤ │    │││    ││  │       │      ││               │
    0 ┼─────────────────────────────────╯───────────────╯
                                             qps
----
----

# Plot the replica movements for the same sample, we should see a steadily
# increasing counter for each store; indicating that rebalancing activity is
# persistent.
plot stat=replica_moves sample=3
----
----

 14.00 ┤                         ╭─────────────────────────────────────────────────────
 13.07 ┤                        ╭╯
 12.13 ┤                ╭───────╯
 11.20 ┤        ╭───────╯
 10.27 ┤       ╭╯
  9.33 ┤       │
  8.40 ┤       │
  7.47 ┤       │
  6.53 ┤      ╭╯
  5.60 ┤      │                         ╭──────────────────────────────────────────────
  4.67 ┤      │      ╭─────────────────────────────────────────────────────────────────
  3.73 ┤      │      │   ╭──────────────╯
  2.80 ┤     ╭╯      │  ╭╯──────╯
  1.87 ┤     │  ╭────╯──╯──────╭───────────────────────────────────────────────────────
  0.93 ┤     │╭╭╯────│  ╭──────╯                        ╭──────────────────────────────
  0.00 ┼────────────────────────────────────────────────╯
                                         replica_moves
----
----

# vim:ft=sh
