K/V数据库 LevelDB

openkk 12年前
     <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>