High-Value Transaction Processing With MySQL
High-Value Transaction Processing With MySQL
Mark Callaghan
Percona Live
February, 2011
What do I mean by value?
▪ Low price?
▪ High price/performance?
▪ Valuable data
OLTP in the datacenter
▪ Sharding
▪ Availability
▪ Legacy applications
▪ Used by many applications
Sharding
▪ Sharding is easy, resharding is hard
▪ Joins within a shard are still frequent and useful
▪ Some all-shards joins must use Hive
▪ Provides some fault-isolation benefits
Availability
▪ Sources of downtime
▪ Schema change (but now we have OSC)
▪ Manual failover
▪ Misbehaving applications
▪ Oops
Used by many applications
If your company is successful then
▪ Your database will be accessed by many different applications
▪ Application authors might not be MySQL experts
▪ Application owners might have different priorities than the DB team
Legacy applications
If your company is successful then you will have
▪ Applications written many years ago by people who are gone
▪ Design decisions that are not good for your current size
▪ Not enough resources or time to rewrite applications
Our busy OLTP deployment
▪ Query response time ▪ Rows read per second
▪ 4 ms reads, 5ms writes ▪ 450M peak
▪ Need
multiple purge threads as the main background thread can
become the dedicated purge thread and that isn’t enough
do {
n_pages_purged = trx_purge();
} while (n_pages_purged);
InnoDB insert buffer stalls
▪ The insert buffer is not drained as fast as it can get full
▪ Drain rate is 5% of innodb_io_capacity
▪ bugs.mysql.com/59214
▪ bugs.mysql.com/55004
▪ When stats are recomputed many uses of that table will stall
▪ Fixed in the Facebook patch
▪ Most threads in InnoDB will block waiting for the buffer pool mutex
▪ bugs.mysql.com/51325 and bugs.mysql.com/56332
▪ I hope Yasufumi can fix it
LOCK_open and kernel_mutex conflicts
▪ Thread A
▪ Gather table statistics while holding LOCK_open
▪ Block on kernel_mutex while starting a transaction
▪ Thread B
▪ Hold kernel_mutex while doing deadlock detection
▪ bugs.mysql.com/54790
▪ bugs.mysql.com/49047
Stalls from innodb_thread_concurrency
▪ When
there are 1000+ sleeping threads it can take too long to
wake up a specific thread
▪ Changeinnodb_thread_concurrency to use FIFO scheduling in
addition to existing use of LIFO and FIFO+LIFO = FLIFO
▪ Fixed in the Facebook patch
Sysbench TPS with FLIFO
IO efficiency
High priority problems for me are:
▪ Reducing IOPs used for my workload
▪ Supporting very large databases
Significant improvements:
▪ Switch from mysqldump to XtraBackup
▪ Run innosim to confirm storage performance
▪ Tune InnoDB
▪ Improve schemas and queries
mysqldump vs XtraBackup
▪ mysqldump is slower for backup
▪ Clustered index is scanned row-at-a-time in key order (lots of random reads)
▪ Backup accounts for half of the disk reads for servers I watch
▪ Incremental backup
▪ Not possible with mysqldump
▪ XtraBackup has incremental (scan all data, write only the changed blocks)
▪ Vamsi from Facebook added support for really incremental, scan & write only
the changed blocks
innosim storage benchmark
▪ InnoDB IO simulator that models
▪ Doublewrite buffer
▪ Dirty page writes
▪ Transaction log and binlog fsync and IO
▪ User transactions that do read, write and commit
▪ Smaller pages are better for some but not all tables
▪ A large log file can reduce the dirty page flush rate
▪ A large buffer pool can reduce the page read rate
IOPs is a function of size and concurrency
Smaller pages aren’t always better
Checkpoint IO rate by log file size
Page read rate by buffer pool size
Improve schemas
▪ Make your performance critical queries index only
▪ Primary key columns are included in the secondary index
▪ Understand how the insert buffer makes index maintenance cheaper