TXSQL: Lock Optimizations Towards High Contented Workloads (Extended Version)
Donghui Wang, Yuxing Chen, Chengyao Jiang, Anqun Pan, Wei Jiang, Songli Wang, Hailin Lei, Chong Zhu, Lixiong Zheng, Wei Lu, Yunpeng Chai, Feng Zhang, Xiaoyong Du
TL;DR
TXSQL tackles lock contention in high-contention OLTP workloads by augmenting the standard two-phase locking (2PL) approach with hotspot-aware group locking. It combines general lock optimizations (lightweight locking, a copy-free MVCC view, and reduced lock overhead) with hotspot-specific mechanisms (automatic hotspot detection, queue locking, and serial group execution of hotspot updates) to maintain serializability while boosting concurrency. The system guarantees correct commit and rollback ordering through a dependency list and introduces latency-aware batching, selective update coordination, and replication-replay safeguards. Evaluations on Tencent-scale workloads and real deployments show up to 6.5x improvements over state-of-the-art lock-based methods and up to 22.3x against competing systems, with substantial gains in hotspot-heavy and real-world scenarios. The results demonstrate practical viability for industry-scale high-contention OLTP, enabling higher throughput with controlled latency and improved reliability during sudden load spikes.
Abstract
Two-phase locking (2PL) is a fundamental and widely used concurrency control protocol. It regulates concurrent access to database data by following a specific sequence of acquiring and releasing locks during transaction execution, thereby ensuring transaction isolation. However, in strict 2PL, transactions must wait for conflicting transactions to commit and release their locks, which reduces concurrency and system throughput. We have observed this issue is exacerbated in high-contented workloads at Tencent, where lock contention can severely degrade system performance. While existing optimizations demonstrate some effectiveness in high-contention scenarios, their performance remains insufficient, as they suffer from lock contention and waiting in hotspot access. This paper presents optimizations in lock management implemented in Tencent's database, TXSQL, with a particular focus on high-contention scenarios. First, we discuss our motivations and the journey toward general lock optimization, which includes lightweight lock management, a copy-free active transaction list, and queue locking mechanisms that effectively enhance concurrency. Second, we introduce a hotspot-aware approach that enables certain highly conflicting transactions to switch to a group locking method, which groups conflicting transactions at a specific hotspot, allowing them to execute serially in an uncommitted state within a conflict group without the need for locking, thereby reducing lock contention. Our evaluation shows that under high-contented workloads, TXSQL achieves performance improvements of up to 6.5x and up to 22.3x compared to state-of-the-art methods and systems, respectively.
