Is your MySQL buffer pool warm? Make it sweat!
Join the DZone community and get the full member experience.Join For Free
this post comes from
at the mysql performance blog.
today’s blog post diving into the waters of the mysql buffer pool is a cross-post from
groupon’s engineering blog
, and is part 1 of 2. thank you to
at groupon for contributing to this project and post. we’ll be posting part 2 on thursday. i’ll be at the
percona live mysql conference and expo
next week in santa clara, california so look for me there – i’d love to connect and talk more about mysql buffer pools or anything else that’s on your mind!
there are numerous solutions for mysql high availability. many rely on mysql’s asynchronous replication to maintain a warm standby server which is flipped into service if the active master server has an issue. at groupon, our standard mysql database configuration follows this active/passive pattern. there is a virtual ip that points to the active server of a pair. the passive server has mysqld running and replicating from the active master. in theory, failing over is the simple matter of moving the virtual ip. in practice, it’s slightly more complicated. to manage this process, we use a tool co-developed with percona.
“warm standby server”? did you catch that? what does that mean? in most of these high-availability solutions it means that mysqld is running on the standby server and that replication is not lagging. unfortunately, that’s often not sufficient for failover during peak traffic. the standby server does not process query traffic except for replication. the buffer pool and adaptive hash index on the standby server will not have recently accessed pages. when it starts handling queries after failover, the lower cache hit rates can lead to outages . specifically, at groupon, our servers would be heavily i/o bound after failover as the buffer pool pages were loaded from disk.
first, we set
to 0 in order to log every query. (see part two for handling massive slow log volume.) the slow logs are served, via http, by
. this daemon is similar to running
tail -f slow.log
, except that it knows how to follow the log stream across log rotation events. on the standby server, the logs are replayed with
by streaming the slow log from the active server.
wget -q -o - http://master_server:3307/slow | percona-playback --mysql-host 127.0.0.1 --mysql-username playback --mysql-password password --mysql-schema schema_name --query-log-stdin --dispatcher-plugin thread-pool --thread-pool-threads-count 100 --session-init-query \"set innodb_fake_changes=1\" > /var/log/playback.log 2>&1 &
our awesome development team added a few features to percona playback to make it work better for this use case. you will need version 0.6 or later to get these features. be aware that playback output is really verbose, in production, most likely you want it to redirect to /dev/null, and only have a log file for debugging purposes.
- streaming logs from stdin percona playback now supports the –query-log-stdin command-line option for accepting a never-ending stream of queries to playback.
- read-only playback using the –session-init-query command-line option, we set the option innodb_fake_changes to prevent inserts, updates, and deletes from corrupting the data on the standby server. you will need percona server in order to use innodb_fake_changes.
- thread pool percona playback added a connection pool option via –dispatcher-plugin-thread-pool that will allow connection reuse. this is necessary when running a large stream of queries.
we benchmarked with slow query logs captured from our production systems. we restored a production database backup to our test database so that our test database was consistent before applying the captured query traffic. this is an important step because update statements that match no rows or insert statements that have duplicate key errors may be faster than an actual database write.
the slow logs were split into chunks, each containing roughly 1m queries. we warmed the cold database with the first chunk and replayed the second chunk after the warmup.
the y axis is logarithmic, so the difference between the io usage is 2 orders of magnitude. all graphs looked like this (we did 39 measurements), the next graph shows chunk 4’s workload warmed up with chunk 3.
the result is similar for every single graph, each chunk warmed up the buffer pool for the next one.
as an additional experiment we tried replaying the same chunk again. we expected everything to be cached if we warmed the cache with the exact same data. all the graphs from such self-warming experiments look like this one. the green part of the graph lines up with the blue part.
check back thursday for part 2!
Published at DZone with permission of Peter Zaitsev, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.