MariaDB系统参数binlog_commit_wait_count引起的单线程单表插入性能低下问题

Stella981
• 阅读 538

binlog_commit_wait_count和binlog_commit_wait_usec两个参数是MariaDB 10.0开始引入的新参数,根据官方文档介绍:

binlog_commit_wait_count

  • Description: For use in parallel replication. The binary log can delay the commit step of a transaction until the given number of transactions are all ready to commit together (group commit). The delay will however not be longer than the value set by binlog_commit_wait_usec. The default value of 0 means that no delay is introduced. Setting this value can reduce I/O on the binary log and give an increased opportunity for parallel apply on the slave, but too high a value will decrease the commit throughput. By monitoring the status variable binlog_group_commit_trigger_count (>=MariaDB 10.1.5) it is possible to see how often this is occurring.
  • Starting with MariaDB 10.0.18 and MariaDB 10.1.4: If the server detects that one of the committing transactions T1 holds an InnoDB/XtraDB row lock that another transaction T2 is waiting for, then the commit will complete immediately without further delay. This helps avoid losing throughput when many transactions need conflicting locks. This often makes it safe to use this option without losing throughput on a slave with parallel replication, provided the value of slave_parallel_threads is sufficiently high.
  • Commandline: --binlog-commit-wait-count=#]
  • Scope: Global
  • Dynamic: Yes
  • Data Type: numeric
  • Default Value: 0
  • Range: 0 - 18446744073709551615
  • Introduced: MariaDB 10.0.5

binlog_commit_wait_usec

  • Description: For use in parallel replication. The binary log can delay the commit step of a transaction by this many microseconds. By monitoring the status variable binlog_group_commit_trigger_timeout (>=MariaDB 10.1.5) it is possible to see how often group commits are made due to binlog_commit_wait_usec. As soon as the number of pending commits reaches binlog_commit_wait_count, the wait will be terminated, though. Thus, this setting only takes effect if binlog_commit_wait_count is non-zero.
  • Commandline: --binlog-commit-wait-usec#
  • Scope: Global
  • Dynamic: Yes
  • Data Type: numeric
  • Default Value: 100000
  • Range: 0 - 18446744073709551615
  • Introduced: MariaDB 10.0.5

这两个参数用于并行复制,在并行复制中做一定的延迟,进而使用到组提交这一特性,我的理解是为了提升主从复制的性能,而不影响独立运行的服务器,而实际情况是什么,我们进行如下测试:

测试场景一(binlog_commit_wait_count = 10,binlog_commit_wait_usec系统默认):

binlog_commit_wait_count = 10
binlog_commit_wait_usec = 6000

10000条数据插入:

# time mysql sbtest < sbtest.sql

real    1m6.715s
user    0m0.280s
sys     0m0.694s

# time mysql sbtest < sbtest.sql

real    1m6.700s
user    0m0.290s
sys     0m0.656s

测试场景二(binlog_commit_wait_usec设置小于系统默认值):

binlog_commit_wait_count = 0
binlog_commit_wait_usec = 6000

10000条数据插入:

# time mysql sbtest < sbtest.sql

real    0m2.211s
user    0m0.178s
sys     0m0.143s

# time mysql sbtest < sbtest.sql

real    0m2.280s
user    0m0.236s
sys     0m0.188s

测试场景三(binlog_commit_wait_usec = 0):

binlog_commit_wait_count = 0
binlog_commit_wait_usec = 0

10000条数据插入:

# time mysql sbtest < sbtest.sql

real    0m5.266s
user    0m0.277s
sys     0m0.261s

# time mysql sbtest < sbtest.sql

real    0m5.852s
user    0m0.354s
sys     0m0.312s

测试场景四(系统默认):

binlog_commit_wait_count = 0
binlog_commit_wait_usec = 100000

10000条数据插入:

# time mysql sbtest < sbtest.sql

real    0m2.598s
user    0m0.373s
sys     0m0.238s

# time mysql sbtest < sbtest.sql

real    0m2.542s
user    0m0.297s
sys     0m0.231s

测试场景五(binlog_commit_wait_usec设置小于系统默认值):

binlog_commit_wait_count = 0
binlog_commit_wait_usec = 200000

10000条数据插入:

# time mysql sbtest < sbtest.sql

real    0m2.398s
user    0m0.195s
sys     0m0.194s

# time mysql sbtest < sbtest.sql

real    0m2.235s
user    0m0.178s
sys     0m0.163s

结论

根据官方文档介绍,这两个参数应该只影响主从复制的服务器架构,但实际使用对独立运行的服务器也有很大的影响,使用binlog_commit_wait_count时单表单线程10000条数据插入耗时1分6秒,不是用该参数时单表单线程10000条数据插入耗时不足3秒。同时关闭binlog_commit_wait_usec时单表单线程10000条数据插入耗时5秒多。binlog_commit_wait_usec取6000/默认值/2倍默认值差别不大,所以建议使用默认参数即可。

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Stella981 Stella981
2年前
Python之time模块的时间戳、时间字符串格式化与转换
Python处理时间和时间戳的内置模块就有time,和datetime两个,本文先说time模块。关于时间戳的几个概念时间戳,根据1970年1月1日00:00:00开始按秒计算的偏移量。时间元组(struct_time),包含9个元素。 time.struct_time(tm_y
Wesley13 Wesley13
2年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Wesley13 Wesley13
2年前
Oracle一张表中实现对一个字段不同值和总值的统计(多个count)
需求:统计WAIT\_ORDER表中的工单总数、未处理工单总数、已完成工单总数、未完成工单总数。表结构:为了举例子方便,WAIT\_ORDER表只有两个字段,分别是ID、STATUS,其中STATUS为工单的状态。1表示未处理,2表示已完成,3表示未完成总数。 SQL:  1.SELECT   2
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
为什么mysql不推荐使用雪花ID作为主键
作者:毛辰飞背景在mysql中设计表的时候,mysql官方推荐不要使用uuid或者不连续不重复的雪花id(long形且唯一),而是推荐连续自增的主键id,官方的推荐是auto_increment,那么为什么不建议采用uuid,使用uuid究
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这