leveldb-rs-binding
Rust interface for Google's LevelDB key-value storage library.
Documentation: https://docs.rs/leveldb-rs-binding/latest/leveldb/.
Refer to the CHANGELOG.md for release notes.
Rust version policy
The leveldb-rs-binding is built and tested with stable releases of Rust toolchain.
Check CI for tested version.
Dependencies
- LevelDB:
mainbranch, commit id: ac69108 - Snappy: v1.2.2
Usage
If your project is using Cargo, drop the following lines in your Cargo.toml:
[dependencies]
leveldb-rs-binding = "2.0"
Development
Make sure you have all prerequisites installed, including cmake, git and a C++ compiler, like g++ or clang++, that supports C++17.
Clone the repository, and run
for building and
to run the test suite.
Examples
Check out the example directory.
Benchmark
For reference, here is a comparison of the results from the LevelDB C++ db_bench and the Rust db_bench_rs benchmarks, each located in the benchmarks folder of their respective repositories.
Test Environment:
| name | environment |
|---|---|
| CPU | 16 × AMD Ryzen 7 5800X 8-Core Processor |
| CPUCache | 512 KB |
| Keys | 16 bytes each |
| Values | 100 bytes each (50.0 bytes after compression) |
| Entries | 1000000 |
| RawSize | 110.6 MB (estimated) |
| FileSize | 55.3 MB (estimated) |
| Compression | Snappy |
Commands executed:
- C++ version:
./db_bench --threads=1 - Rust version:
./target/release/db_bench_rs --threads=1
| Test | C++ Latency (micros/op) | Rust Latency (micros/op) | Latency Diff (%) | C++ Throughput (MB/s) | Rust Throughput (MB/s) | Throughput Diff (%) |
|---|---|---|---|---|---|---|
| fillseq | 1.053 | 1.154 | +9.59% | 105.1 | 95.9 | -8.75% |
| fillsync | 2.665 | 2.398 | -10.02% | 41.5 | 46.1 | +11.08% |
| fillrandom | 1.220 | 1.312 | +7.54% | 90.7 | 84.3 | -7.06% |
| overwrite | 1.429 | 1.402 | -1.89% | 77.4 | 78.9 | +1.94% |
| readrandom | 2.612 | 2.186 | -16.31% | N/A | N/A | N/A |
| readrandom | 2.371 | 2.083 | -12.15% | N/A | N/A | N/A |
| readseq | 0.100 | 0.099 | -1.00% | 1107.2 | 1117.8 | +0.96% |
| readreverse | 0.184 | 0.168 | -8.70% | 602.3 | 659.4 | +9.48% |
| compact | 247713.000 | 350.000 | -99.86% | N/A | N/A | N/A |
| readrandom | 1.988 | 2.065 | +3.87% | N/A | N/A | N/A |
| readseq | 0.090 | 0.098 | +8.89% | 1225.1 | 1125.7 | -8.11% |
| readreverse | 0.161 | 0.170 | +5.59% | 687.9 | 652.2 | -5.19% |
| fill100K | 259.673 | 230.063 | -11.40% | 367.3 | 424.5 | +15.57% |
Notes:
- Latency Diff (%): Positive values indicate Rust is slower, negative values indicate Rust is faster.
- Throughput Diff (%): Positive values indicate Rust is faster, negative values indicate Rust is slower.
- For
N/A: Throughput data not available for related cases. - Compact Performance: The dramatic difference in the
compactcase (C++: 247713μs vs Rust: 350μs) is explained by LevelDB's internal background compaction mechanism. Whenreadrandomoperations are executed beforecompact, the database instance triggers background compaction that significantly reduces the time required by the subsequentcompactoperation. - Read Performance: The reason above also explains why
readrandom/readseq/readreverseperformance beforecompactcases are almost the same as cases aftercompact. - Tests Order Impact: Benchmark results are highly sensitive to tests execution order. Different sequences of operations can lead to completely different performance measurements, especially for compaction operations.
- Fair Comparison: For accurate performance comparison, it's more important to run benchmarks for your specific use case scenarios.
License
MIT, see LICENSE