pt-online-schema-change and binlog_format
Join the DZone community and get the full member experience.
Join For Freestatement-based or row-based, or mixed? we’ve all seen this discussed at length so i’m not trying to rehash tired arguments. at a high level, the difference is simple:
- statement based replication (sbr) replicates the sql statements to the slave to be replayed
- row based replication (rbr) replicates the actual rows changed to the slave to be replayed
- mixed mode uses rbr in the event of a non-deterministic statement, otherwise uses sbr
recently, i worked with a client to optimize their use of pt-online-schema-change and keep replication delay to a minimum. we found that using rbr in conjunction with a smaller chunk-time was the best result in their environment due to reduced io on the slave, but i wanted to recreate the test locally as well to see how it looked in the generic sense (sysbench for data/load).
here was my local setup:
- 3 vms (centos 6.4, 512m ram, macbook pro host)
- 1 vm was for sysbench and pt-osc
- 1 master, 1 slave (percona server 5.5.30, 256m buffer pool)
and here is the base test that i ran:
- populate the db with four, 1 million row tables
- restart mysql to ensure an empty buffer pool (no lru dump/restore)
- run pt-osc against the master and capture diagnostics on slave
- repeat with both sbr and rbr
visually, the most telling difference between the two baselines comes from comparing the slave iops when using sbr vs rbr:
while the write operations look similar in both, you can see the dramatic difference in the read operations in that they are almost negligible when using row based. i had assumed there would be high read iops as the buffer pool was empty, so i also verified that the innodb_buffer_pool_reads (reads that missed the buffer pool and went to disk) on both:
looking at how pt-osc and the buffer pool operate, these results make sense for this workload. here is the basic process for pt-osc:
- create a new, shadow table based on the original table
- apply the alters to the new shadow table
- add triggers to the original table to track changes
- run insert … select chunk against the original table to populate the shadow table
- rename the tables after all records are copied
in the case of sbr, the actual insert … select chunk is replayed on the slave verbatim, meaning that the chunk will need to be read from disk if not in the bp in order to insert it into the new table. however, when using rbr, you simply send the rows to the slave. as this is a new table, there is nothing to read from disk so innodb simply writes the new page and it eventually gets flushed to disk.
this is where the –set-vars switch can come in handy with pt-online-schema-change. picture this scenario:
- the buffer pool is undersized (due to lack of memory compared to data size)
- you are altering a table that mostly archive (i.e. not hot data)
- the slave is nearly io bound already as it is actively serving read traffic
in this case, adding extra read iops to the slave could be a performance killer. so assuming you have binlog_format=mixed on the slave, you can use the –set-vars like this to run the alter using rbr to save on iops:
pt-online-schema-change –alter=”engine=innodb” –set-vars=”binlog_format=row” –execute h=master,d=db,t=tbl
keep in mind, rbr isn’t going to give you the same results in the course of normal replication. when replicating changes to the slave, the page is requested from the buffer pool and read from disk if not present so that the changes can be applied to it. this can still be a win (think of a query that is very complicated that returns only a few rows), but you won’t see the dramatic difference as you do when using this approach with pt-osc.
Published at DZone with permission of Peter Zaitsev, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
-
Microservices With Apache Camel and Quarkus
-
Writing a Vector Database in a Week in Rust
-
How To Approach Java, Databases, and SQL [Video]
Comments