Binlog parallel flush

更新时间:
复制 MD 格式

To improve performance, AliSQL includes the Binlog Parallel Flush optimization for the binary log commit stage. Enabling this optimization can significantly improve the write performance of your instance.

Prerequisites

  • The instance runs one of the following database versions:

    • MySQL 8.4

    • MySQL 8.0 with a minor engine version of 20230930 or later.

      Note

      On the Basic Information page, look for the Upgrade Minor Engine Version button in the Configuration Information section. If this button is visible, you can click it to view the current version. If not, your instance is on the latest version. For more information, see Upgrade Minor Engine Version.

  • The sync_binlog parameter for the instance is not set to 1.

Background

13ca93f432f146db197ded0b18b3023042978ae3ee7812bef3267aa4ca532dedQzpcVXNlcnNccWl5aW5ndGFuXEFwcERhdGFcUm9hbWluZ1xpRGluZ1RhbGtcNDI5ODE1NTU5N192MlxJbWFnZUZpbGVzXDE3MTEwMTA5NTg1MTRfMjVEODNBODItRjNCMi00OGYxLUE1RDMtNzkzNkU5REIxNjQ5LnBuZw==.png

In MySQL, every transaction must write to the binary log during the commit stage. This is a serial process: a transaction can write to the binary log only after the preceding transaction finishes, as shown in the preceding figure.

This process is also time-consuming. Before writing to the binary log, all events stored in the binary log cache must be parsed, checksums and log positions must be populated, and a GTID event must be generated. Only then can these events be written to the binary log file. This serial and time-consuming process creates a significant bottleneck for instance write performance. To address this bottleneck, AliSQL includes the Binlog Parallel Flush optimization.

Optimization details

Binary log buffer

7d62745838385a745eefff4a18d6f6ae712c7f429c11d5456c9288e66c0685d9QzpcVXNlcnNccWl5aW5ndGFuXEFwcERhdGFcUm9hbWluZ1xpRGluZ1RhbGtcNDI5ODE1NTU5N192MlxJbWFnZUZpbGVzXDE3MTEwMTEwNTY5ODBfRkE0RTZEOEYtMTg0NC00NzFiLTg0RTYtRjIxQTYyNjk4OEQwLnBuZw==.png

AliSQL enhances the standard logic by introducing a binary log buffer. After positions are allocated, multiple threads can write binary log events to the binary log buffer in parallel. A backend thread then writes the contents of the binary log buffer to the binary log file. This design allows previously serial steps—such as parsing, populating checksum and log position values, and generating GTID events—to execute in parallel. This significantly alleviates the performance bottleneck when writing binary logs during transaction commits.

Parallel group commit

In MySQL, transactions write to the binary log and redo log in groups during the commit stage. This technique, known as group commit, merges I/O operations to improve performance. This optimization retains the group commit concept and integrates it with the Binlog Parallel Flush feature, as illustrated in the following figure.

49080702daa3a9709047732fbb09ebe2c40954015a22dc572926f5f706cdec34QzpcVXNlcnNccWl5aW5ndGFuXEFwcERhdGFcUm9hbWluZ1xpRGluZ1RhbGtcNDI5ODE1NTU5N192MlxJbWFnZUZpbGVzXDE3MTEwMTEzMzE1ODZfRUVEQUNGMkEtMTE4RS00YmU4LUE0RDItQjZGRDg2NjEzMDE0LnBuZw==.png

With the Binlog Parallel Flush optimization, each transaction serially allocates a GTID and space in the binary log buffer. Subsequently, multiple groups can write to the binary log buffer in parallel. After the redo log is persisted and the backend thread finishes writing to the binary log, the system commits the entire group of transactions.

Binary log persistence

f8acb0a238e8f535995bc410175c5b167240ab1ee31b97091d438c41812720b7QzpcVXNlcnNccWl5aW5ndGFuXEFwcERhdGFcUm9hbWluZ1xpRGluZ1RhbGtcNDI5ODE1NTU5N192MlxJbWFnZUZpbGVzXDE3MTEwMTExMTgzOTBfOUMxQTkzNjktRTczNi00ZjIwLUFGNzktRUFCNERBOENBNDcwLnBuZw==.pngWith the Binlog Parallel Flush optimization, a backend thread periodically persists the binary log file. By default, this occurs once per second.

Parameters

loose_binlog_parallel_flush

This global system variable enables or disables the Binlog Parallel Flush feature. Valid values: on or off. Changes to this parameter take effect immediately without requiring an instance restart.

Performance impact

Test environment

The test compared performance across four different ApsaraDB RDS for MySQL instance specifications, as detailed in the following table.

Product

Version

vCPU and memory

Storage type

Storage size

ApsaraDB RDS for MySQL

8.0 (minor engine version 20230930)

16 vCPUs 32 GB

ESSD PL1

1000 GB

16 vCPUs 32 GB

SSD

1000 GB

64 vCPUs 128 GB

ESSD PL1

1000 GB

64 vCPUs 128 GB

SSD

1000 GB

Parameter settings

The test instance uses a high-performance parameter template with two performance-related parameters set to sync_binlog = 1000 and innodB_flush_log_at_trx_commit = 2.

Test script

The performance test used the oltp_update_non_index script from SysBench. The test dataset consisted of 100 tables, each with 100,000 rows.

Test results

The test results are shown in the following figure. Under high-concurrency workloads, the Binlog Parallel Flush feature delivers a significant performance improvement compared to the standard MySQL implementation. The peak performance gain is between 10% and 30%.

5387087b82ed9e5a496a96425aee3abbe3cd103f9e53f63b92eae933526933a3QzpcVXNlcnNccWl5aW5ndGFuXEFwcERhdGFcUm9hbWluZ1xpRGluZ1RhbGtcNDI5ODE1NTU5N192MlxJbWFnZUZpbGVzXDE3MTA0ODMyODY1NTlfOTdCMkI0NTktNTYzMi00ZmU2LUJEMTMtOEQwMjg5QTYwQTVCLnBuZw==.png