Abstract
Reinforcement Learning (RL) training is often bottlenecked by data handling in the Replay Buffer, particularly when scaling to multi-core CPU architectures. This paper introduces a high-performance framework that optimizes the Prioritized Replay Buffer through a $K$-ary sum tree data structure and a "lazy writing" synchronization mechanism. By improving memory access patterns and reducing locking overhead, the proposed framework achieves buffer operation speedups of up to 100x. When integrated into standard RL libraries, these optimizations translate to a 1.19x to 1.75x improvement in overall training time across various benchmarks.
Introduction
The computational demands of Reinforcement Learning have led to the widespread adoption of parallel architectures. In these systems, multiple "actor" threads interact with environments to collect experience, while "learner" threads update the neural network policy. Central to this interaction is the Replay Buffer, which stores and samples past experiences. However, as the number of parallel threads increases, the Replay Buffer—especially the Prioritized Replay Buffer (PRB)—becomes a significant performance bottleneck due to synchronization overheads and inefficient memory access.
System Architecture
The framework addresses the interaction between actors, learners, and the dataset. Actors generate experience by taking actions in the world, which are then stored in the dataset. Learners sample from this dataset to update the policy, which is then propagated back to the actuators.
Beyond the basic loop, the framework includes an automated profiling tool that determines the optimal ratio of actor threads to learner threads for the specific hardware in use, ensuring efficient resource utilization.
Optimizing the Prioritized Replay Buffer
The core innovation of this work lies in rethinking the sum tree data structure used for prioritized sampling. While traditional implementations use binary trees, this framework utilizes a $K$-ary sum tree.
By increasing the fanout $K$ (e.g., to 4, 8, or 16), the height of the tree is significantly reduced. This reduction leads to fewer memory lookups during sampling and updates. Furthermore, the framework employs a cache-aligned data layout, mapping the tree nodes to a flat array to ensure that siblings are fetched into the CPU cache simultaneously, minimizing expensive RAM access.
Synchronization and Scalability
To further eliminate bottlenecks, the authors introduce a "lazy writing" synchronization mechanism. Traditional global locks force threads to wait during buffer writes. The proposed approach instead uses atomic operations to temporarily zero out a data point's priority during updates, allowing writes to occur without a global lock. While this can lead to transient inconsistencies, the stochastic nature of RL training makes it robust to such minor errors in exchange for massive throughput gains.
Evaluation and Results
The framework was evaluated on OpenAI Gym benchmarks, including Mujoco and Atari games, using algorithms like DQN and SAC. Results show that the $K$-ary sum tree improves sampling performance by 4x to 100x compared to baseline implementations. Overall training times improved by 1.19x to 1.75x when integrated with RLlib and Tianshou, demonstrating near-linear scaling with additional CPU cores.
Conclusion
By focusing on hardware-aware data structures and relaxed synchronization, this framework provides a scalable solution for high-performance RL. Future work includes extending these techniques to distributed systems and exploring hardware accelerators like FPGAs for buffer management.
Summary updated