leveldb README

The project's README from github.com/google/leveldb. As one markdown file: README.md.

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.

This repository is receiving very limited maintenance. We will only review the following types of changes.

  • Fixes for critical bugs, such as data loss or memory corruption
  • Changes absolutely needed by internally supported leveldb clients. These typically fix breakage introduced by a language/standard library/OS update

ci

Authors: Sanjay Ghemawat ([email protected]) and Jeff Dean ([email protected])

Features

Documentation

LevelDB library documentation is online and bundled with the source code.

Limitations

Getting the Source

git clone --recurse-submodules https://github.com/google/leveldb.git

Building

This project supports CMake out of the box.

Build for POSIX

Quick start:

mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build .

Building for Windows

First generate the Visual Studio 2017 project/solution files:

mkdir build
cd build
cmake -G "Visual Studio 15" ..

The default default will build for x86. For 64-bit run:

cmake -G "Visual Studio 15 Win64" ..

To compile the Windows solution from the command-line:

devenv /build Debug leveldb.sln

or open leveldb.sln in Visual Studio and build from within.

Please see the CMake documentation and CMakeLists.txt for more advanced usage.

Contributing to the leveldb Project

This repository is receiving very limited maintenance. We will only review the following types of changes.

  • Bug fixes
  • Changes absolutely needed by internally supported leveldb clients. These typically fix breakage introduced by a language/standard library/OS update

The leveldb project welcomes contributions. leveldb's primary goal is to be a reliable and fast key/value store. Changes that are in line with the features/limitations outlined above, and meet the requirements below, will be considered.

Contribution requirements:

  1. Tested platforms only. We generally will only accept changes for platforms that are compiled and tested. This means POSIX (for Linux and macOS) or Windows. Very small changes will sometimes be accepted, but consider that more of an exception than the rule.

  2. Stable API. We strive very hard to maintain a stable API. Changes that require changes for projects using leveldb might be rejected without sufficient benefit to the project.

  3. Tests: All changes must be accompanied by a new (or changed) test, or a sufficient explanation as to why a new (or changed) test is not required.

  4. Consistent Style: This project conforms to the Google C++ Style Guide. To ensure your changes are properly formatted please run:

    clang-format -i --style=file <file>
    

We are unlikely to accept contributions to the build configuration files, such as CMakeLists.txt. We are focused on maintaining a build configuration that allows us to test that the project works in a few supported configurations inside Google. We are not currently interested in supporting other requirements, such as different operating systems, compilers, or build systems.

Submitting a Pull Request

Before any pull request will be accepted the author must first sign a Contributor License Agreement (CLA) at https://cla.developers.google.com/.

In order to keep the commit timeline linear squash your changes down to a single commit and rebase on google/leveldb/main. This keeps the commit timeline linear and more easily sync'ed with the internal repository at Google. More information at GitHub's About Git rebase page.

Performance

Here is a performance report (with explanations) from the run of the included db_bench program. The results are somewhat noisy, but should be enough to get a ballpark performance estimate.

Setup

We use a database with a million entries. Each entry has a 16 byte key, and a 100 byte value. Values used by the benchmark compress to about half their original size.

LevelDB:    version 1.1
Date:       Sun May  1 12:11:26 2011
CPU:        4 x Intel(R) Core(TM)2 Quad CPU    Q6600  @ 2.40GHz
CPUCache:   4096 KB
Keys:       16 bytes each
Values:     100 bytes each (50 bytes after compression)
Entries:    1000000
Raw Size:   110.6 MB (estimated)
File Size:  62.9 MB (estimated)

Write performance

The "fill" benchmarks create a brand new database, in either sequential, or random order. The "fillsync" benchmark flushes data from the operating system to the disk after every operation; the other write operations leave the data sitting in the operating system buffer cache for a while. The "overwrite" benchmark does random writes that update existing keys in the database.

fillseq      :       1.765 micros/op;   62.7 MB/s
fillsync     :     268.409 micros/op;    0.4 MB/s (10000 ops)
fillrandom   :       2.460 micros/op;   45.0 MB/s
overwrite    :       2.380 micros/op;   46.5 MB/s

Each "op" above corresponds to a write of a single key/value pair. I.e., a random write benchmark goes at approximately 400,000 writes per second.

