|
1 | 1 | # Cache Simulation
|
2 | 2 |
|
3 |
| -[TBD] |
| 3 | +## Basic Usage |
| 4 | + |
| 5 | +The cache classes are the core of cache simulation. When an instance of a cache is creates (e.g., `LRU`, `S3FIFO`), we can configure the cache size and any cache-specific parameters such as promotion thresholds. |
| 6 | + |
| 7 | +```py |
| 8 | +import libcachesim as lcs |
| 9 | + |
| 10 | +# Initialize cache |
| 11 | +cache = lcs.S3FIFO( |
| 12 | + cache_size=1024 * 1024, |
| 13 | + # Cache specific parameters |
| 14 | + small_size_ratio=0.2, |
| 15 | + ghost_size_ratio=0.8, |
| 16 | + move_to_main_threshold=2, |
| 17 | +) |
| 18 | +``` |
| 19 | + |
| 20 | +Admission policies are optional - if none is provided, the cache will simply admit all objects according to the replacement policy. An admissioner (e.g., `BloomFilterAdmissioner`) can be placed infront of the cache by specifying the `admissioner` argument. |
| 21 | + |
| 22 | +```py |
| 23 | +import libcachesim as lcs |
| 24 | + |
| 25 | +# Initialize admissioner |
| 26 | +admissioner = lcs.BloomFilterAdmissioner() |
| 27 | + |
| 28 | +# Step 2: Initialize cache |
| 29 | +cache = lcs.S3FIFO( |
| 30 | + cache_size=1024 * 1024, |
| 31 | + # Cache specific parameters |
| 32 | + small_size_ratio=0.2, |
| 33 | + ghost_size_ratio=0.8, |
| 34 | + move_to_main_threshold=2, |
| 35 | + # Optionally provide admissioner |
| 36 | + admissioner=admissioner, |
| 37 | +) |
| 38 | +``` |
| 39 | + |
| 40 | +Then we can run cache simulations using real world workloads leveraging trace readers (see [Trace Reader](reader.md) for more on using `TraceReader`): |
| 41 | + |
| 42 | +```py |
| 43 | +# Process entire trace efficiently (C++ backend) |
| 44 | +req_miss_ratio, byte_miss_ratio = cache.process_trace(reader) |
| 45 | +print(f"Request miss ratio: {req_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}") |
| 46 | +``` |
| 47 | + |
| 48 | +## Caches |
| 49 | +The following cache classes all inherit from `CacheBase` and share a common interface, sharing the following arguments in all cache classes unless otherwise specified: |
| 50 | + |
| 51 | +- `cache_size: int` |
| 52 | +- `default_ttl: int` (optional) |
| 53 | +- `hashpower: int` (optional) |
| 54 | +- `consider_obj_metadata: bool` (optional) |
| 55 | +- `admissioner: AdmissionerBase` (optional) |
| 56 | + |
| 57 | +### LHD |
| 58 | +**Lest Hit Density** evicts objects based on each objects expected hits-per-space-consumed (hit density). |
| 59 | + |
| 60 | +- *No additional parameters beyond the common arguments* |
| 61 | + |
| 62 | +### LRU |
| 63 | +**Least Recently Used** evicts the object that has not been accessed for the longest time. |
| 64 | + |
| 65 | +- *No additional parameters beyond the common arguments* |
| 66 | + |
| 67 | +### FIFO |
| 68 | +**First-In, First-Out** evicts objects in order regardless of frequency or recency. |
| 69 | + |
| 70 | +- *No additional parameters beyond the common arguments* |
| 71 | + |
| 72 | +### LFU |
| 73 | +**Least Frequently Used** evicts the object with the lowest access frequency. |
| 74 | + |
| 75 | +- *No additional parameters beyond the common arguments* |
| 76 | + |
| 77 | +### Arc |
| 78 | +**Adaptive Replacement Cache** a hybrid algorithm which balances recency and frequency. |
| 79 | + |
| 80 | +- *No additional parameters beyond the common arguments* |
| 81 | + |
| 82 | +### Clock |
| 83 | +**Clock** is an low-complexity approximation of `LRU`. |
| 84 | + |
| 85 | +- `int_freq: int` - Initial frequency counter value which is used for new objects (default: `0`) |
| 86 | +- `n_bit_counter: int` - Number of bits used for the frequency counter (default: `1`) |
| 87 | + |
| 88 | +### Random |
| 89 | +**Random** evicts objects at random. |
| 90 | + |
| 91 | +- *No additional parameters beyond the common arguments* |
| 92 | + |
| 93 | +### S3FIFO |
| 94 | +[TBD] |
| 95 | + |
| 96 | +### Sieve |
| 97 | +[TBD] |
| 98 | + |
| 99 | +### LIRS |
| 100 | +[TBD] |
| 101 | + |
| 102 | +### TwoQ |
| 103 | +[TBD] |
| 104 | + |
| 105 | +### SLRU |
| 106 | +[TBD] |
| 107 | + |
| 108 | +### WTinyLFU |
| 109 | +[TBD] |
| 110 | + |
| 111 | +### LeCaR |
| 112 | +[TBD] |
| 113 | + |
| 114 | +### LFUDA |
| 115 | +[TBD] |
| 116 | + |
| 117 | +### ClockPro |
| 118 | +[TBD] |
| 119 | + |
| 120 | +### Cacheus |
| 121 | +[TBD] |
| 122 | + |
| 123 | +### Belady |
| 124 | +[TBD] |
| 125 | + |
| 126 | +### BeladySize |
| 127 | +[TBD] |
| 128 | + |
| 129 | +### LRUProb |
| 130 | +[TBD] |
| 131 | + |
| 132 | +### FlashProb |
| 133 | +[TBD] |
| 134 | + |
| 135 | +### GDSF |
| 136 | +[TBD] |
| 137 | + |
| 138 | +### Hyperbolic |
| 139 | +[TBD] |
| 140 | + |
| 141 | +### ThreeLCache |
| 142 | +[TBD] |
| 143 | + |
| 144 | +### GLCache |
| 145 | +[TBD] |
| 146 | + |
| 147 | +### LRB |
| 148 | +[TBD] |
| 149 | + |
| 150 | +## Admission Policies |
| 151 | + |
| 152 | +### BloomFilterAdmissioner |
| 153 | +Uses a Bloom filter to decide admissions based on how many times an object has been seen. |
| 154 | + |
| 155 | +- *No parameters* |
| 156 | + |
| 157 | +### ProbAdmissioner |
| 158 | +Admits objects with a fixed probability. |
| 159 | + |
| 160 | +- `prob: float` (optional) - Probability of admitting an object (default: `0.5`) |
| 161 | + |
| 162 | +### SizeAdmissioner |
| 163 | +Admits objects only if they are below a specified size threshold. |
| 164 | + |
| 165 | +- `size_threshold: int` (optional) - Maximum allowed object size (in bytes) for admission (default: `9_223_372_036_854_775_807`, or `INT64_MAX`) |
| 166 | + |
| 167 | +### SizeProbabilisticAdmissioner |
| 168 | +Admits objects with a probability that decreases with object size, favoring smaller objects over large. |
| 169 | + |
| 170 | +- `exponent: float` (optional) - Exponent controlling how aggressively larger objects are filtered out (default: `1e-6`) |
| 171 | + |
| 172 | +### AdaptSizeAdmissioner |
| 173 | +Implements **AdaptSize**, a feedback-driven policy that periodically adjusts its size threshold. |
| 174 | + |
| 175 | +- `max_iteration: int` (optional) - Maximum number of iterators for parameter tuning (default: `15`) |
| 176 | +- `reconf_interval: int` (optional) - Interval (with respect to request count) at which the threshold is re-evaluated (default: `30_000`) |
0 commit comments