Dump Thread Enhancement On MySQL-5.7.2

    Dump Thread Enhancement On MySQL-5.7.2 On the new milestone release MySQL 5.7.2, we did some optimizations  on binlog lock and dump thread. Major dump thread cod...
On the new milestone release MySQL 5.7.2, we did some optimizations  on binlog lock and dump thread. Major dump thread code was re-written: Some code never reached was removed; Complex
logic was simplified; Code became more readable. But I don't want to introduce the refactoring here. Today, I would like to introduce you the optimization on binlog lock which improved master throughput.

Background
binlog lock(LOCK_log) is a mutex which is used to protect binlog read and write operations. With this mutex, binlog read and write operations are safe. But it has limited concurrency. Not only can dump threads and user sessions not read and write binlog simultaneously but even the dump threads themselves cannot read the binlog simultaneously. 
attachments-2017-08-nBR1bq9Y59a014f4c7ad
All other sessions have to wait whenever one session is reading or writing a binlog file. So sequential
read and write could be a bottleneck especially when read and write operations are slow.
Better Concurrency in MySQL 5.7.2
To improve binlog read and write concurrency, we made the following optimization:
  • Removed binlog lock from dump thread
  • Introduced safe read boundary to guarantee binlog read safe.
Binlog looks like a log file which is append only, it is safe to read the binary events which are appended without a lock. And so the binlog lock was removed from the dump thread. Instead of using the binlog lock, the safe read boundary(max position) is maintained for the active binlog. 

Dump threads never read positions that exceed the safe read boundary. It will wait for the boundary to be updated when it reaches the boundary.

User sessions are responsible for updating the safe read boundary after its binlog events have been appended.

attachments-2017-08-BNYUfYVN59a015571d70
From above diagram, we can know that:

  • Dump threads are not blocked by each other while reading binlog events.
  • Dump threads are not blocked by the user session which is writing binlog events.
  • Users sessions are not blocked by dump threads which is reading binlog events.
So both dump threads and users sessions get better throughput and the improvement is remarkable especially when there are many slaves.
  • 发表于 2017-08-25 20:14
  • 阅读 ( 47 )

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
石天
石天

437 篇文章

作家榜 »

  1. shitian 662 文章
  2. 石天 437 文章
  3. 每天惠23 33 文章
  4. 小A 29 文章