pub struct HyperClockCacheOptions { /* private fields */ }Expand description
Configuration for a HyperClockCache, RocksDB’s block cache of choice.
HCC is lock free, so it holds up far better than LRU under parallel load and contention, and it needs sharding only for a modest gain, so its shards can be much larger and are much less prone to thrashing. Upstream recommends it over LRU for the block cache.
The caveats, from rocksdb/include/rocksdb/cache.h:
- It only works as
BlockBasedOptions::set_block_cache. It is not a general cache, so it is not usable as a row cache. - Cache priorities are enforced less aggressively, so a long range scan can
dilute the cache unless it reads with
fill_cacheoff. - Some configurations need anonymous mmap support.
- The bounded counting-CLOCK eviction gives a hit rate slightly different from LRU’s, in either direction.
Build a cache from these with Cache::new_hyper_clock_cache_opts.
Implementations§
Source§impl HyperClockCacheOptions
impl HyperClockCacheOptions
Sourcepub fn new(capacity: size_t, estimated_entry_charge: size_t) -> Self
pub fn new(capacity: size_t, estimated_entry_charge: size_t) -> Self
Creates options for a HyperClockCache of capacity bytes.
There is no Default, because a cache with no capacity is not a useful
starting point. See Self::set_estimated_entry_charge for what to
pass as estimated_entry_charge, and pass 0 if unsure.
Sourcepub fn set_capacity(&mut self, capacity: size_t)
pub fn set_capacity(&mut self, capacity: size_t)
Capacity of the cache, in the same units as the charge of each entry,
which is bytes unless entries are charged some other way.
Sourcepub fn set_estimated_entry_charge(&mut self, estimated_entry_charge: size_t)
pub fn set_estimated_entry_charge(&mut self, estimated_entry_charge: size_t)
The estimated average charge of a cache entry, which selects the HCC
variant.
0, the recommended value, picks the variant with a dynamically growing table and generally good performance. That variant depends on anonymous mmap, so it is not available everywhere.
A non-zero value picks the most efficient variant, but only pays off if
the estimate is close. A bad estimate degrades performance. Estimating
is hard or impossible with cache-charging features such as
WriteBufferManager in play. For a cache already running, roughly
cache.get_usage() / cache.get_occupancy_count() is the right number,
and when the ratio moves around it is better to guess low than high.
Sourcepub fn set_num_shard_bits(&mut self, num_shard_bits: c_int)
pub fn set_num_shard_bits(&mut self, num_shard_bits: c_int)
Cache is sharded into 2^num_shard_bits shards, by hash of key.
If < 0, a good default is chosen based on the capacity and the
implementation.
HCC uses sharding only for a modest performance boost, so it does not need as many shards as LRU does to scale.
Sourcepub fn set_memory_allocator(&mut self, allocator: &MemoryAllocator)
pub fn set_memory_allocator(&mut self, allocator: &MemoryAllocator)
Allocates cache block memory through allocator instead of the system
allocator.
These options do not borrow the allocator. The C setter copies the
shared_ptr<MemoryAllocator> out of the handle
(opts->rep.memory_allocator = memory_allocator->rep in db/c.cc), so
the allocator stays alive through the options and the caches built from
them even after the MemoryAllocator here is dropped.