K/V数据库 LevelDB
<p>Leveldb是一个google实现的非常高效的kv数据库,目前的版本1.2能够支持billion级别的数据量了。 在这个数量级别下还有着非常高的性能,主要归功于它的良好的设计。特别是LSM算法。</p> <h3>关键特性<br /> </h3> <ul> <li>Keys and values are arbitrary byte arrays. </li> <li>Data is stored sorted by key. </li> <li>Callers can provide a custom comparison function to override the sort order. </li> <li>The basic operations are <tt>Put(key,value)</tt>, <tt>Get(key)</tt>, <tt>Delete(key)</tt>. </li> <li>Multiple changes can be made in one atomic batch. </li> <li>Users can create a transient snapshot to get a consistent view of data. </li> <li>Forward and backward iteration is supported over the data. </li> <li>Data is automatically compressed using the <a href="/misc/goto?guid=4959223617307691158" rel="nofollow">Snappy compression library</a>. </li> <li>External activity (file system operations etc.) is relayed through a virtual interface so users can customize the operating system interactions. </li> <li><a href="/misc/goto?guid=4959223617401491869" rel="nofollow">Detailed documentation</a> about how to use the library is included with the source code. </li> </ul> <p></p> <p>LevelDB 是单进程的服务,性能非常之高,在一台4个Q6600的CPU机器上,每秒钟写数据超过40w,而随机读的性能每秒钟超过10w。</p> <p>示例代码:</p> <pre class="brush:cpp; toolbar: true; auto-links: false;">#include #include "leveldb/include/db.h" leveldb::DB* db; leveldb::Options options; options.create_if_missing = true; leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db); assert(status.ok()); std::string value; leveldb::Status s = db->Get(leveldb::ReadOptions(), key1, &value); if (s.ok()) s = db->Put(leveldb::WriteOptions(), key2, value); if (s.ok()) s = db->Delete(leveldb::WriteOptions(), key1);</pre> <p></p> <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1322708170155" target="_blank">http://www.open-open.com/lib/view/home/1322708170155</a></p>
本文由用户 openkk 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!