By Mat Keep on Feb 07, 2013
With data volumes and user populations growing, its no wonder that database performance is a hot topic in developer and DBA circles.
Its also no surprise that continued performance improvements were one of the top design goals of the new MySQL 5.6 release which was declared GA on February 5th (note: GA means “Generally Available”, not “Gypsy Approved” @mysqlborat)
And the performance gains haven’t disappointed:
- Dimitri Kravtchuk’s Sysbench tests showed MySQL delivering up to 4x higher performance than the previous 5.5 release.
- Mikael Ronstrom’s testing showed up to 4x better scalability as thread counts rose to 48 and 60 threads (not so uncommon in commodity systems today)
Of course, YMMV (Your Mileage May Vary) in real-world workloads, but you can be reasonably certain you will see performance gains by upgrading to MySQL 5.6. It is up to you whether you invest these gains to serve more applications and users from your MySQL databases, or you consolidate to fewer instances to reduce operational costs.
How about if you are using MySQL replication in order to scale out your database across commodity nodes, and as a foundation for High Availability (HA)? Performance here has also been improved through a combination of:
- Binary Log Group Commit
- Multi-Threaded Slaves
- Optimized Row-Based Replication
As well as giving you the benefits above; higher replication performance directly translates to:
- Reduced risk of losing data in the event of a failure on the master
- Improved read consistency from slaves
- Resource-efficient binlogs traversing the replication cluster
We will look at each of these in more detail.
Binlog Group Commit
Rather than applying writes one at a time, Binary Log Group Commit batches writes to the Binlog, significantly reducing overhead to the master. This is demonstrated by the benchmark results below.
Using the SysBench RW tests, enabling the binlog and using the default sync_binlog=0 reduces the throughput of the master by around 10%. With sync_binlog=1 (where the MySQL server synchronizes its binary log to disk after every write to the binlog, thereby giving maximum data safety), throughput is reduced by a further 5%.
To understand the difference this makes, the tests were repeated comparing MySQL 5.6 to MySQL 5.5
Even with sync_binlog=1, MySQL 5.6 was still up to 4.5x faster than 5.5 with sync_binlog=0
Gone are the days when configuring replication resulted in a 50% or more hit to performance of your master.
The result of Binary Log Group Commit is that MySQL replication is much better able to keep pace with the demands of write-intensive workloads, imposing much less overhead on the master, even when the binlog is flushed to disk after each commit!
Details of the configurations used for the benchmark are in the Appendix at the end of this post.
You can learn more about the implementation of Binlog Group Commit from Mats Kindahl’s blog.
Looking beyond the replication master, it is also necessary to bring performance enhancements to the replication slaves.
Using Multi-Threaded Slaves, processing is split between worker threads based on schema, allowing updates to be applied in parallel, rather than sequentially. This delivers benefits to those workloads that isolate application data using databases - e.g. multi-tenant systems deployed in cloud environments.
Benchmarks demonstrate that Multi-Threaded Slaves increase performance by 5x.
This performance enhancement translates to improved read consistency for clients accessing the replication cluster. Slaves are better able to keep up with the master, and so users are much less likely to need to throttle the sustained throughput of writes, just so that the slaves don't indefinitely fall further and further behind (previously some users had to reduce the capacity of their systems in order to reduce slave lag).
You can get all of the details on this benchmark and the configurations used in this earlier blog posting
Optimized Row-Based Replication
The final piece in improving replication performance is to introduce efficiencies to the binary log itself.
By only replicating those elements of the row image that have changed following INSERT, UPDATE and DELETE operations, replication throughput for both the master and slave(s) can be increased while binary log disk space, network resource and server memory footprint are all reduced.
This is especially useful when replicating across datacenters or cloud availability zones.
Another performance enhancements is the was Row-Based Replication events are handled on the slave against tables without Primary Keys. Updates would be made via multiple table scans. In MySQL 5.6, no matter size of the event, only one table scan is performed, significantly reducing the apply time.
You can learn more about Optimized Row Based Replication from the MySQL documentation.
Crash-Safe Slaves and Binlog
Aka “Transactional Replication” this is more of an availability than a performance feature, but there is a nice performance angle to it.
The key concept behind crash safe replication is that replication positions are stored in tables rather than files and can therefore be updated transactionally, together with the data. This enables the slave or master to automatically roll back replication to the last committed event before a crash, and resume replication without administrator intervention. Not only does this reduce operational overhead, it also eliminates the risk of data loss or corruption.
From a performance perspective, it also means there is one less disk sync, since we leverage the storage engine's fsync and don't need an additional fsync for the file, giving users a performance gain.
So with a faster MySQL Server, InnoDB storage engine and replication, developers and DBAs can get ahead of performance demands. Bear in mind there is more to MySQL 5.6 replication than performance – for example Global Transaction Identifiers (GTIDs), replication event checksums, time-delayed replication and more.
To learn more about all of the new replication features in MySQL 5.6, download the Replication Introduction guide
To get up and running with MySQL replication, download the new Replication Tutorial Guide
Appendix – Binary Log Group Commit Benchmarks
System Under Test:
5 x 12 thread Intel Xeon E7540 CPUs @2.00 GHz
512 GB memory
Oracle Linux 6.1