# SPDX-License-Identifier: Apache-2.0

#
# Run the 14-day Wikipedia trace from 2018 (wiki2018.tr) from the LRB simulator.
#
# Learning Relaxed Belady for Content Distribution Network Caching
# Zhenyu Song, Daniel S. Berger, Kai Li, Wyatt Lloyd
#
# Download traces from the simulator (uncompressed trace is 54 GB):
# https://github.com/sunnyszy/lrb#traces
#
# Trace is 2.8 billion accesses with around 37.5 million unique ids.
# Active entity limit of 100k is just over 0.1% of the id space.
# The most popular 100k ids account for almost half of the accesses.
#
# > cluster-sharding/Test/runMain org.apache.pekko.cluster.sharding.passivation.simulator.Simulator wikipedia-trace-2018
#
#   ╔═════════════════════╤═════════╤═══════════════╤═══════════════╤═══════════════╗
#   ║                 Run │  Active │      Accesses │   Activations │  Passivations ║
#   ╠═════════════════════╪═════════╪═══════════════╪═══════════════╪═══════════════╣
#   ║            LRU 100k │ 53.48 % │ 2,800,000,000 │ 1,302,519,161 │ 1,302,419,161 ║
#   ╟─────────────────────┼─────────┼───────────────┼───────────────┼───────────────╢
#   ║           SLRU 100k │ 60.89 % │ 2,800,000,000 │ 1,095,063,465 │ 1,094,963,465 ║
#   ╟─────────────────────┼─────────┼───────────────┼───────────────┼───────────────╢
#   ║          S4LRU 100k │ 60.66 % │ 2,800,000,000 │ 1,101,617,318 │ 1,101,517,318 ║
#   ╟─────────────────────┼─────────┼───────────────┼───────────────┼───────────────╢
#   ║            MRU 100k │  5.70 % │ 2,800,000,000 │ 2,640,279,048 │ 2,640,179,048 ║
#   ╟─────────────────────┼─────────┼───────────────┼───────────────┼───────────────╢
#   ║            LFU 100k │ 58.17 % │ 2,800,000,000 │ 1,171,104,161 │ 1,171,004,161 ║
#   ╟─────────────────────┼─────────┼───────────────┼───────────────┼───────────────╢
#   ║          LFUDA 100k │ 60.01 % │ 2,800,000,000 │ 1,119,687,614 │ 1,119,587,614 ║
#   ╟─────────────────────┼─────────┼───────────────┼───────────────┼───────────────╢
#   ║    LRU/FS/SLRU 100k │ 61.81 % │ 2,800,000,000 │ 1,069,272,588 │ 1,069,172,588 ║
#   ╟─────────────────────┼─────────┼───────────────┼───────────────┼───────────────╢
#   ║ LRU/FS/SLRU/HC 100k │ 60.54 % │ 2,800,000,000 │ 1,104,800,099 │ 1,104,700,099 ║
#   ╚═════════════════════╧═════════╧═══════════════╧═══════════════╧═══════════════╝
#

wiki-traces="wiki-traces"
wiki-traces=${?WIKI_TRACES}

pekko.cluster.sharding {
  passivation.simulator {
    runs = [
#       {
#         name = "LRU 100k"
#         shards = 100
#         regions = 10
#         pattern = wiki-2018
#         strategy = lru-10k
#       },
#       {
#         name = "SLRU 100k"
#         shards = 100
#         regions = 10
#         pattern = wiki-2018
#         strategy = slru-10k
#       },
#       {
#         name = "S4LRU 100k"
#         shards = 100
#         regions = 10
#         pattern = wiki-2018
#         strategy = s4lru-10k
#       },
#       {
#         name = "MRU 100k"
#         shards = 100
#         regions = 10
#         pattern = wiki-2018
#         strategy = mru-10k
#       },
#       {
#         name = "LFU 100k"
#         shards = 100
#         regions = 10
#         pattern = wiki-2018
#         strategy = lfu-10k
#       },
#       {
#         name = "LFUDA 100k"
#         shards = 100
#         regions = 10
#         pattern = wiki-2018
#         strategy = lfuda-10k
#       },
      {
        name = "LRU/FS/SLRU 100k"
        shards = 100
        regions = 10
        pattern = wiki-2018
        strategy = lru-fs-slru-10k
      },
      {
        name = "LRU/FS/SLRU/HC 100k"
        shards = 100
        regions = 10
        pattern = wiki-2018
        strategy = lru-fs-slru-hc-10k
      },
    ]

    print-detailed-stats = true

    wiki-2018 {
      pattern = trace
      trace {
        format = wikipedia
        path = ${wiki-traces}"/wiki2018.tr"
      }
    }

    lru-10k {
      strategy = least-recently-used
      least-recently-used {
        per-region-limit = 10000
      }
    }

    slru-10k {
      strategy = least-recently-used
      least-recently-used {
        per-region-limit = 10000
        segmented {
          levels = 2
          proportions = [0.2, 0.8]
        }
      }
    }

    s4lru-10k {
      strategy = least-recently-used
      least-recently-used {
        per-region-limit = 10000
        segmented.levels = 4
      }
    }

    mru-10k {
      strategy = most-recently-used
      most-recently-used {
        per-region-limit = 10000
      }
    }

    lfu-10k {
      strategy = least-frequently-used
      least-frequently-used {
        per-region-limit = 10000
      }
    }

    lfuda-10k {
      strategy = least-frequently-used
      least-frequently-used {
        per-region-limit = 10000
        dynamic-aging = on
      }
    }

    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-10k = ${pekko.cluster.sharding.passivation.simulator.lru-fs-slru} {
      composite.per-region-limit = 10000
    }

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

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

  }
}
