LevelDB Cache
【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的更多相关文章
- LevelDB Cache机制
[LevelDB Cache机制] 对于levelDb来说,读取操作如果没有在内存的memtable中找到记录,要多次进行磁盘访问操作.假设最优情况,即第一次就在level 0中最新的文件中找到了这个 ...
- LevelDB Cache实现机制分析
几天前淘宝量子恒道在博客上分析了HBase的Cache机制,本篇文章,结合LevelDB 1.7.0版本的源码,分析下LevelDB的Cache机制. 概述 LevelDB是Google开源的持久化K ...
- LevelDB:一个快速轻量级的key-value存储库(译)
作者:Jeff Dean, Sanjay Ghemawat 原文:http://leveldb.googlecode.com/svn/trunk/doc/index.html 译者:phylips@b ...
- Derek解读Bytom源码-持久化存储LevelDB
作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...
- Leveldb 使用说明文档
Leveldb 使用说明文档 原作者:Jeff Dean, Sanjay Ghemawat 翻译:乌合之众solym@sohu.com 英文原文地址https://rawgit.com/google/ ...
- 【神经网络与深度学习】Leveldb的一些具体操作说明
本文转自 http://blog.csdn.net/poweruser5956/article/details/7727325 Leveldb概述 leveldb提供了持久的键值对的存储.key和va ...
- LevelDB源码分析--Cache及Get查找流程
本打算接下来分析version相关的概念,但是在准备的过程中看到了VersionSet的table_cache_这个变量才想起还有这样一个模块尚未分析,经过权衡觉得leveldb的version相对C ...
- leveldb 性能、使用场景评估
最近有个业务写远远大于读,读也集中在最近写入,这不很适合采用leveldb存储么,leveldb业界貌似ssdb用得挺广,花了两天时间就ssdb简单做下测试,以下总结. ssdb 是leveldb的r ...
- leveldb源码分析--SSTable之Compaction
对于compaction是leveldb中体量最大的一部分,也应该是最为复杂的部分,为了便于理解我们首先从一些基本的概念开始.下面是一些从doc/impl.html中翻译和整理的内容: Level 0 ...
随机推荐
- C++设计模式之职责链模式
代码实现: // chainResbonsibility.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stri ...
- java基础第8天
继承extends(也叫扩展) 多个类中存在相同的属性和行为时,将这些内容抽取到单独一个类中,那么多个类无需再定义这些属性和行为,只要继承那个类即可. 通过extends关键字可以实现类的继承 继承的 ...
- New Concept English Two 27 73
新概念一:对应小学水平,重在口语和基础.是不可多得的学习教材,全本144课,可以给孩子(hello world 级别的我)学半年.新概念二:对应高中水平,重在听力和场景对话,共96课,学后,听懂歪果仁 ...
- CS231n课程笔记翻译4:最优化笔记
译者注:本文智能单元首发,译自斯坦福CS231n课程笔记Optimization Note,课程教师Andrej Karpathy授权翻译.本篇教程由杜客翻译完成,堃堃和李艺颖进行校对修改.译文含公式 ...
- cool 软件 —— Carnac(实时桌面显示按键)
1. Carnac 下载地址:Carnac, the Magnificent Keyboard Utility 使用说明:carnac – 在屏幕实时显示按键操作
- C# 后台线程更新UI控件
/********************************************************************************* * C# 后台线程更新UI控件 * ...
- windows 不能在本地计算机启动SqlServer. 参考特定服务错误代码10048
这一般都是由于Sql Server的端口号被其他应用程序占用导致的,可以使用dos命令或者网络工具查看当前端口的使用情况,看看哪个程序占用了Sql Server的默认端口1433,将这个程序结束就可以 ...
- 在VS2008中使用WSE 3.0【转】
原文:http://www.cnblogs.com/chenxizhang/archive/2008/07/25/1251626.html 在VS2008中使用WSE 3.0 WSE 是微软推出的一套 ...
- CH3201 Hankson的趣味题
题意 3201 Hankson的趣味题 0x30「数学知识」例题 描述 Hanks博士是BT(Bio-Tech,生物技术)领域的知名专家,他的儿子名叫Hankson.现在,刚刚放学回家的Hankson ...
- 利用OCR文字识别+百度算法搜索,玩转冲顶大会、百万英雄、芝士超人等答题赢奖金游戏
[先上一张效果图]: 一.原理: 其实原理很简单: 1.手机投屏到电脑: 2.截取投屏画面的题目部分,进行识别,得到题目和三个答案: 3.将答案按照一定的算法,进行搜索,得出推荐答案: 4.添加了一些 ...