简体   繁体   中英

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

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 . when log_bin is comment out #log_bin=mysql_bin, jmeter test result is 3500.2 transaction/second .

on both setting the insert rate is similar, about 8000 transaction/second.

why log_bin has terrible performance impact on mysql? how can I improve update performance when log_bin is turn on?

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. The long answer comes from an article by Baron Schwartz, the lead author of the MySQL performance blog:

Enabling the binary log reduces MySQL's performance dramatically. 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. And the server performs an XA transaction between InnoDB and the binary log. This adds more fsync calls, and causes mutex contention, and prevents group commit, and probably other things that aren't coming to mind now.

You can read the full article here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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