Skip to content

Latest commit

 

History

History
25 lines (23 loc) · 1.16 KB

04.Block-Cache.md

File metadata and controls

25 lines (23 loc) · 1.16 KB

Cache设置

推荐对同一个进程的所有数据库的所有列族的table_options都使用同一个cache对象(传递同一个tables_options或者table_factory)。

  • Block Cache
    用于缓存常用的未压缩块内容(与此同时, 操作系统Page Cache也会缓存经过压缩的原始数据),用来缓存Block,可以加速读操作和Compaction速度

    rocksdb::BlockBasedTableOptions table_options;
    table_options.block_cache = rocksdb::NewLRUCache(/*capacity*/100 * 1048576,  
          /*num_shard_bits*/6, /*strict_capacity_limit*/false, /*high_pri_pool_ratio*/0.4,);
    
    rocksdb::Options options;
    options.table_factory.reset(rocksdb::NewBlockBasedTableFactory(table_options));
    
  • block_cache_size
    根据实际的内存容量来设,建议总的block cache空间占内存的1/4到1/3,调大该值对该CF的读性能有明显提升

  • 非Cache大批量读
    禁用缓存以便大容量读取(Scan场景)不会替换大部分缓存内容

    rocksdb::ReadOptions options;
    options.fill_cache = false;
    rocksdb::Iterator* it = db->NewIterator(options);
    for (it->SeekToFirst(); it->Valid(); it->Next()) {
        ...
    }