You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary:
Fixing some inaccuracies and adding documentation around some configs.
___
overriding_review_checks_triggers_an_audit_and_retroactive_review
Oncall Short Name: cachelib
Differential Revision: D104251642
fbshipit-source-id: b478a5f7c69cca06511dc7b8723e9e265b6ea83c
You can also override the rebalance strategy for a specific pool by passing a
93
+
strategy to `addPool()` or by calling `overridePoolRebalanceStrategy()`.
60
94
61
95
### Picking a strategy
62
96
63
-
Cachelib offers a few pre-package strategies for rebalancing that you can pick
97
+
Cachelib offers a few pre-packaged strategies for rebalancing that you can pick
64
98
from. They differ by what they try to optimize for based on traditional wisdom
65
99
of large scale caches like social graph caches and general purpose look-aside
66
100
key value caches. These are good defaults to start with, but you can also come
67
101
up with your own implementation if you have other goals.
68
102
69
-
#### Lru TailAge
103
+
#### Base strategy
70
104
71
-
LruTailAge is a fair policy that ensures that objects of different sizes get the same eviction age in cache. For example, in steady state for your cache, you could have 100 byte objects getting 1 hr lifetime vs 1000 byte objects getting 30 min lifetime. This strategy tries to make the eviction age for various sizes similar. You can configure the following parameters(LruTailAgeStrategy::Config) (whose default values are pretty good to begin with):
105
+
`RebalanceStrategy` is the default strategy. It does not optimize hit rate or
106
+
eviction-age fairness. It only helps allocation classes that have seen
107
+
allocation failures since the previous rebalancer run. This is a conservative
108
+
default that helps a class get at least one slab when it cannot allocate or
109
+
evict within its current allocation class.
72
110
73
-
*`tailAgeDiffRatio`
111
+
#### LRU Tail Age
112
+
113
+
`LruTailAgeStrategy` is a fair policy that tries to make objects of different
114
+
sizes get similar eviction ages in cache. For example, in steady state for your
115
+
cache, you could have 100 byte objects getting a 1 hour lifetime while 1,000
116
+
byte objects get a 30 minute lifetime. This strategy picks the allocation class
117
+
with the oldest projected eviction age as the victim and the allocation class
118
+
with the youngest eviction age as the receiver.
119
+
120
+
You can configure the following parameters in `LruTailAgeStrategy::Config`:
121
+
122
+
*`tailAgeDifferenceRatio`
74
123
This defines how tight the tail age of various object sizes you want them to be. Setting it to 0.1 means that you don't want the min and max age to differ by more than 10%.
75
124
76
125
*`minTailAgeDifference`
@@ -80,51 +129,111 @@ This specifies a threshold of how big the actual diff ratio should be to warrant
80
129
This specifies the minimum amount of memory in slabs that specific object size can not go below while rebalancing. Keep in mind that this is specified in slabs and not in bytes.
81
130
82
131
*`numSlabsFreeMem`
83
-
When you specify rebalancing under this mode, cachlib aggressively moves memory from object sizes that have a lot of free memory. This specifies the threshold for triggering that behavior.
132
+
If an allocation class has more than this many slabs worth of free memory
133
+
(i.e. `numSlabsFreeMem * Slab::kSize` bytes) and has not recently evicted,
134
+
it is prioritized as a victim.
84
135
85
136
*`slabProjectionLength`
86
-
This lets you estimate the min and max by picking a projected eviction age instead of the real eviction age. This can sometimes let you get better results.
137
+
How many slabs worth of items to project when computing the victim's
138
+
projected tail age.
87
139
88
-
For example:
140
+
*`queueSelector`
141
+
Which eviction-age queue to use: hot, warm, or cold. Not every eviction
142
+
policy has separate hot, warm, and cold queues; when it does not, the policy
143
+
defines how these values map to its available eviction-age stats.
89
144
145
+
*`getWeight`
146
+
An optional weight function for weighted tail age. When this is set,
147
+
`tailAgeDifferenceRatio` and `minTailAgeDifference` are ignored.
`HitsPerSlabStrategy` tries to optimize the overall hit ratio rather than ensuring a fairness in the cache eviction age. This should result in a relatively higher hit ratio. However, it might potentially make your cache contain more of objects that give hits vs. objects that are expensive to recompute. For example, the cost of miss on objects is not uniform.
103
164
104
-
HitBased approach tries to optimize the overall hit ratio rather than ensuring a fairness in the cache eviction age. This should result in a relatively higher hit ratio. However, it might potentially make your cache contain more of objects that give hits vs. objects that are expensive to recompute. For example, the cost of miss on objects is not uniform. To control the downsides of such implications, cachelib offers these parameters(HitsPerSlabStrategy::Config). Most of these are similar to the LruTailAge parameters, however, their semantics could slightly differ in the following ways:
165
+
You can configure the following parameters in `HitsPerSlabStrategy::Config`:
105
166
106
167
* `minDiff`
107
-
Like tailAgeDiffRatio, this controls the minimum improvement that should trigger a rebalancing.
168
+
The minimum absolute improvement in hits per slab required before a rebalance
169
+
happens.
170
+
171
+
* `diffRatio`
172
+
The minimum relative improvement required before a rebalance happens. Both
173
+
`minDiff` and `diffRatio` must be satisfied.
174
+
175
+
* `minSlabs`
176
+
The minimum number of slabs to retain in every allocation class. An
177
+
allocation class with `minSlabs` or fewer slabs cannot be picked as the
178
+
victim.
179
+
180
+
* `numSlabsFreeMem` and `enableVictimByFreeMem`
181
+
When enabled, prioritize allocation classes with more than
182
+
`numSlabsFreeMem` slab equivalents of free memory as victims.
183
+
108
184
* `minLruTailAge`
109
-
When using hit based rebalancing, if you want to ensure some level of fairness by guaranteeing some eviction age, you can configure it through this parameter.
185
+
Require a victim to have at least this eviction age, and prioritize receivers
186
+
below this eviction age. Use this to preserve some eviction-age fairness
187
+
while optimizing hits.
188
+
189
+
* `maxLruTailAge`
190
+
Prefer victims above this eviction age and receivers below this eviction age.
191
+
If no receiver satisfies the limit, the strategy falls back to the hits-based
192
+
choice.
193
+
194
+
* `updateHitsOnEveryAttempt`
195
+
Update the hit-count baseline on every rebalance attempt, even if no slab is
196
+
moved. By default, the baseline is updated after successful rebalances.
197
+
198
+
* `getWeight`
199
+
An optional weight function to bias hit-per-slab values. Higher weights make
200
+
an allocation class more likely to receive slabs and less likely to donate.
201
+
202
+
* `classIdTargetEvictionAge`
203
+
Optional per-class target eviction ages. Victims must meet their target, and
204
+
receivers below target are prioritized.
110
205
111
206
#### Marginal hits
112
207
113
208
This strategy ensures that the marginal hits (estimated by the hits in the tail part of LRU) across different object sizes are similar. Unlike hit based strategy which counts for historical count of hits across the entire cache, this tracks which objects could marginally benefit from getting more memory. To enable this, you need to use the MM2Q eviction policy and enable tail hits tracking (`Allocator::Config::enableTailHitsTracking()`).
114
209
210
+
You can configure the following parameters in `MarginalHitsStrategy::Config`:
211
+
212
+
* `movingAverageParam`
213
+
The smoothing parameter used for marginal-hit rankings.
214
+
215
+
* `minSlabs`
216
+
The minimum number of slabs to retain in every allocation class. An
217
+
allocation class with `minSlabs` or fewer slabs cannot be picked as the
218
+
victim.
219
+
220
+
* `maxFreeMemSlabs`
221
+
An allocation class can be picked as the receiver only when its free memory
222
+
is below this many slab equivalents.
223
+
115
224
#### Free memory
116
225
117
226
This strategy frees a slab from an allocation class that satisfies all of the following requirements:
118
227
- this allocation class has total slabs above `minSlabs`
119
-
- this allocation class has free slabs above `numFreeSlabs`
228
+
- this allocation class has more than `numFreeSlabs` slab equivalents of total free memory
120
229
- this allocation class has the most total free memory among all non-evicting (i.e. no eviction is currently happening) allocation classes in the pool
121
230
122
231
Note: this strategy does not specify a target allocation class to receive the freed slab.
123
-
Here are the parameters to configure this strategy:
232
+
You can configure the following parameters in `FreeMemStrategy::Config`:
124
233
* `minSlabs`
125
234
The minimum number of slabs to retain in every allocation class. Default is 1.
126
235
* `numFreeSlabs`
127
-
The threshold of required free slabs. Default is 3.
236
+
The free-memory threshold, in slab equivalents. Default is 3.
128
237
* `maxUnAllocatedSlabs`
129
238
FreeMem strategy will not rebalance anything if the number of free slabs in this pool is more than this number. Default is 1000.
130
239
@@ -136,14 +245,16 @@ In addition, if you have some application specific context on how you can improv
0 commit comments