Learning to Optimize LSM-trees: Towards A Reinforcement Learning based Key-Value Store for Dynamic Workloads

Dingheng Mo, Fanchao Chen, Siqiang Luo, Caihua Shan · DOI

Abstract

Log-Structured Merge-trees (LSM-trees) are the foundational storage architecture for modern key-value stores like RocksDB and LevelDB. However, their performance is highly sensitive to compaction policies, which traditionally require manual tuning and struggle to adapt to dynamic workloads. This paper introduces RusKey, a self-tuning key-value store that leverages Reinforcement Learning (RL) to optimize compaction policies on the fly. By combining a novel Flexible LSM-tree (FLSM-tree) structure with a Level-based RL approach (LERP), RusKey achieves up to 4x better throughput than RocksDB under shifting workloads while maintaining negligible operational overhead.

Introduction

The performance of LSM-trees is governed by a fundamental trade-off between read and write efficiency, dictated by compaction policies. "Leveling" policies prioritize read performance by aggressively merging data, while "Tiering" policies favor write speed by allowing multiple sorted runs per level. In real-world applications, workloads are rarely static; they fluctuate between read-heavy and write-heavy phases.

Existing solutions face two primary hurdles: the inability of static mathematical models to capture complex system behaviors (such as CPU overhead from Bloom filters) and the "transition bottleneck," where changing a compaction policy requires expensive, high-latency data reorganization. RusKey addresses these challenges by treating the LSM-tree as a dynamic system capable of "morphing" its structure in response to RL-driven insights.

System Design

FLSM-tree: Enabling Zero-Delay Transitions

Traditional LSM-trees enforce a uniform number of runs per level, making policy changes disruptive. RusKey introduces the Flexible LSM-tree (FLSM-tree), which allows runs of varying sizes to coexist within the same level. When the RL agent dictates a policy shift, the system simply "seals" the current active run and initiates a new one according to the updated parameters. This design enables zero-delay transitions, avoiding the massive I/O spikes typically associated with reconfiguring a database's storage structure.

LERP: Level-based RL with Policy Propagation

Optimizing an entire LSM-tree presents a massive action space that is difficult for standard RL algorithms to navigate. RusKey employs LERP (Level-based RL with Policy Propagation) to simplify this problem:

  1. Independent Agents: The system trains independent RL agents using the Deep Deterministic Policy Gradient (DDPG) algorithm for the top levels of the tree, where data turns over quickly and feedback is frequent.
  2. Policy Propagation: Because the massive bottom levels of a database fill slowly, gathering enough data for RL convergence is impractical. RusKey utilizes a mathematical "Policy Propagation" formula to extend the optimal settings learned at the top levels to the bottom levels, ensuring the entire tree remains optimized even when data is sparse.

Experimental Evaluation

Methodology

RusKey was evaluated against standard RocksDB configurations (Aggressive, Moderate, and Lazy) and the state-of-the-art "Lazy-Leveling" (Dostoevsky) approach. The benchmarks included:

  • Synthetic Workloads: Controlled mixes of lookups and updates.
  • Dynamic Workloads: Sequences of five distinct sessions with shifting read/write ratios to test adaptation speed.
  • YCSB (Yahoo! Cloud Serving Benchmark): Industry-standard simulations of real-world access patterns.

Key Results

  • Throughput Gains: RusKey demonstrated up to 4x better end-to-end performance than RocksDB in dynamic environments.
  • Adaptability: While static policies performed well in specific scenarios but poorly in others, RusKey maintained a consistent top-tier ranking (average rank of 1.2) across all tested workload sessions.
  • Efficiency: The RL model's training and update process proved highly efficient, consuming less than 1% of total processing time. The system typically converged on an optimal policy within 300 to 600 workload "missions."

Discussion and Future Work

RusKey demonstrates that a "black-box" RL approach can outperform "white-box" mathematical models by accounting for hidden system costs, such as the CPU cycles required for Bloom filter hashing on modern NVMe drives. By bridging the gap between RL and storage theory through policy propagation, RusKey solves the data sparsity problem that often hinders machine learning in systems research.

Future iterations of RusKey may explore tuning additional "knobs," such as the size ratio between levels and memory allocation for Bloom filters. Additionally, refining the policy propagation formula to better handle "non-zero-result" lookups (where keys are frequently found) could further enhance performance in hit-heavy workloads.

Conclusion

RusKey represents a significant step toward truly autonomous storage systems. By rethinking the underlying LSM-tree structure to support flexibility and employing a hybrid RL-theoretical tuning strategy, it provides a robust solution for the unpredictable demands of modern data-driven applications.

Summary updated

BibTeX
@article{mo2023learning,
  author = {Dingheng Mo and Fanchao Chen and Siqiang Luo and Caihua Shan},
  title = {{Learning to Optimize LSM-trees: Towards A Reinforcement Learning based Key-Value Store for Dynamic Workloads}},
  journal = {Proc. ACM Manag. Data},
  year = {2023},
  doi = {10.1145/3617333},
}
Figure