|
| 1 | +# Background Data Movement |
| 2 | + |
| 3 | +In order to reduce the number of online evictions and support asynchronous |
| 4 | +promotion - we have added two periodic workers to handle eviction and promotion. |
| 5 | + |
| 6 | +The diagram below shows a simplified version of how the background evictor |
| 7 | +thread (green) is integrated to the CacheLib architecture. |
| 8 | + |
| 9 | +<p align="center"> |
| 10 | + <img width="640" height="360" alt="BackgroundEvictor" src="cachelib-background-evictor.png"> |
| 11 | +</p> |
| 12 | + |
| 13 | +## Background Evictors |
| 14 | + |
| 15 | +The background evictors scan each class to see if there are objects to move the next (lower) |
| 16 | +tier using a given strategy. Here we document the parameters for the different |
| 17 | +strategies and general parameters. |
| 18 | + |
| 19 | +- `backgroundEvictorIntervalMilSec`: The interval that this thread runs for - by default |
| 20 | +the background evictor threads will wake up every 10 ms to scan the AllocationClasses. Also, |
| 21 | +the background evictor thread will be woken up everytime there is a failed allocation (from |
| 22 | +a request handling thread) and the current percentage of free memory for the |
| 23 | +AllocationClass is lower than `lowEvictionAcWatermark`. This may render the interval parameter |
| 24 | +not as important when there are many allocations occuring from request handling threads. |
| 25 | + |
| 26 | +- `evictorThreads`: The number of background evictors to run - each thread is a assigned |
| 27 | +a set of AllocationClasses to scan and evict objects from. Currently, each thread gets |
| 28 | +an equal number of classes to scan - but as object size distribution may be unequal - future |
| 29 | +versions will attempt to balance the classes among threads. The range is 1 to number of AllocationClasses. |
| 30 | +The default is 1. |
| 31 | + |
| 32 | +- `maxEvictionBatch`: The number of objects to remove in a given eviction call. The |
| 33 | +default is 40. Lower range is 10 and the upper range is 1000. Too low and we might not |
| 34 | +remove objects at a reasonable rate, too high and it might increase contention with user threads. |
| 35 | + |
| 36 | +- `minEvictionBatch`: Minimum number of items to evict at any time (if there are any |
| 37 | +candidates) |
| 38 | + |
| 39 | +- `maxEvictionPromotionHotness`: Maximum candidates to consider for eviction. This is similar to `maxEvictionBatch` |
| 40 | +but it specifies how many candidates will be taken into consideration, not the actual number of items to evict. |
| 41 | +This option can be used to configure duration of critical section on LRU lock. |
| 42 | + |
| 43 | + |
| 44 | +### FreeThresholdStrategy (default) |
| 45 | + |
| 46 | +- `lowEvictionAcWatermark`: Triggers background eviction thread to run |
| 47 | +when this percentage of the AllocationClass is free. |
| 48 | +The default is `2.0`, to avoid wasting capacity we don't set this above `10.0`. |
| 49 | + |
| 50 | +- `highEvictionAcWatermark`: Stop the evictions from an AllocationClass when this |
| 51 | +percentage of the AllocationClass is free. The default is `5.0`, to avoid wasting capacity we |
| 52 | +don't set this above `10`. |
| 53 | + |
| 54 | + |
| 55 | +## Background Promoters |
| 56 | + |
| 57 | +The background promoters scan each class to see if there are objects to move to a lower |
| 58 | +tier using a given strategy. Here we document the parameters for the different |
| 59 | +strategies and general parameters. |
| 60 | + |
| 61 | +- `backgroundPromoterIntervalMilSec`: The interval that this thread runs for - by default |
| 62 | +the background promoter threads will wake up every 10 ms to scan the AllocationClasses for |
| 63 | +objects to promote. |
| 64 | + |
| 65 | +- `promoterThreads`: The number of background promoters to run - each thread is a assigned |
| 66 | +a set of AllocationClasses to scan and promote objects from. Currently, each thread gets |
| 67 | +an equal number of classes to scan - but as object size distribution may be unequal - future |
| 68 | +versions will attempt to balance the classes among threads. The range is `1` to number of AllocationClasses. The default is `1`. |
| 69 | + |
| 70 | +- `maxProtmotionBatch`: The number of objects to promote in a given promotion call. The |
| 71 | +default is 40. Lower range is 10 and the upper range is 1000. Too low and we might not |
| 72 | +remove objects at a reasonable rate, too high and it might increase contention with user threads. |
| 73 | + |
| 74 | +- `minPromotionBatch`: Minimum number of items to promote at any time (if there are any |
| 75 | +candidates) |
| 76 | + |
| 77 | +- `numDuplicateElements`: This allows us to promote items that have existing handles (read-only) since |
| 78 | +we won't need to modify the data when a user is done with the data. Therefore, for a short time |
| 79 | +the data could reside in both tiers until it is evicted from its current tier. The default is to |
| 80 | +not allow this (0). Setting the value to 100 will enable duplicate elements in tiers. |
| 81 | + |
| 82 | +### Background Promotion Strategy (only one currently) |
| 83 | + |
| 84 | +- `promotionAcWatermark`: Promote items if there is at least this |
| 85 | +percent of free AllocationClasses. Promotion thread will attempt to move `maxPromotionBatch` number of objects |
| 86 | +to that tier. The objects are chosen from the head of the LRU. The default is `4.0`. |
| 87 | +This value should correlate with `lowEvictionAcWatermark`, `highEvictionAcWatermark`, `minAcAllocationWatermark`, `maxAcAllocationWatermark`. |
| 88 | +- `maxPromotionBatch`: The number of objects to promote in batch during BG promotion. Analogous to |
| 89 | +`maxEvictionBatch`. It's value should be lower to decrease contention on hot items. |
| 90 | + |
0 commit comments