LevelDB Cache

  The contents of the database are stored in a set of files in the filesystem and each file stores a sequence of compressed blocks. If options.cache is non-NULL, it is used to cache frequently used uncompressed block contents.

  #include "leveldb/cache.h"

  leveldb::Options options;
options.cache = leveldb::NewLRUCache(100 * 1048576); // 100MB cache
leveldb::DB* db;
leveldb::DB::Open(options, name, &db);
... use the db ...
delete db
delete options.cache;

  Note that the cache holds uncompressed data, and therefore it should be sized according to application level data sizes, without any reduction from compression. (Caching of compressed blocks is left to the operating system buffer cache, or any custom Env implementation provided by the client.)

  When performing a bulk read, the application may wish to disable caching so that the data processed by the bulk read does not end up displacing most of the cached contents. A per-iterator option can be used to achieve this:

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

Key Layout

  Note that the unit of disk transfer and caching is a block. Adjacent keys (according to the database sort order) will usually be placed in the same block. Therefore the application can improve its performance by placing keys that are accessed together near each other and placing infrequently used keys in a separate region of the key space.

  把可能一起访问的key加上相同的前缀,以使他们能在同一block上,以提高性能。

  For example, suppose we are implementing a simple file system on top of leveldb. The types of entries we might wish to store are:

   filename -> permission-bits, length, list of file_block_ids
file_block_id -> data

  We might want to prefix filename keys with one letter (say '/') and the file_block_id keys with a different letter (say '0') so that scans over just the metadata do not force us to fetch and cache bulky file contents.

参考:http://htmlpreview.github.io/?https://github.com/google/leveldb/blob/master/doc/index.html

												

LevelDB Cache的更多相关文章

  1. LevelDB Cache机制

    [LevelDB Cache机制] 对于levelDb来说,读取操作如果没有在内存的memtable中找到记录,要多次进行磁盘访问操作.假设最优情况,即第一次就在level 0中最新的文件中找到了这个 ...

  2. LevelDB Cache实现机制分析

    几天前淘宝量子恒道在博客上分析了HBase的Cache机制,本篇文章,结合LevelDB 1.7.0版本的源码,分析下LevelDB的Cache机制. 概述 LevelDB是Google开源的持久化K ...

  3. LevelDB:一个快速轻量级的key-value存储库(译)

    作者:Jeff Dean, Sanjay Ghemawat 原文:http://leveldb.googlecode.com/svn/trunk/doc/index.html 译者:phylips@b ...

  4. Derek解读Bytom源码-持久化存储LevelDB

    作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...

  5. Leveldb 使用说明文档

    Leveldb 使用说明文档 原作者:Jeff Dean, Sanjay Ghemawat 翻译:乌合之众solym@sohu.com 英文原文地址https://rawgit.com/google/ ...

  6. 【神经网络与深度学习】Leveldb的一些具体操作说明

    本文转自 http://blog.csdn.net/poweruser5956/article/details/7727325 Leveldb概述 leveldb提供了持久的键值对的存储.key和va ...

  7. LevelDB源码分析--Cache及Get查找流程

    本打算接下来分析version相关的概念,但是在准备的过程中看到了VersionSet的table_cache_这个变量才想起还有这样一个模块尚未分析,经过权衡觉得leveldb的version相对C ...

  8. leveldb 性能、使用场景评估

    最近有个业务写远远大于读,读也集中在最近写入,这不很适合采用leveldb存储么,leveldb业界貌似ssdb用得挺广,花了两天时间就ssdb简单做下测试,以下总结. ssdb 是leveldb的r ...

  9. leveldb源码分析--SSTable之Compaction

    对于compaction是leveldb中体量最大的一部分,也应该是最为复杂的部分,为了便于理解我们首先从一些基本的概念开始.下面是一些从doc/impl.html中翻译和整理的内容: Level 0 ...

随机推荐

  1. 【LeetCode 38_字符串_算术运算】Count and Say

    string countAndSay(int n) { string res; ) return res; res = "; ) { int len = res.size(); int i, ...

  2. jQuery 参数详解

    url: 要求为String类型的参数,发送请求的地址.如果没有填写, 默认发送当前页的url type: 要求为String类型的参数,请求方式(post或get)默认为get. 注意其他http请 ...

  3. 《Unity 3D游戏客户端基础框架》多线程异步 Socket 框架构建

    引言: 之前写过一个 demo 案例大致讲解了 Socket 通信的过程,并和自建的服务器完成连接和简单的数据通信,详细的内容可以查看 Unity3D -- Socket通信(C#).但是在实际项目应 ...

  4. 利用 Create React Native App 快速创建 React Native 应用

    本文介绍的 Create-React-Native-App 是非常 Awesome 的工具,而其背后的 Expo 整个平台也让笔者感觉非常的不错.笔者目前公司是采用 APICloud 进行移动应用开发 ...

  5. windows下 两个版本的JDK环境变量进行切换 MARK

    我们平时在window上做开发的时候,可能需要同时开发两个甚至多个项目,有时不同的项目对JDK的版本要求有区别,为了简化操作,我们可以通过批处理文件来完成环境变量切换的任务.使用方法:阅读代码我们就会 ...

  6. 走在linux 的路上

    终于现在不看鸟哥的私房菜基础篇了,以后再慢慢看,像我这种初学者,感觉还是不太适合看鸟哥的私房菜. 于是从图书馆借了本书继续学习我的linux. 这样看着linux容易多了,进而熟悉了几个命令:ls c ...

  7. BZOJ3212: Pku3468 A Simple Problem with Integers(线段树)

    3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 2530  So ...

  8. docker默认配置文件不存在问题解决

    Docker默认的配置文件/etc/default/docker或者/etc/sysconfig/docker都不起作用,查看了一下/lib/systemd/system/docker.service ...

  9. ffmpeg V4L2_BUF_FLAG_ERROR的解决方法

    利用ffmpeg进行视频采集时经常出现“V4L2_BUF_FLAG_ERROR”的错误,并不再进行下帧的采集.通过借鉴下面的方法,对ffmpeg3.0.7版本进行补丁,能解决此类问题. 当某帧出错后, ...

  10. 一个单元测试 学习 aysnc await

    using System; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; name ...