# SPDX-License-Identifier: Apache-2.0

#
# Run with synthetically generated access events with a looping scan through ids.
#
# > cluster-sharding/Test/runMain org.apache.pekko.cluster.sharding.passivation.simulator.Simulator synthetic-loop
#
#   ╔═════════════════════╤═════════╤════════════╤═════════════╤══════════════╗
#   ║                 Run │  Active │   Accesses │ Activations │ Passivations ║
#   ╠═════════════════════╪═════════╪════════════╪═════════════╪══════════════╣
#   ║            LRU 500k │  0.00 % │ 10,000,000 │  10,000,000 │    9,500,000 ║
#   ╟─────────────────────┼─────────┼────────────┼─────────────┼──────────────╢
#   ║            MRU 500k │ 45.00 % │ 10,000,000 │   5,500,000 │    5,000,000 ║
#   ╟─────────────────────┼─────────┼────────────┼─────────────┼──────────────╢
#   ║    LRU/FS/SLRU 500k │ 44.24 % │ 10,000,000 │   5,576,284 │    5,076,284 ║
#   ╟─────────────────────┼─────────┼────────────┼─────────────┼──────────────╢
#   ║ LRU/FS/SLRU/HC 500k │ 44.24 % │ 10,000,000 │   5,576,284 │    5,076,284 ║
#   ╚═════════════════════╧═════════╧════════════╧═════════════╧══════════════╝
#

pekko.cluster.sharding {
  passivation.simulator {
    runs = [
      {
        name = "LRU 500k"
        shards = 100
        regions = 10
        pattern = loop-1M
        strategy = lru-50k
      },
      {
        name = "MRU 500k"
        shards = 100
        regions = 10
        pattern = loop-1M
        strategy = mru-50k
      },
      {
        name = "LRU/FS/SLRU 500k"
        shards = 100
        regions = 10
        pattern = loop-1M
        strategy = lru-fs-slru-50k
      },
      {
        name = "LRU/FS/SLRU/HC 500k"
        shards = 100
        regions = 10
        pattern = loop-1M
        strategy = lru-fs-slru-hc-50k
      },
    ]

    print-detailed-stats = true

    # looping sequence of ids
    # generate 10M events over 1M ids
    loop-1M {
      pattern = synthetic
      synthetic {
        events = 10000000
        generator = loop
        loop {
          start = 1
          end = 1000000
        }
      }
    }

    # LRU strategy with 50k limit in each of 10 regions
    # total limit across cluster of 500k (50% of id space)
    lru-50k {
      strategy = least-recently-used
      least-recently-used {
        per-region-limit = 50000
      }
    }

    # MRU strategy with 50k limit in each of 10 regions
    # total limit across cluster of 500k (50% of id space)
    mru-50k {
      strategy = most-recently-used
      most-recently-used {
        per-region-limit = 50000
      }
    }

    lru-fs-slru {
      strategy = composite
      composite {
        admission {
          window.strategy = least-recently-used
          filter = frequency-sketch
          optimizer = none
        }
        main {
          strategy = least-recently-used
          least-recently-used {
            segmented {
              levels = 2
              proportions = [0.2, 0.8]
            }
          }
        }
      }
    }

    lru-fs-slru-50k = ${pekko.cluster.sharding.passivation.simulator.lru-fs-slru} {
      composite.per-region-limit = 50000
    }

    lru-fs-slru-hc = ${pekko.cluster.sharding.passivation.simulator.lru-fs-slru} {
      composite.admission.optimizer = hill-climbing
    }

    lru-fs-slru-hc-50k = ${pekko.cluster.sharding.passivation.simulator.lru-fs-slru-hc} {
      composite.per-region-limit = 50000
    }

  }
}
