It is able to help users tune their current block cache size, and determine how efficient they are using the memory. Also, it helps understand the cache performance with fast storage.

The basic idea of SimCache is to wrap the normal block cache with a key-only block cache configured with targeted simulation capacity. When insertion happens, we insert the key to both caches, but value is only inserted into normal cache. The size of the value is contributed to the capacities of both caches so that we simulate the behavior of a block cache with simulation capacity without using that much memory because in fact, the real memory usage only includes the total size of keys.

Then wrap the normal_block_cache with NewSimCache and set the SimCache as the block_cache field of and then generate the options.table_factory:

  1. rocksdb::BlockBasedTableOptions bbt_opts;
  2. NewSimCache(normal_block_cache,
  3. bbt_opts.block_cache = sim_cache;

Finally, open the DB with options. Then the HIT/MISS value of SimCache can be acquired by calling sim_cache->get_hit_counter() and sim_cache->get_miss_counter(), respectively. Alternatively, if you don’t want to store sim_cache and using Rocksdb (>= v4.12), you can get these statistics through Tickers SIM_BLOCK_CACHE_HIT and SIM_BLOCK_CACHE_MISS in .

sim_capacity * entry_size / (entry_size + block_size),

  • 76 <= entry_size (key_size + other) <= 104,

Therefore, by default the actual memory overhead of SimCache is around sim_capacity * 2%.