Hot Table, Cold Disk: Learning to Read the InnoDB Buffer Pool

The complaint had an odd regularity to it: every morning between 06:00 and 06:40 the application slowed down, then recovered on its own. During the day, p95 latency was 80 milliseconds; in that window it climbed to 900 milliseconds. The first suspects were the scheduled jobs running at that hour. We turned them off one by one, and the slowdown stayed put. The second suspect was morning traffic, but traffic peaked at 08:00 while the problem ended at 06:40. The culprit was hiding in the night: the database backup that started at 02:00 and finished at 05:50.

If the backup's CPU and IO load was over by morning, what could it possibly have to do with the morning slowdown? The connection was memory. As mysqldump read every table from start to finish, it had pushed the hot pages out of the InnoDB buffer pool, meaning the index and data pages that daytime traffic touched constantly. When the first users of the morning arrived, everything that had been in memory the evening before was now on disk. The 06:00-06:40 window was simply the time it took the pool to warm up again.

The Deceptive Decimals of Hit Ratio

What clinched the diagnosis was the buffer pool metrics, and the first lesson we learned here is about scale. Innodb_buffer_pool_read_requests counts total page requests, and Innodb_buffer_pool_reads counts the ones among them that had to go to disk. Our daytime ratio was 99.97 percent; in the problem window it dropped to 98.9. Both numbers read as "around 99, perfectly fine." Yet the difference between them means disk reads went up 35-fold. That week we learned to judge buffer pool health not by the hit ratio percentage but by physical reads per second: for us, normal operation meant 60 physical reads per second, and during the warm-up window that shot up to 2,100. Once we put that metric on the graph, the problem became visible to the naked eye.

A drop in hit ratio from 99.97 to 98.9 percent looks harmless; the physical read count clearly shows the jump from 60 to 2,100.
Pool health was judged by physical read count, not by percentage.

InnoDB Actually Knows About This Attack

Interestingly, InnoDB has a defense built for exactly this scenario. The buffer pool LRU list is split in two: a young (hot) region and an old region. A new page read from disk first enters the old region, and to be promoted to the young region it has to be touched a second time after innodb_old_blocks_time (1 second by default) has passed. This way, single-pass scan traffic flows through the old region without ever contaminating the hot region. So why didn't it work for us? Scale: the backup runs for three hours and 50 minutes, and the enormous volume passing through the old region during that time kept churning the pool's 37 percent old share, so the warm pages waiting in the old region got swept away in the flood of the scan as well. The defense mechanism had proven partly inadequate against the sheer size of the siege.

A page read from disk enters the old region and is promoted to the young region on a second touch; during the long backup scan this defense was not enough.
The three-hour-50-minute backup kept churning the old region.

Even after we'd made the connection, a verification step was needed; correlation isn't causation. We gathered the evidence with a cheap experiment: we deliberately skipped the backup one night, and the 06:00 window the next morning went by perfectly clean. The following night the backup came back, and so did the slowdown. That two-night experiment put a definitive end to a "maybe it's something else" debate that could have dragged on for weeks. Experimenting in production often gets described as reckless, yet as long as it's controlled, reversible and changes a single variable, it's the most honest diagnostic tool there is.

A Three-Move Fix

The first move is the cleanest: we stopped taking the backup from the master. Backups are now taken from a replica. Who cares if the replica goes cold until morning? Its buffer pool doesn't carry user traffic. The second move was the buffer pool size. The server had 32 GB of RAM, but the pool sat at 12 GB, a setting left over from years ago when the machine handled other jobs too. We measured our active data set (frequently touched tables and indexes came to about 19 GB) and raised the pool to 24 GB. The third move is small but elegant: the innodb_buffer_pool_dump_at_shutdown and load_at_startup settings. MySQL now writes the list of hot pages to disk when it shuts down and loads the same list back when it starts. The warm-up pain after maintenance restarts, that sluggish period that used to last half an hour, dropped to a few minutes.

While growing the buffer pool, we learned two more details, and neither is as simple as "just make it bigger." First, a bigger pool isn't free: InnoDB's page scanning and cleanup work grows with the pool size, and although the size can be changed online since 5.7, brief stalls can occur during the change, so we still scheduled the operation for a low-traffic hour. Second, the multiple buffer pool instances setting: we split the 24 GB pool into 8 instances to reduce mutex contention under concurrent access. We measured the effect of this setting in a synthetic test and saw a 6-8 percent improvement at high concurrency. Not dramatic, but free. On the dirty page side, rather than fiddling with innodb_max_dirty_pages_pct, increasing the redo log size helped more; once checkpoint pressure eased, the write spikes smoothed out.

We also used the occasion to change our backup method. mysqldump's problem isn't only that it washes out the pool; because it's a logical backup, restoring from it also takes hours. We moved to xtrabackup on the replica: it makes a physical copy, barely touches the buffer pool, and restoring is as fast as putting the files back in place. To actually measure restore time, we ran a drill: going from a 300 GB backup to a fully functional server takes 40 minutes. Knowing that number is the difference between panic and a plan on any crisis night.

The backup was moved to a replica, the pool was enlarged, the dump and load settings were enabled and the backup method was switched to xtrabackup.
Measuring restore time with a drill gives you a plan in a crisis.

Wiring the Pool to the Dashboard

The measurement we used to size the pool also deserves a sentence: the 19 GB we call the "active data set" isn't the sum of table sizes but the sum of the pages actually touched over a week. Total data was over 300 GB; trying to fit all of it in memory would have been both impossible and unnecessary. Memory planning is driven by access patterns, not by data volume.

After this case, the buffer pool stopped being a "set it and forget it" setting and became an indicator we watch all the time. The dashboard now has four curves: physical reads per second, the young/old region promotion rate, free list length and dirty page percentage. Every odd movement in these curves tells a story. Once, we saw physical reads climbing around noon for no apparent reason; tracing it, we found that a newly added report was doing a full scan on an unindexed column and washing out the pool every time it ran. The query was caught and fixed before anyone had complained. Finding a problem before the slowness complaints arrive is one of the rare pleasures of this profession.

A note, by the way, for anyone curious about the forensic side: you can see how much space each table takes up in the pool through information_schema.innodb_buffer_page. The query itself is expensive on large pools and isn't something to run often in production, but even a single weekly snapshot tells you a lot. Our first snapshot was embarrassing: 11 percent of the pool was taken up by the index of an old notification log table nobody had queried in two years, a table that a nightly job was scanning for no reason. The job was fixed, the table was archived, and 2.6 GB of memory went back to genuinely hot data. Memory collects junk just like disk does; you need to take inventory every so often.

If I had to sum it up: your database's real performance limit is often not the speed of the disk but what memory remembers. And the things that change what memory remembers (backups, migrations, full scans, restarts) mostly don't show up in query statistics, because the damage isn't suffered by them but by whatever comes after them. If you have a system that slows down every morning for no apparent reason, look at who washed out the memory overnight. If you can't find it, write to me and we'll look together.