6

I've been working on optimizing my site and databases, and I have been using mysqltuner.pl to help with this. I've gotten just about everything correct, except for the table cache hit rate, no matter how high I raise it in my.cnf, I am still hitting about 0% (284 open / 79k opened).

My problem is that I don't really understand exactly what affects this so I don't really know what to look for in my queries/database structure to fix this.

2 Answers 2

7

The table cache defines the number of simultaneous file descriptors that MySQL has open. So table cache hit rate will be affected by how many tables you have relative to your limit as well as how frequently you re-reference tables (keeping in mind that it is counting not just a single connection, but simultaneous connections)

For instance, if your limit is 100 and you have 101 tables and you query each one in order, you'll never get any table cache hits. On the other hand, if you only have 1 table, you should generally get close to 100% hit rate unless you run FLUSH TABLES a lot ( as long as your table_cache is set higher than the number of typically simultaneous connections).

So for tuning, you need to look at how many distinct tables you might reference by one process/client and then look at how many simultaneous connections you might typically have.

Without more details, I can't guess whether your case is due to too many simultaneous connections or too many frequently referenced tables.

2
  • Ok, so, I have a maximum of 1000 connections on my server, with 6 tables. Does that mean I need 6000 in my table cache conf? Nov 6, 2010 at 9:41
  • 1
    Just to be clear, its not the number of tables on the server but the number of tables in a query (due to joins/subqueries/etc). So if you have a query that uses 6 tables and you at least occasionally hit 1000 simultaneous connections then 6000 is not unreasonable. However, if 1000 is your max but you rarely go above 500 and the biggest query only touches 3 out of 6 tables, then 1500 should be sufficient. Nov 6, 2010 at 20:37
3

A cache is supposed to maintain copies of hot data. Hot data is data that is used a lot. If you cannot retrieve data out of a certain cache it means the DB has to go to disk to retrieve it.

--edit--

sorry if the definition seemed a bit obnoxious. a specific cache often covers a lot of entities, and these are database specific, you need to find out what is cached by the table cache firstly.

--edit: some investigation --

Ok, it seems (from the reply to this post), that Mysql uses the table cache for the data structures used to represent a table. the data structures also (via encapsulation or by having duplicate table entries for each table) represent a set of file descriptors open for the data files on the file system. The MyIsam engine uses one for a table and one for each index, additionally each active query element requires its own descriptors.

A file descriptor is a kernel entity used for file IO, it represents the low-level context of a particular file read or write.

I think you are either interpreting the value's incorrectly or they need to be interpreted differently in this context. 284 is the amount of active tables at the instance you took the snapshot and the second value represents the amount of times a table was acquired since you started Mysql.

I would hazard a guess that you need to take multiple snapshots of this reading and see if the first value (active fd's at that instance) ever exceed your cache size capacity.

p.s., the kernel generally has a upper limit on the amount of file descriptors it will allow each process to open -- so you might need to tune this if it is too low.

2
  • Right but what am I looking for to improve this? The query cache hit rate is around 50%, so what causes the table cache hit rate to be non-existant? Dec 25, 2009 at 19:29
  • I hope the answer satisfies :D Dec 26, 2009 at 1:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.