MySQL Binlog预分配的实现和性能


最近对http://forge.mysql.com/worklog/task.php?id=4925上提到的binlog预分配进行了实现,基于percoan5.5.18版本

在worklog中号称在sync_binlog = 1的情况下有10倍的tps提升。在没有group commit的情况下确实有可能。


实现思路:

与worklog中提到的不同,这里使用daemon plugin来实现预分配


1.创建一个daemon plugin,这个plugin专门用于预分配binlog文件,命名为x1~xN

在系统启动时和创建完毕预分配文件后,等待信号量;


2.在new_file_impl函数(需要切换binlog时)中增加判断,当开启预分配时:

   ---存在预分配的文件,rename之

   ---不存在,则通知daemon plugin去创建,自己直接返回,退化到正常的模式


3.增加一个变量actual_size,用于记录当前活跃binlog的写入position,在每次signal_update之前,会对其进行更新


4.修改read_log_event,避免读到预分配文件中的脏数据


简单的性能测试:

测试的结果表明在存在group commit的情况下,性能没有worklog中提到的那么高。委屈


测试1:使用mysqlslap

纯插入自增主键表
create table xxx(a int auto_increment, b int ,c varchar(100), primary key(a));

插入100w数据

mysqlslap --no-defaults -uroot --create-schema=zwx --number-of-queries=1000000 --concurrency=100 --socket=/u01/mysql/run/mysql.sock --query="insert into xxx values  (NULL,2, 'sadasda')"


1.50个线程
(1).binlog_prealloc_num = 0

tps = 1000000/149 = 6711

(2).binlog_prealloc_num = 10

tps = 1000000/82 = 12195

提升(12195-6711)/6711 = 81.7%


2.100个线程

(1).binlog_prealloc_num = 0

tps = 1000000/86.6 = 11547

(2).binlog_prealloc_num = 10

tps = 1000000/57 = 17543

提升(17543-11547)/11547=51.9%


测试2:使用sysbench测试update性能

./sysbench --debug=off --test=tests/db/update_index.lua --mysql-user=root --oltp-tables-count=5  --oltp-point-selects=0 --oltp-table-size=1000000 --num-threads=50 --max-requests=1000000 --max-time=7200 --oltp-auto-inc=off --mysql-engine-trx=yes --mysql-table-engine=innodb  --oltp-test-mode=notrx  --oltp-nontrx-mode=update_key   --mysql-socket=/u01/mysql/run/mysql.sock run 

1.50个线程
(1).binlog_prealloc_num = 0

tps = 4520.04

(2).binlog_prealloc_num = 10

tps = 6720.15

提升(6720-4520)/4520 = 48.6%


2.100个线程

(1).binlog_prealloc_num = 0

tps = 5967.17

(2).binlog_prealloc_num = 10

tps = 7698.61


提升(7698-5967)/5967 = 29%


-----------------------------------

提升有限,初步测试性能介于sync_binlog = 1 和 sync_binlog = 0之间,不过聊胜于无.后续等稳定后放出patch

相关内容