Mysql Optimization – table_open_cache, query_cache

MySQLoptimization

I have already optimize many times my Mysql server but now I want to have your advices.

mysqltuner:

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.52-log
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster 
[--] Data in MyISAM tables: 26G (Tables: 36)
[--] Data in InnoDB tables: 221M (Tables: 35)
[!!] Total fragmented tables: 41

-------- Security Recommendations  -------------------------------------------
[!!] User '@localhost' has no password set.

-------- Performance Metrics -------------------------------------------------
[--] Up for: 78d 11h 57m 53s (1B q [151.485 qps], 1M conn, TX: 336B, RX: 218B)
[--] Reads / Writes: 60% / 40%
[--] Total buffers: 2.2G global + 8.2M per thread (300 max threads)
[OK] Maximum possible memory usage: 4.6G (39% of installed RAM)
[OK] Slow queries: 0% (55K/1B)
[OK] Highest usage of available connections: 69% (209/300)
[OK] Key buffer size / total MyISAM indexes: 2.0G/6.1G
[OK] Key buffer hit rate: 98.2% (2B cached / 47M reads)
[OK] Query cache efficiency: 28.9% (79M cached / 276M selects)
[!!] Query cache prunes per day: 102031
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 3M sorts)
[OK] Temporary tables created on disk: 25% (1M on disk / 3M total)
[OK] Thread cache hit rate: 98% (16K created / 1M connections)
[!!] Table cache hit rate: 7% (330 open / 4K opened)
[OK] Open file limit used: 14% (149/1K)
[OK] Table locks acquired immediately: 99% (489M immediate / 490M locks)
[!!] InnoDB data size / buffer pool: 221.3M/128.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
    query_cache_size (> 20M)
    table_cache (> 400)
    innodb_buffer_pool_size (>= 221M)

tuning-primer:

SLOW QUERIES
The slow query log is enabled.
Current long_query_time = 1.000000 sec.
You have 56239 out of 1027500028 that take longer than 1.000000 sec. to complete
Your long_query_time seems to be fine

BINARY UPDATE LOG
The binary update log is enabled
Binlog sync is not enabled, you could loose binlog records during a server crash

WORKER THREADS
Current thread_cache_size = 10
Current threads_cached = 7
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 300
Current threads_connected = 26
Historic max_used_connections = 209
The number of used connections is 69% of the configured maximum.
Your max_connections variable seems to be fine.

INNODB STATUS
Current InnoDB index space = 28 M
Current InnoDB data space = 221 M
Current InnoDB buffer pool free = 0 %
Current innodb_buffer_pool_size = 128 M
Depending on how much space your innodb indexes take up it may be safe
to increase this value to up to 2 / 3 of total system memory

MEMORY USAGE
Max Memory Ever Allocated : 3.78 G
Configured Max Per-thread Buffers : 2.42 G
Configured Max Global Buffers : 2.09 G
Configured Max Memory Limit : 4.52 G
Physical Memory : 11.73 G
Max memory limit seem to be within acceptable norms

KEY BUFFER
Current MyISAM index space = 6.09 G
Current key_buffer_size = 1.95 G
Key cache miss rate is 1 : 54
Key buffer free ratio = 0 %
You could increase key_buffer_size
It is safe to raise this up to 1/4 of total system memory;
assuming this is a dedicated database server.

QUERY CACHE
Query cache is enabled
Current query_cache_size = 20 M
Current query_cache_used = 6 M
Current query_cache_limit = 4 M
Current Query cache Memory fill ratio = 33.45 %
Current query_cache_min_res_unit = 4 K
Query Cache is 30 % fragmented
Run "FLUSH QUERY CACHE" periodically to defragment the query cache memory
If you have many small queries lower 'query_cache_min_res_unit' to reduce fragmentation.
MySQL won't cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 2 M
Current read_rnd_buffer_size = 2 M
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 2.00 M
You have had 12284 queries where a join could not use an index properly
You should enable "log-queries-not-using-indexes"
Then look for non indexed joins in the slow query log.
If you are unable to optimize your queries you may want to increase your
join_buffer_size to accommodate larger joins in one pass.

Note! This script will still suggest raising the join_buffer_size when
ANY joins not using indexes are found.

OPEN FILES LIMIT
Current open_files_limit = 1024 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
Your open_files_limit value seems to be fine

TABLE CACHE
Current table_open_cache = 400 tables
Current table_definition_cache = 256 tables
You have a total of 94 tables
You have 330 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 128 M
Current tmp_table_size = 128 M
Of 2988791 temp tables, 25% were created on disk
Perhaps you should increase your tmp_table_size and/or max_heap_table_size
to reduce the number of disk-based temporary tables
Note! BLOB and TEXT columns are not allow in memory tables.
If you are using these columns raising these values might not impact your 
ratio of on disk temp tables.

TABLE SCANS
Current read_buffer_size = 2 M
Current table scan ratio = 5 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 1 : 5129
Your table locking seems to be fine

And memory infos:

[air@prod01 ~]$ free -m
         total       used       free     shared    buffers     cached
Mem:         12011      11926         85          0        406       6395
-/+ buffers/cache:       5123       6887
Swap:         1027          0       1027

query infos:

mysql>  show status like "Qc_%";
+-------------------------+-----------+
| Variable_name           | Value     |
+-------------------------+-----------+
| Qcache_free_blocks      | 3447      |
| Qcache_free_memory      | 13968768  |
| Qcache_hits             | 79867788  |
| Qcache_inserts          | 163036705 |
| Qcache_lowmem_prunes    | 8012726   |
| Qcache_not_cached       | 33127499  |
| Qcache_queries_in_cache | 3758      |
| Qcache_total_blocks     | 11259     |
+-------------------------+-----------+

I have increase table_open_cache value at 330 to 400.

Should I do something in order to have some better performances ?

Thanks

Best Answer

The first step you should do is to install some performance graphing software and start using it to graph your server's vital statistics.

One of these two will do the job: Better Cacti Templates or Appaloosa Zabbix Templates

Once that is in place and you can see what your normal workload looks like, then start changing values and seeing what difference they make.

If you aren't measuring your performance, any changes you make are little more than guessing.