Each "fillsync" operation costs much less (0.3 millisecond) than a disk seek (typically 10 milliseconds). We suspect that this is because the hard disk itself is buffering the update in its memory and responding before the data has been written to the platter. This may or may not be safe based on whether or not the hard disk has enough power to save its memory in the event of a power failure.

Read performance

We list the performance of reading sequentially in both the forward and reverse direction, and also the performance of a random lookup. Note that the database created by the benchmark is quite small. Therefore the report characterizes the performance of leveldb when the working set fits in memory. The cost of reading a piece of data that is not present in the operating system buffer cache will be dominated by the one or two disk seeks needed to fetch the data from disk. Write performance will be mostly unaffected by whether or not the working set fits in memory.

readrandom  : 16.677 micros/op;  (approximately 60,000 reads per second)
readseq     :  0.476 micros/op;  232.3 MB/s
readreverse :  0.724 micros/op;  152.9 MB/s

LevelDB compacts its underlying storage data in the background to improve read performance. The results listed above were done immediately after a lot of random writes. The results after compactions (which are usually triggered automatically) are better.

readrandom  : 11.602 micros/op;  (approximately 85,000 reads per second)
readseq     :  0.423 micros/op;  261.8 MB/s
readreverse :  0.663 micros/op;  166.9 MB/s

Some of the high cost of reads comes from repeated decompression of blocks read from disk. If we supply enough cache to the leveldb so it can hold the uncompressed blocks in memory, the read performance improves again:

readrandom  : 9.775 micros/op;  (approximately 100,000 reads per second before compaction)
readrandom  : 5.215 micros/op;  (approximately 190,000 reads per second after compaction)

Repository contents

See doc/index.md for more explanation. See doc/impl.md for a brief overview of the implementation.

The public interface is in include/leveldb/*.h. Callers should not include or rely on the details of any other header files in this package. Those internal APIs may be changed without warning.

Guide to header files:

leveldb (google/leveldb)

Searching Database…

39.5K ·GitHub
这是什么?LevelDB 是 Google 开发的一个高速键值存储库,提供从字符串键到字符串值的有序映射,支持 Put、Get、Delete 和范围遍历。
这是数据库服务器,还是我可以嵌入应用里的库?它是嵌入式库,不是独立的服务器:同一时间只有一个进程可以访问某个数据库,并且没有内置的客户端-服务器支持。
我要怎样构建并在项目中使用它?它开箱即支持 CMake:在 POSIX 系统上进行标准的 CMake 构建;在 Windows 上生成 Visual Studio 2017 项目/解决方案文件(默认 x86,也可选 64 位),然后通过命令行构建,或打开 leveldb.sln 进行构建。
要获得压缩功能,我还需要额外的库吗?数据会自动使用 Snappy 压缩库进行压缩,同时也支持将 Zstd 压缩作为可选项。
我能在它上面运行 SQL 查询或建立索引吗?不能——它明确不是 SQL 数据库:没有关系模型,不支持 SQL 查询,也不支持索引。
这个项目是在积极开发,还是只处于维护模式?它只获得非常有限的维护——仅审查关键的错误修复(数据丢失、内存损坏),以及内部支持的 leveldb 客户端所需的变更。
官方支持哪些平台来构建它?一般只接受经过编译和测试的平台:POSIX(Linux 和 macOS)或 Windows。
LevelDB 支持哪些主要的数据操作?Put、Get、Delete、原子性的多键批量写入、一致的时间点快照,以及对数据的前向和后向遍历。
我能控制键的排序方式吗?可以,调用方可以提供自定义比较函数来覆盖默认的按字节排序,例如用于自定义字符编码。
LevelDB 在实际中有多快?在一百万条 16 字节键 / 100 字节值的记录上进行基准测试,结果显示随机写入约每秒 40 万次,随机读取约每秒 6 万至 19 万次,具体取决于缓存和压缩状态。
我应该从哪里开始阅读代码?从 include/leveldb/db.h 开始了解主要的 DB 接口;其他关键头文件包括 options.h、comparator.h、iterator.h、writebatch.h、slice.h、status.h,以及用于操作系统抽象的 env.h。
What are similar projects?wcdb, badger, MMKV, bolt, KeyDB, phpredis, rocksdb, ducklake
Creator
google
Size
1.8 MB
Stars
39.5K
Age
12y
Commits · 90 Days