Home  >  Article  >  Database  >  [MySQL5.6] 最近对group commit的小优化_MySQL

[MySQL5.6] 最近对group commit的小优化_MySQL

WBOY
WBOYOriginal
2016-06-01 13:06:44985browse

最近花了一些时间在做MySQL Group Commit的优化,关于Group commit的原理,这里不再赘述,有兴趣的可以翻阅我之前的博客http://mysqllover.com/?p=581,这里简单描述下两点优化,主要基于MySQL5.6.16

1.优化binlog_order_commits=0并且sync_binlog>0时的性能 

我们知道当binlog_order_commits关闭时,表示我们能接受binlog commit和innodb commit的顺序不同(这不会带来数据不一致,但可能会影响到热备份),关闭该选项可以带来一定程度的性能提升。

本优化也是基于该前提,假定sync_binlog =1000, 那么在第1000组事务进入sync stage时,需要去做binlog sync,我们知道fsync操作是非常慢且耗时的操作,而第1001组事务,显然无需去做sync,如果我们允许innodb/binlog commit失序,就可以让第1001组事务跳过sync stage,直接进入innodb commit

detail见http://bugs.mysql.com/bug.php?id=73018,附加补丁

2.延迟写redo直到group commit时来提升性能

我们知道MySQL使用Binlog,Innodb XA的方式来进行crash recovery,所有记录在binlog中的事务我们都期望能够commit掉;这意味着,在写binlog之前,需要确保事务的prepare状态被写到redo中,这样才能从crash中恢复.

原生的逻辑中,各个事务各自做innodb prepare, 并写redo log; 只有到了commit阶段,进入ordered_commit,才进入组提交;

我们主要集中在group commit的第一阶段:flush stage。 在该阶段,leader线程从队列中pop 线程加入queue,并依次flush thread cache到binlog文件.

修改后的流程:1. 在Innodb prepare阶段不再write/sync redo log,而是直接返回

2.在group commit的flush stage阶段,修改成如下逻辑

a) 收集组提交队列

b) 调用ha_flush_logs 做一次redo write/sync

c) 将队列中thd的所有binlog cache写到binlog文件中

detail见http://bugs.mysql.com/bug.php?id=73202, 附加补丁

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn