If you are using MariaDB for some time now you may have heard about adaptive flushing. “Adaptive” refers to a behavior where-in the algorithm auto-tunes itself based on certain parameters. In the new-generation world, it is called an “AI-based algorithm”. The same concept is now being applied to purge. Purge is a critical and resource-consuming operation so scheduling of purge along with user workload needs to be balanced. This is what exactly adaptive purge would do.
Adaptive Purge in MariaDB appeared first on MariaDB.org
If you are using MariaDB for some time now you may have heard about adaptive flushing. “Adaptive” refers to a behavior where-in the algorithm auto-tunes itself based on certain parameters. In the new-generation world, it is called an “AI-based algorithm”. The same concept is now being applied to purge. Purge is a critical and resource-consuming operation so scheduling of purge along with user workload needs to be balanced. This is what exactly adaptive purge would do.
A quick note on purgeMySQL/MariaDB doesn’t immediately delete the data. Data is marked for delete and updated data is placed in the mainline tree. Old data is copied over to UNDO logs. This is needed to support multi-version concurrency control (further details are beyond the scope of this blog so you can always read details here).
These old copies needs to be cleaned/removed/purged once there is no active transactions referring to it. This is done by the purge operations in the background. There are dedicated purge thread(s) meant to do this operation. Configurable using innodb_purge_threads (default=4/max=32).
If purge is being done aggressively along with the active user workload, the latter will start seeing effects like jitter, reduced performance, etc.. Let’s see how adaptive purge could help solve these issues.
Benchmarking purge with user workload
The purge system is multi-threaded with N threads progressing in parallel. If we can limit these threads (based on the redo log fill factor) we can limit the pressure, purge is adding on the redo-log allowing the user/active workload to make effective use of redo-log. On the flip side, there will be an increase in history length and in turn larger undo-logs (that can eventually truncate with mariadb supporting undo log truncate).
Let’s try to devise an algorithm using this rule and see if that helps improve active workload.
Note: lower and higher watermarks are pre-configured to 20/80 (currently not user-configurable. not sure if really needed). The number of buckets/ranges depends upon the number of purge threads. The ranges are created using arithmetic progression if possible otherwise, an average distribution is used.
If your workload and/or configuration are such that even without purge the active workload continues to put pressure on redo-log, in such cases furious flushing will take place but this algorithm will not solve the said issue since it is not originating from the purge.
With the faster disk (say NVMe SSD), we observed that flushing is done quite fast thereby keeping a check on redo-log size and so adaptive purge may not kick in (depending on size of redo-log).
Adaptive purge not only helps reduce jitter in performance but also helps improve overall throughput there-by improving the responsiveness of the server (including latency).
If you have more questions/queries do let me know. Will try to answer them.
| # | Наименование новости | Тональность | Информативность | Дата публикации |
|---|---|---|---|---|
| 1 | Tune your MariaDB IO workload using this simple step | 0 | 6.97 | 14-07-2021 |
| 2 | Using temporary tables in MariaDB | 0 | 5.76 | 02-05-2024 |
| 3 | MariaDB has broken the concept of dynamically configurable buffer pools! | 0 | 10.18 | 09-02-2026 |
| 4 | InnoDB Page Flushing Diagram | 0 | 5.76 | 18-06-2022 |
| 5 | What is MariaDB? | 0 | 7.66 | 21-09-2023 |
| 6 | Slides: MariaDB’s Join Optimizer: how it works and current fixes | 0 | 4.6 | 20-07-2022 |
| 7 | MariaDB Contribution Statistics, January-June 2026 | 0 | 11.03 | 25-08-2026 |
| 8 | What the Flush? | 0 | 11.7 | 05-07-2020 |
| 9 | Interesting Binary Logging Optimization in MariaDB | 0 | 4.87 | 26-05-2025 |
| 10 | I’m joining MariaDB! | 0 | 8.26 | 27-11-2021 |