简体   繁体   English

刷新InnoDB缓存

[英]Flush InnoDB cache

I have some reporting queries that are rarely run, which I need to be performant without relying on them being cached anywhere in the system. 我有一些很少运行的报告查询,我需要高性能,而不依赖于它们在系统中的任何位置缓存。 In testing various schema and sproc changes I'll typically see the first run be very slow and subsequent runs fast, so I know there's some caching going on that's making it cumbersome to test changes. 在测试各种模式和sproc更改时,我通常会看到第一次运行非常慢并且后续运行速度很快,所以我知道有一些缓存正在使测试更改变得很麻烦。 Restarting mysqld or running several other large queries are the only reliable ways to reproduce it. 重新启动mysqld或运行其他几个大型查询是重现它的唯一可靠方法。 I'm wondering if there's a better way. 我想知道是否有更好的方法。

The MySQL Query Cache is turned OFF. MySQL Query Cache已关闭。

Monitoring the disk, I don't see any reads happening except on the first run. 监视磁盘,除了第一次运行外,我没有看到任何读取。 I'm not that familiar with disk cache but I would expect if that's where the caching is happening I'd still see disk reads, they'd just be very fast. 我不熟悉磁盘缓存,但我希望如果这就是缓存发生的地方我仍然会看到磁盘读取,它们只是非常快。

MONyog gives me what I think is the definitive proof, which is the InnoDB cache hit ratio. MONyog给了我我认为最终的证据,即InnoDB缓存命中率。 Monitoring it I see that when the query's fast it's hitting the InnoDB buffer, when it's slow it's hitting disk. 监视它我看到当查询速度很快时它正在击中InnoDB缓冲区,当它缓慢时它正在击中磁盘。

On a live system I'll gladly let InnoDB do this, but for development and test purposes I'm interested in worst case scenarios. 在实时系统上,我很乐意让InnoDB这样做,但是出于开发和测试的目的,我对最坏的情况感兴趣。

I'm using MySQL 5.5 on Windows Server 2008R2 我在Windows Server 2008R2上使用MySQL 5.5

I found a post on the Percona blog that says: 在Percona博客上发了一篇帖子说:

For MySQL Caches you can restart MySQL and this is the only way to clean all of the caches. 对于MySQL缓存,您可以重新启动MySQL,这是清除所有缓存的唯一方法。 You can do FLUSH TABLES to clean MySQL table cache (but not Innodb table meta data) or you can do “set global key_buffer_size=0; 您可以使用FLUSH TABLES清理MySQL表缓存(但不是Innodb表元数据),或者可以执行“set global key_buffer_size = 0; set global key_buffer_size=DEFAULT” to zero out key buffer but there is no way to clean Innodb Buffer Pool without restart. 设置全局key_buffer_size = DEFAULT“将密钥缓冲区归零,但没有重启就无法清理Innodb缓冲池。

In the comments he goes on to say: 他在评论中继续说:

Practically everything has caches. 实际上一切都有缓存。 To do real profiling you need to profile real query mix which will have each query having appropriate cache/hit ratio not running one query in the loop and assuming results will be fine. 要进行真正的分析,您需要分析真实的查询混合,这将使每个查询具有适当的缓存/命中率,而不是在循环中运行一个查询并假设结果会很好。

I guess that sums it up. 我想总结一下。 It does make it hard to test individual queries. 它确实使测试单个查询变得困难。 My case is that I want to try forcing different indices to make sure the query planner is picking the right one, and apparently I'll have to restart MySQL between tests to take the cache out of the equation! 我的情况是,我想尝试强制不同的索引,以确保查询规划器正在选择正确的,并且显然我将不得不在测试之间重新启动MySQL以使缓存脱离等式!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM