How Tencent’s TXSQL Supercharges MySQL Performance and Stability in the Cloud
This article details the design, performance enhancements, feature extensions, stability improvements, and benchmark results of TXSQL—a heavily customized MySQL branch used by Tencent Cloud’s CDB service—to illustrate how it achieves higher throughput, stronger consistency, and better reliability for large‑scale cloud databases.
Introduction
As Tencent's largest MySQL service, Cloud Database (CDB) is the most popular relational database on Tencent Cloud. CDB provides a full suite of operations solutions—backup, monitoring, rapid scaling—and runs on a deeply customized kernel called TXSQL (Tencent MySQL), which offers higher performance, stronger stability, and enterprise‑grade features.
What is TXSQL and Why Build It?
TXSQL is a Tencent‑internal project that deeply customizes the MySQL source code to meet both internal and external customers’ diverse functional and performance requirements. It supports workloads ranging from a few gigabytes to hundreds of terabytes and serves as the critical foundation for stable business operation.
Key work areas include:
Database performance tuning
Kernel deep modifications for high‑traffic events
Implementation of business‑required features
Resource‑management support in the kernel
Diagnostic tools for DBAs
Bug fixing for kernel‑level issues
Data security guarantees
What TXSQL Has Done
Version Selection
TXSQL 5.6 is based on MySQL 5.6.28 because it was the most stable 5.6 release at the time, widely adopted by users, and free of serious bugs present in early 5.7 releases.
Performance Improvements
Read‑view Optimization
Read‑view creation previously required a global lock and traversal of a long transaction list, becoming a bottleneck under high concurrency. TXSQL introduced a globally ordered transaction‑ID set, a compact active‑transaction list for purge, per‑trx cached read‑view buffers, and removed the redundant ro_trx_list from 5.6, dramatically improving read/write performance.
Redo Log Group Commit
TXSQL collects the maximum redo‑log LSN from all engines and forces logs with smaller LSN to flush before the first commit phase, reducing mutex contention and improving write throughput.
Redo Log Double Buffering
A double‑buffer mechanism with a separate w_mutex allows flushing redo logs while releasing the main log_sys‑mutex, thus increasing concurrency.
Adaptive Hash Index (AHI) Lock Splitting
TXSQL adopts the 5.7‑style AHI lock splitting and introduces a new index‑lock protocol, reducing lock contention while allowing AHI to be disabled when it harms performance.
Feature Additions
Multiple Working Modes
TXSQL supports read‑only, read‑write, and unavailable modes, each restricting client operations accordingly, which helps OSS implement cross‑region disaster recovery without double‑write issues.
ALTER TABLE … NOWAIT
Inspired by Oracle, TXSQL adds a timeout option to DDL statements to avoid long‑running lock blocks.
Extended Lock System
TXSQL implements a connection‑independent lease‑based read‑write lock (cdb_lock / cdb_unlock) for distributed transactions, exposing a C API for application use.
int cdb_lock(string key, int type, uint64_t wait_timeout, uint64_t timeout); int cdb_unlock(string key);Semi‑Sync Strengthening
Improvements include an ACK thread for parallel processing, replacing select‑based fd monitoring with poll, enhancing dump‑thread checks, and adding status fields to display waiting binlog positions and elapsed wait time.
Stability Improvements and Testing
TXSQL addresses memory‑allocation jitter, thread‑contention, buffer‑pool flushing bottlenecks, replication lag, and various kernel bugs (redo‑log deadlocks, charset issues, shutdown problems). Each patch is accompanied by test cases, coverage tests, regression, performance, and stress testing before gray‑release.
Financial Business Support
To guarantee strong consistency for financial workloads, TXSQL prevents user‑kill during ACK waiting, monitors long‑wait situations, implements a lease‑based HA mechanism to avoid double‑writes across regions, and splits the master lock_log to improve write performance.
Version Performance
Recent releases (TXSQL_20160730, TXSQL_20160902, TXSQL_20161130) have resolved high‑concurrency performance drops, optimized redo‑log handling, fixed charset and shutdown bugs, and demonstrated superior performance and stability in sysbench benchmarks compared with MySQL 5.6.28, 5.6.35, and 5.7.17.
TXSQL_0730 introduced advanced ideas and fixed bug #49169, stabilizing high‑traffic workloads. TXSQL_0902 optimized redo‑log and added lease‑based mode to avoid double‑writes. TXSQL_1130 fixed widespread charset and shutdown issues, further improving stability.
Benchmark charts (select.lua, update_index.lua, oltp.lua) show TXSQL consistently outperforming the official MySQL versions.
About TXSQL 5.7
Support for MySQL 5.7 is planned, including index‑lock splitting, Group Replication, JSON support, virtual columns, query rewrite, sys schema monitoring, and InnoDB tablespace encryption.
Future Directions
TXSQL will continue to develop features driven by business needs (audit, firewall), performance optimizations (hotspot updates, multi‑statement commits), risk‑resistance (malicious SQL, index anomalies), deeper open‑source collaboration, and operational tools for DBAs.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
