MySQL table_cache and Opened_tables
http://dba.stackexchange.com/questions/5232/mysql-table-cache-and-opened-tables
MySQL table_cache and Opened_tables
I have seen people use the comparison of Open_tables and Opened_tables to assess whether the table_cache is too small in MySQL. However, I believe that Opened_tables is cumulative across uptime, so this is not a valid comparison. The only caveat being that perhaps Opened_tables is only bumped on misses - although even then if the tables being opened per second is still small, it's probably not a problem for it to grow gradually. If comparing Open_tables to Opened_tables is not valid, is there another way to get measured data for this? This is on MySQL 5.0, but differences between version are welcome too. |
|||
feedback
|
The biggest reason to have a large table_cache is so that LOCK_open mutex is not hot. MySQL prior to 5.5 has a lot of contention when you are trying to open/close tables, so you want to restrict doing this as much as possible, i.e. have a large table cache. So you don't care about any particular ratio of hits to misses (infact you should ignore ratios altogether - this blog post explains why). What you care about is the miss rate, because the more times this happens per second, the higher the chance that you will have contention (one thread has to wait for another thread to release the lock.) How do you spot the miss rate? You fetch a few samples of Opened_Tables a few seconds apart during the busiest period of the day, and if there are increases in each sample, it's probably a good idea to see if you can bump up the table_cache. Note: I very specifically do not recommend comparing to uptime. |
|||
feedback
|
From one of the user comments on the table_cache documentation page:
Meaning that it is incremented when you go over your A couple caveats to mention:
|
|||
feedback
|
First, let's consider those status variables: Open tables : The number of tables that are open. Opened_tables : The number of tables that have been opened. If Opened_tables is big, your table_open_cache value is probably too small. Surprisingly, the answer to your question lies within the question itself. The two variables would only make more sense if you throw one more status variable into the mix : Uptime (or Uptime_since_flush status for fresh averages after FLUSH STATUS). You should be comparing Open_tables agsinst (Opened_tables / Uptime). If Open_tables climbs above (Opened_tables / Uptime), now you have cause for concern and should keep an eye open for things like the following:
UPDATE 2011-08-31 12:18 EDT Please note why I also suggested using Uptime_since_flush_status instead of Uptime to get a fix Opened_tables pattern of growth for a given period. For example, if you run
This open table factor amounts to the number that represent the number of open tables at any given moment against the average number of opened tables throughtout a given period. With a Here is a sample out from one of my employer's clients:
This client normally maintains about 7745 OpenTableFactor at max. If OpenTableFactor drops suddenly (even if a little), it could indicate lower traffic patterns, high aborted conenctions, and so forth. If OpenTableFactor never changes (even if a little), it could present you with an opportunity to change these settings: Once adjusted, the OpenTableFactor may change constantly or hit another ceiling or plateau. Thus, using different units within the status variables becomes vital for this kind of tuning. UPDATE 2011-08-31 12:42 EDT The SQL query I ran for the OpenTableFactor does not works for MySQL 5.0 and back. If you are using MySQL Administrator or MONyog, you could customize a graph using the formula in the query and monitor. MONyog collects the history using SQLLite for later historical graphing. This can be done for any version of MySQL. |
||||
|