简体   繁体   English

log_bin打开时,mysql 5.6.21更新语句非常慢

[英]mysql 5.6.21 update statement is very slow when log_bin is on

my update statement is 我的更新声明是

update ptest set amount = amount - 2000 where id = 2

table ptest is 表ptest是

CREATE TABLE `ptest` (
  `id` bigint(19) NOT NULL AUTO_INCREMENT,
  `developerId` bigint(19) DEFAULT NULL,
  `appId` bigint(19) DEFAULT NULL,
  `caller` varchar(20) DEFAULT NULL,
  `callerDisplay` varchar(20) DEFAULT NULL,
  `called` varchar(20) DEFAULT NULL,
  `calledDisplay` varchar(20) DEFAULT NULL,
  `startTime` datetime DEFAULT NULL,
  `endTime` datetime DEFAULT NULL,
  `callTime` int(11) DEFAULT NULL,
  `callId` varchar(32) NOT NULL ,
  `billingTime` int(11) DEFAULT NULL,
  `callResult` varchar(10) DEFAULT NULL,
  `amount` bigint(20) DEFAULT NULL ,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=200001 DEFAULT CHARSET=utf8;

when system variable log_bin was set to: log_bin=mysql_bin, jmeter test result is 237.4 transaction/second . 当系统变量log_bin设置为:log_bin = mysql_bin时,jmeter测试结果为237.4 transaction / second。 when log_bin is comment out #log_bin=mysql_bin, jmeter test result is 3500.2 transaction/second . 当log_bin被注释掉#log_bin = mysql_bin时,jmeter测试结果为3500.2 transaction / second。

on both setting the insert rate is similar, about 8000 transaction/second. 在两个设置上的插入率都差不多,大约为8000个事务/秒。

why log_bin has terrible performance impact on mysql? 为什么log_bin对mysql有可怕的性能影响? how can I improve update performance when log_bin is turn on? 打开log_bin时如何提高更新性能?

Short answer is no. 简短的答案是没有。 You can't improve the performance while binary logging is on. 二进制日志记录打开时,您无法提高性能。 I think this is one of the biggest tradeoffs in MySQL. 我认为这是MySQL中最大的折衷之一。 The long answer comes from an article by Baron Schwartz, the lead author of the MySQL performance blog: 长答案来自MySQL性能博客的主要作者Baron Schwartz的一篇文章:

Enabling the binary log reduces MySQL's performance dramatically. 启用二进制日志会大大降低MySQL的性能。 It is not the logging itself that's the problem — writing the log is usually not much additional work. 问题不是日志本身,写日志通常不需要太多额外的工作。 It's ensuring consistency and durability that is expensive. 它确保了昂贵的一致性和耐用性。 Flushing it to disk adds an fsync call for every transaction. 将其刷新到磁盘会为每个事务添加一个fsync调用。 And the server performs an XA transaction between InnoDB and the binary log. 然后,服务器在InnoDB和二进制日志之间执行XA事务。 This adds more fsync calls, and causes mutex contention, and prevents group commit, and probably other things that aren't coming to mind now. 这增加了更多的fsync调用,并导致互斥锁争用,并阻止了组提交,并且可能还阻止了其他一些现在还没有想到的事情。

You can read the full article here . 您可以在此处阅读全文

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM