Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. Restarting mysqld or running several other large queries are the only reliable ways to reproduce it. I'm wondering if there's a better way.

The MySQL Query Cache is turned OFF.

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. Monitoring it I see that when the query's fast it's hitting the InnoDB buffer, when it's slow it's hitting disk.

On a live system I'll gladly let InnoDB do this, but for development and test purposes I'm interested in worst case scenarios.

I'm using MySQL 5.5 on Windows Server 2008R2

like image 916
Eric McNeill Avatar asked Sep 10 '11 17:09

Eric McNeill


People also ask

What is InnoDB flush?

InnoDB flushing mechanism FSYNC: Data and log files are opened with no options, and the fsyncsystem call is used when the engine requires flushing the data and log files. This option causes double buffering: page cache.

How do I flush MySQL query cache?

You can defragment the query cache to better utilize its memory with the FLUSH QUERY CACHE statement. The statement does not remove any queries from the cache. The RESET QUERY CACHE statement removes all query results from the query cache. The FLUSH TABLES statement also does this.

What is Mysqladmin flush hosts?

Unblock with mysqladmin flush hosts" is a database side error and occurs due to multiple connections created while connecting the database. To resolve the above error, you need to execute "Flush hosts " command. You can execute the command as per below syntax.


1 Answers

I found a post on the Percona blog that says:

For MySQL Caches you can restart MySQL and this is the only way to clean all of the caches. 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; set global key_buffer_size=DEFAULT” to zero out key buffer but there is no way to clean Innodb Buffer Pool without restart.

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!

like image 184
spieden Avatar answered Sep 28 '22 07:09

spieden