All Products
Search
Document Center

ApsaraDB RDS:Use binlog cache free flush

Last Updated:Mar 30, 2026

When a large transaction commits, ApsaraDB RDS for MySQL holds a write lock while flushing binary log events from the session cache to a binary log file. If the binary log cache grows to dozens of GB, this lock blocks all write requests and can exhaust I/O resources, leaving the instance unresponsive.

The binlog cache free flush feature eliminates this bottleneck by converting temporary files in the binary log cache directly into binary log files at commit time, instead of reading and re-writing each event under a lock. This shortens large-transaction commit time, reduces I/O consumption, and keeps the instance responsive.

Prerequisites

Before you begin, make sure that:

  • Your RDS instance runs MySQL 8.0 or MySQL 5.7

  • The minor engine version is 20240731 or later

To check the minor engine version, log on to the ApsaraDB RDS console and go to the Basic Information page. In the Configuration Information section, check whether the Upgrade Kernel Version button is displayed. If the button appears, click it to view and update the minor engine version. If the button is not displayed, the instance is already on the latest minor engine version. For more information, see Update the minor engine version.

Enable and configure the feature

Enable the feature

Run the following command to enable binlog cache free flush:

SET GLOBAL loose_binlog_cache_free_flush = on;

The change takes effect immediately. You do not need to restart the instance.

Verify the feature is active

SHOW GLOBAL VARIABLES LIKE 'loose_binlog_cache_free_flush';

Tune the threshold

The loose_binlog_cache_free_flush_limit_size parameter sets the minimum binary log data size that triggers the conversion. The default is 256 MB, meaning only transactions whose binary log data exceeds 256 MB use the free-flush path.

To apply the optimization to smaller transactions, lower the threshold:

SET GLOBAL loose_binlog_cache_free_flush_limit_size = <size-in-bytes>;

Disable the feature

SET GLOBAL loose_binlog_cache_free_flush = off;

Parameters

Parameter Default Description
loose_binlog_cache_free_flush off Enables or disables the feature. Global system variable. Takes effect immediately without restarting the instance. Valid values: on, off.
loose_binlog_cache_free_flush_limit_size 268435456 (256 MB) The threshold that triggers conversion. When a transaction's binary log data exceeds this value, temporary files in the binary log cache are converted to binary log files at commit time. Value range: 20971520–18446744073709551615 bytes.

How it works

Binary log cache

image

Each session gets its own binary log cache—a combination of in-memory space (bounded by binlog_cache_size) and temporary files on disk. When a transaction's events overflow the in-memory limit, they spill into a temporary file.

At commit time, the engine reads every event from the cache, updates the end position and checksum, and writes them to the binary log file under a write lock. The lock ensures events are written without interruption, but it blocks other transactions for the entire duration of the flush.

Impact of large-transaction binary log writes

image

When a transaction's binary log cache reaches dozens of GB, flushing it at commit time causes two problems:

  • Write requests blocked: The write lock is held for the entire flush, preventing other transactions from writing.

  • I/O exhaustion: The large sequential write consumes I/O resources and can make the instance unresponsive.

How binlog cache free flush resolves this

image

AliSQL optimizes the binary log caching mechanism so that temporary files in the cache can be converted directly into binary log files. Two changes make this possible:

  • Reserved header space: When events are written to the temporary file, space is reserved at the beginning for binary log file headers. When the temporary file is converted to a binary log file, that reserved space is filled with the required headers—no separate write is needed.

  • Precomputed end positions: Each event calculates its end position based on the size of the reserved space, so positions are already correct after conversion.

What the converted binary log file contains

image

When a large transaction commits, the reserved space at the beginning of the temporary file is filled with the following data before conversion:

Data Description
File header The 4-byte magic number [0xFE 'bin'] that identifies the file as a binary log file
Header events The format description event and the previous global transaction identifier (GTID) event
Empty event An ignorable-type event that fills any remaining reserved space
GTID event The GTID of the committing transaction, generated at commit time

The rest of the file retains the transaction's original events: query events, table map events, row-based events, and XID events.

image

Differences from a regular binary log file

Converted binary log files differ from regular binary log files in two ways:

  • They contain an empty event (ignorable type) that occupies the remaining reserved space.

  • Checksum is disabled by default.

The binlog cache free flush feature does not change the binary log file format. Replication and third-party tools are not affected.

Optimization effects

image.png

The figure compares large-transaction commit times on instances using Enterprise SSDs (ESSDs) of performance level 1 (PL1) and Premium Local SSDs, with the feature enabled and disabled. Enabling binlog cache free flush shortens commit time and resolves both I/O resource exhaustion and long write-lock duration.