-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Simulator
The simulator allows for experimenting with different cache configurations to determine the best balance between the size and hit rate. Tracing is required to capture a snapshot of the application's cache activity.
The simulator includes a family of eviction policies and distribution generators. As each policy is a decision of trade-offs, the simulator allows developers to determine which policy is best for their usage scenario. A general purpose cache, like the one provided by Caffeine, should evaluate policies that improve upon LRU. Specialized application-specific caches, such as off-heap, can utilize this infrastructure as well.
The simulator is implemented using Akka where each policy is an actor. The default configuration can be overridden by system properties or an application.conf file. It can be run locally using,
# Run a simulation against a local trace file
gradlew simulator:run -Dcaffeine.simulator.source=file -Dcaffeine.simulator.file.path=trace.log
# Run a simulation against a generated data set
gradlew simulator:run -Dcaffeine.simulator.source=synthetic -Dcaffeine.simulator.synthetic.size=1000A report can be printed to the console or a file. The output lists the hit rate of the eviction policies that were evaluated, e.g.
╔═════════════════════════════╤══════════╤════════════╤═══════════╤═════════╗
║ Policy │ Hit rate │ Requests │ Evictions │ Time ║
╠═════════════════════════════╪══════════╪════════════╪═══════════╪═════════╣
║ opt.Clairvoyant │ 59.05 % │ 10,430,564 │ 4,270,817 │ 15.09 s ║
╟─────────────────────────────┼──────────┼────────────┼───────────┼─────────╢
║ linked.Lru_TinyLfu │ 57.04 % │ 10,430,564 │ 4,480,651 │ 16.87 s ║
╟─────────────────────────────┼──────────┼────────────┼───────────┼─────────╢
║ adaptive.Arc │ 56.33 % │ 10,430,564 │ 4,554,140 │ 8.451 s ║
╟─────────────────────────────┼──────────┼────────────┼───────────┼─────────╢
║ two-queue.TwoQueue │ 55.57 % │ 10,430,564 │ 4,601,748 │ 8.942 s ║
╟─────────────────────────────┼──────────┼────────────┼───────────┼─────────╢
║ linked.Lru │ 46.62 % │ 10,430,564 │ 5,567,011 │ 7.544 s ║
╟─────────────────────────────┼──────────┼────────────┼───────────┼─────────╢
║ linked.Fifo │ 41.87 % │ 10,430,564 │ 6,062,391 │ 7.548 s ║
╚═════════════════════════════╧══════════╧════════════╧═══════════╧═════════╝

