最近對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