Configs2026年5月21日·1 分钟阅读

Sled — Modern Embedded Database for Rust

A lightweight, lock-free embedded key-value store written in Rust, inspired by modern B-tree research.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Sled Overview
通用 CLI 安装命令
npx tokrepo install 6678c522-5551-11f1-9bc6-00163e2b0d79

Introduction

Sled is an embedded database written in Rust that provides a concurrent, ACID-compliant key-value store. It was designed from the ground up to leverage modern hardware with lock-free data structures, making it suitable for applications that need high-throughput embedded storage without an external database process.

What Sled Does

  • Provides a zero-config embedded key-value store with ACID transactions
  • Supports ordered iteration, range scans, and prefix scanning
  • Offers merge operators for conflict-free concurrent value updates
  • Delivers crash-safe storage through write-ahead logging
  • Enables structured data through typed trees and namespaced keyspaces

Architecture Overview

Sled uses a lock-free B+ tree variant called a Bw-tree for its core index structure. Writes go through a write-ahead log for durability, and background compaction reclaims space. The page cache uses epoch-based reclamation to avoid locks, and the storage engine is designed around flash-friendly I/O patterns to minimize write amplification.

Self-Hosting & Configuration

  • Add sled as a Cargo dependency; no external process or server needed
  • Configure cache size, flush interval, and compression via the sled::Config builder
  • Use temporary mode for testing to avoid writing to disk
  • Set segment size and snapshot thresholds for write-heavy workloads
  • Monitor database statistics through the built-in sled::Db::size_on_disk method

Key Features

  • Lock-free concurrent reads and writes using modern B-tree research
  • Built-in ACID transactions with serializable isolation
  • Zero external dependencies beyond the Rust standard library
  • Merge operators for conflict-free counters and append-only logs
  • Subscribes to key-change events for reactive application patterns

Comparison with Similar Tools

  • RocksDB — RocksDB is C++ with Rust bindings; sled is pure Rust with a simpler API
  • SQLite — SQLite provides relational SQL; sled is a key-value store for structured Rust data
  • LevelDB — LevelDB is read-optimized; sled targets balanced read/write workloads with concurrency
  • redb — redb is a newer Rust embedded DB focused on simplicity; sled offers more features like subscribers
  • LMDB — LMDB uses memory-mapped files; sled uses a log-structured approach with compaction

FAQ

Q: Is sled production-ready? A: Sled is widely used but still pre-1.0. The API is stable for the 0.34 line, and the author is working on a 1.0 rewrite with improved performance.

Q: Does sled support multi-process access? A: No. Sled is designed for single-process, multi-threaded use. Use a client-server database if you need multi-process access.

Q: How does sled handle crash recovery? A: Sled uses write-ahead logging and periodic snapshots to recover to a consistent state after unexpected shutdowns.

Q: Can sled be used in WebAssembly? A: Not directly, since sled depends on filesystem I/O. It is designed for native Rust applications.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产