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 · DOI

Introduction

In the landscape of modern cloud databases, "hotspots"—frequently accessed data items such as viral product inventory or popular digital wallets—represent a significant performance bottleneck. Traditional databases primarily rely on Two-Phase Locking (2PL) to maintain transaction isolation. However, under high-contention scenarios, 2PL often leads to long wait queues, resulting in substantial overhead from lock acquisition, frequent context switching, and computationally expensive deadlock detection.

While academic protocols like Aria or Bamboo attempt to mitigate these issues through early lock release or deterministic scheduling, they typically require developers to rewrite SQL queries or provide read-write sets in advance. Such requirements are impractical for complex, real-world industrial applications. TXSQL, Tencent’s optimized MySQL branch, addresses these challenges with a workload-agnostic solution designed to handle the extreme traffic spikes characteristic of services like WeChat Pay.

The TXSQL Architecture

TXSQL introduces several layers of optimization within its storage engine, which follows an InnoDB-like architecture. These optimizations are designed to reduce the internal friction of the database engine before applying more specialized contention-handling logic.

Key general optimizations include:

  • Lightweight Locking: The system replaces heavy global mutexes with a lock-free hash map to manage waiting transactions, significantly lowering the cost of conflict tracking.
  • Copy-Free Active Transaction List: By leveraging Multi-Version Concurrency Control (MVCC) snapshots, TXSQL can check transaction visibility without the performance penalty of locking the global transaction list.

Hotspot-Aware Group Locking

The core innovation of TXSQL is its Group Locking mechanism. When the system detects that a specific row has become a hotspot (based on the length of its wait queue), it dynamically switches from standard 2PL to Group Locking mode.

In this mode, concurrently arriving transactions for a hotspot are organized into a group. The first transaction is designated as the Leader and acquires the actual row lock. Subsequent transactions become Followers. These followers execute their updates serially within the group in an uncommitted state. Because they follow a strict, pre-determined order, they do not need to acquire individual locks, effectively eliminating the "wake-up and re-lock" cycle that degrades performance in standard 2PL. To maintain consistency, TXSQL ensures that the commit phase (Flush, Sync, Commit) also follows this group sequence.

Performance Evaluation

The researchers evaluated TXSQL using industry-standard benchmarks including SysBench and TPC-C, as well as Tencent's internal FiT (Financial Transaction) benchmark. The results demonstrate that in extreme hotspot scenarios, serializing work while parallelizing the wait is more efficient than managing parallel access overhead.

Performance analysis showing TPS across varying thread counts and transaction lengths.

Key Results:

  • Throughput Gains: In the FiT workload, TXSQL achieved up to 8.25x higher throughput than standard MySQL. In high-latency synchronous replication scenarios, this improvement reached 22.3x.
  • Scalability: As illustrated in the performance charts, while standard MySQL performance collapses as thread counts reach 1024, TXSQL maintains high and stable throughput.
  • Real-World Impact: Tencent has deployed TXSQL across more than 20,000 database instances. This has resulted in a 30% general performance boost and a 10x improvement in handling sudden hotspot spikes during major events.

Conclusion and Future Work

TXSQL successfully mitigates high-contention bottlenecks without requiring changes to application-level SQL. While the current implementation is highly optimized for single-row hotspots, future work will focus on transactions involving multiple hotspots and further optimizing the Two-Phase Commit (2PC) mechanism to reduce the impact of network latency in distributed environments. Currently, the system provides a robust solution for the short, high-concurrency transactions typical of modern financial and social platforms.

Summary updated

BibTeX
@inproceedings{wang2025txsql,
  author = {Donghui Wang and Yuxing Chen and Chengyao Jiang and Anqun Pan and Wei Jiang and Songli Wang and Hailin Lei and Chong Zhu and Lixiong Zheng and Wei Lu and Yunpeng Chai and Feng Zhang and Xiaoyong Du},
  title = {{TXSQL: Lock Optimizations Towards High Contented Workloads (Extended Version)}},
  booktitle = {SIGMOD Conference Companion},
  year = {2025},
  doi = {10.1145/3722212.3724457},
}
Figure