字體:  

MySQL Tunning 效能分析工具

adj 發表於: 2008-3-11 11:54 來源: ADJ網路控股集團


要分析 MySQL 為何緩慢的工具還真不少, 上次用了 mysqlreport 後...又發現神秘好心人寫的
檔案下載:


tuning-primer.sh

基本上, 它是利用 MySQL 本身提供的訊息, 做點判斷, 同時提供一些建議.
以下是它執行產出的結果. 它建議 mysql 至少跑超過 48 小時之後, 收集的資訊跟建議會比較準確.

-- MYSQL PERFORMANCE TUNING PRIMER --
- By: Matthew Montgomery - MySQL Version 5.0.27-log x86_64 Uptime = 0 days 1 hrs 10 min 21 sec
Avg. qps = 73
Total Questions = 311395

Threads Connected = 83 Warning: Server has not been running for at least 48hrs.
It may not be safe to use these recommendations To find out more information on how each of these
runtime variables effects performance visit:
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html
Visit http://www.mysql.com/products/enterprise/advisors.html
for info about MySQL's Enterprise Monitoring and Advisory Service

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

WORKER THREADS
Current thread_cache_size = 16
Current threads_cached = 14
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 512
Current threads_connected = 83
Historic max_used_connections = 130
The number of used connections is 25% of the configured maximum.
Your max_connections variable seems to be fine.

MEMORY USAGE
Max Memory Ever Allocated : 4 G
Configured Max Per-thread Buffers : 14 G
Configured Max Global Buffers : 1 G
Configured Max Memory Limit : 15 G
Physical Memory : 1.96 G
Max memory limit exceeds 90% of physical memory

KEY BUFFER
Current MyISAM index space = 440 M
Current key_buffer_size = 768 M
Key cache miss rate is 1 : 507
Key buffer fill ratio = 5.00 %
Your key_buffer_size seems to be too high.
Perhaps you can use these resources elsewhere


QUERY CACHE
Query cache is enabled
Current query_cache_size = 256 M
Current query_cache_used = 10 M
Current query_cache_limit = 4 M
Current Query cache Memory fill ratio = 4.17 %
Current query_cache_min_res_unit = 2 K
Query Cache is 14 % 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.
Your query_cache_size seems to be too high.
Perhaps you can use these resources elsewhere

MySQL won't cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 16 M
Current record/read_rnd_buffer_size = 3 M
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 256.00 K
You have had 2 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 = 2570 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_cache value = 1024 tables
You have a total of 224 tables
You have 284 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 63 M
Current tmp_table_size = 64 M
Of 24475 temp tables, 60% were created on disk
Effective in-memory tmp_table_size is limited to max_heap_table_size.
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 = 7 M
Current table scan ratio = 37 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 1 : 2015
You may benefit from selective use of InnoDB.

From: http://www.mw.net.tw/user/chinian/blog/2008/02/01/110/77063/