TXSQL: Lock Optimizations Towards High Contented Workloads

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

This paper introduces TXSQL, a database system that optimizes lock management for high-contention workloads, particularly those with "hotspots" (frequently accessed data). By introducing a novel "group locking" mechanism, TXSQL significantly reduces lock contention and improves performance, achieving up to 22.3x speedup compared to existing systems.

What Problem Does This Paper Address?

Online Transaction Processing (OLTP) systems often experience periods of intense activity, known as high-contention workloads. During these times, a small subset of data, termed "hotspots," can become a bottleneck as numerous transactions attempt to access and modify it simultaneously. Traditional concurrency control protocols, like Two-Phase Locking (2PL), struggle with these hotspots, leading to significant lock contention, transaction delays, and reduced system throughput. While existing optimizations offer some relief, they often fall short in truly dynamic hotspot scenarios. This paper addresses the challenge of efficiently managing these high-contention workloads, especially those with hotspots, to maintain high performance and system stability.

Methods

The core innovation presented is Group Locking, a novel approach to concurrency control for hotspot data within the 2PL framework. Unlike traditional 2PL where each transaction acquires and releases locks individually, group locking logically groups transactions that contend for the same hotspot.

Here's a breakdown of the key techniques:

  • Hotspot Detection: TXSQL identifies hotspots by monitoring the number of waiting transactions for a specific data row. If this number exceeds a predefined threshold, the row is flagged as a hotspot.
  • Group Locking Mechanism:
    • Leader/Follower Roles: Within a hotspot group, one transaction acts as the "leader," responsible for acquiring and releasing the lock for the hotspot. Other transactions become "followers" and execute serially without acquiring individual locks.
  • Serial Execution within Group: Followers execute their updates to the hotspot serially, one after another, without needing to wait for locks to be released by other transactions within the same group.
  • Commit Order Guarantee: A dependency list is maintained to ensure that transactions commit in the order they updated the hotspot, preventing anomalies.
  • Rollback Order Guarantee: Similarly, rollbacks are performed in the reverse order of updates to maintain consistency.
  • Lightweight Locking: TXSQL employs a lightweight lock management system, including a copy-free active transaction list and a queue lock mechanism, to reduce overhead in general high-contention scenarios.
  • Dynamic Batch Size: To address latency issues in fixed TPS environments, TXSQL dynamically adjusts batch sizes for group locking, releasing locks early if no new transactions are waiting.
  • Deadlock Handling: For non-hotspot rows, a timeout mechanism is used. For scenarios involving both hotspot and non-hotspot rows, a proactive rollback strategy is employed when a blocking situation is detected and both transactions have updated the same hotspot.

Datasets

The paper does not introduce new datasets. Instead, it uses standard benchmarks and real-world workloads:

  • SysBench: Used for various workloads including hotspot update, hotspot scan, uniform update, and read/write mixes.
  • TPC-C: A standard OLTP benchmark simulating e-commerce scenarios.
  • FiT (Financial Transaction): A real-world workload simulating Tencent's financial services, featuring a hot table for account information and a non-hot table for transaction records.
  • Hotspots: A composite real-world workload from Tencent Cloud applications experiencing high-contention spikes.

Key Insights and Ideas

  • Hotspots are a distinct problem: The paper clearly demonstrates that traditional 2PL and even general concurrency optimizations are insufficient for hotspot scenarios, where performance can degrade below serial execution.
  • Group Locking as a paradigm shift: The core idea of grouping conflicting transactions and executing them serially without individual locking for hotspots is a significant departure from traditional approaches. This effectively bypasses the bottleneck of lock acquisition and release contention.
  • Correctness is paramount: The paper dedicates significant effort to ensuring correctness, particularly in maintaining commit and rollback orders within group locking, which is crucial for serializability and failure recovery.
  • Dynamic adaptation is key: The inclusion of dynamic batch sizing and proactive deadlock handling highlights the need for adaptive strategies in real-world, fluctuating workloads.
  • Industry adoption matters: The paper emphasizes the practical implementation and successful deployment of TXSQL in Tencent's production environment, showcasing its real-world applicability.

Key Results

TXSQL demonstrates substantial performance improvements across various scenarios:

  • General High-Contention: Up to 8.25x throughput improvement over MySQL in FiT workloads.
  • Hotspot Scenarios: Up to 7.5x improvement in SysBench hotspot update workloads.
  • State-of-the-Art Comparison: Up to 6.5x improvement compared to other state-of-the-art methods and up to 22.3x compared to state-of-the-art systems in specific scenarios.
  • Synchronous Replication: Achieved 22.3x performance improvement in synchronous replication scenarios.
  • Real-world Impact: In Tencent's financial services, upgrades from MySQL to TXSQL resulted in a 30% overall performance improvement and nearly 10x boost in hotspot handling.

Limitations and Future Work

  • Single Hotspot Limitation: The current group locking mechanism is designed for transactions that update a single hotspot row. Transactions involving multiple hotspot rows are not directly supported and could lead to deadlocks. The authors suggest merging such data into a single table/row as a workaround.
  • Cascading Rollback Risk: While group locking aims to prevent deadlocks, cascading rollbacks can still occur. The paper discusses strategies to manage this, but it remains a potential concern.
  • Future Work: The authors mention that further optimizations could involve merging binlog and redolog for consistency and exploring caching hotspot row locations in the index. They also note that the group locking mechanism is independent of isolation levels and supports SELECT FOR UPDATE.

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}},
  booktitle = {SIGMOD Conference Companion},
  year = {2025},
  doi = {10.1145/3722212.3724457},
}
Figure