Skip to main content

HyperClockCacheOptions

Struct HyperClockCacheOptions 

Source
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_cache off.
  • 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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Drop for HyperClockCacheOptions

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for HyperClockCacheOptions

Source§

impl Sync for HyperClockCacheOptions

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.