MySQLTuner result and Tuning Primer result
My server eat up of high CPU resource. I’ve figure out by using
and found out that these results.
| 214024 | phpwind | localhost | phpwind | Query | 318 | Copying to tmp table | SELECT pt.tid,pt.fid,pt.subject,pa.attachurl FROM pw_threads pt
,pw_attachs pa,pw_forums pf where p |
| 214028 | _wp | localhost | _wp | Query | 315 | Sending data | SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND YEAR(wp_pos
| 214029 | phpwind | localhost | phpwind | Query | 318 | Locked | UPDATE LOW_PRIORITY pw_threads SET hits=hits+1 WHERE tid= '6424'
| 214030 | phpwind | localhost | phpwind | Query | 315 | Copying to tmp table | SELECT pt.tid,pt.fid,pt.subject,pa.attachurl FROM pw_threads pt
,pw_attachs pa,pw_forums pf where p |
| 214031 | phpwind | localhost | phpwind | Query | 307 | Locked | UPDATE LOW_PRIORITY pw_threads SET hits=hits+1 WHERE tid= '92850'
| 214035 | phpwind | localhost | phpwind | Query | 296 | Locked | UPDATE LOW_PRIORITY pw_threads SET hits=hits+1 WHERE tid= '69204'
I’m thinking the problem is cause by Copying to tmp table. After running this SQL, all other query after it has been Locked and wait the first query finish. If more and more query keep requesting, then it will take a lot of memory and resources.
I’m going to check how to optimize using MySQLTuner and Tuning Primer.
[root@server src]# ./mysqltuner.pl
>> MySQLTuner 1.1.1 - Major Hayden
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with '--help' for additional options and output filtering
-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.50-log
[OK] Operating on 32-bit architecture with less than 2GB RAM
-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 654M (Tables: 1682)
[--] Data in InnoDB tables: 43M (Tables: 132)
[--] Data in MEMORY tables: 0B (Tables: 5)
[!!] Total fragmented tables: 171
-------- Security Recommendations -------------------------------------------
[OK] All database users have passwords assigned
-------- Performance Metrics -------------------------------------------------
[--] Up for: 1d 22h 10m 51s (3M q [22.757 qps], 215K conn, TX: 11B, RX: 530M)
[--] Reads / Writes: 72% / 28%
[--] Total buffers: 416.0M global + 3.7M per thread (100 max threads)
[OK] Maximum possible memory usage: 784.8M (77% of installed RAM)
[OK] Slow queries: 0% (696/3M)
[!!] Highest connection usage: 100% (101/100)
[OK] Key buffer size / total MyISAM indexes: 128.0M/142.1M
[OK] Key buffer hit rate: 99.7% (142M cached / 404K reads)
[OK] Query cache efficiency: 61.2% (1M cached / 2M selects)
[!!] Query cache prunes per day: 66260
[OK] Sorts requiring temporary tables: 2% (1K temp sorts / 47K sorts)
[!!] Joins performed without indexes: 962
[!!] Temporary tables created on disk: 39% (11K on disk / 28K total)
[OK] Thread cache hit rate: 99% (101 created / 215K connections)
[!!] Table cache hit rate: 14% (2K open / 14K opened)
[OK] Open file limit used: 40% (3K/8K)
[OK] Table locks acquired immediately: 99% (1M immediate / 1M locks)
[!!] InnoDB data size / buffer pool: 43.6M/30.0M
-------- Recommendations -----------------------------------------------------
Run OPTIMIZE TABLE to defragment tables for better performance
Reduce or eliminate persistent connections to reduce connection usage
Adjust your join queries to always utilize indexes
When making adjustments, make tmp_table_size/max_heap_table_size equal
Reduce your SELECT DISTINCT queries without LIMIT clauses
Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
max_connections (> 100)
wait_timeout (< 15)
interactive_timeout (< 50) query_cache_size (> 128M)
join_buffer_size (> 512.0K, or always use indexes with joins)
tmp_table_size (> 128M)
max_heap_table_size (> 128M)
table_cache (> 2048)
innodb_buffer_pool_size (>= 43M)
Tuning Primer result
[root@server src]# ./tuning-primer.sh
-- MYSQL PERFORMANCE TUNING PRIMER --
- By: Matthew Montgomery -
MySQL Version 5.1.50-log i686
Uptime = 1 days 22 hrs 12 min 35 sec
Avg. qps = 22
Total Questions = 3786857
Threads Connected = 1
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:
for info about MySQL's Enterprise Monitoring and Advisory Service
The slow query log is enabled.
Current long_query_time = 10.000000 sec.
You have 697 out of 3786878 that take longer than 10.000000 sec. to complete
Your long_query_time seems to be fine
BINARY UPDATE LOG
The binary update log is NOT enabled.
You will not be able to do point in time recovery
Current thread_cache_size = 328
Current threads_cached = 100
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine
Current max_connections = 100
Current threads_connected = 1
Historic max_used_connections = 101
The number of used connections is 101% of the configured maximum.
You should raise max_connections
Current InnoDB index space = 11 M
Current InnoDB data space = 43 M
Current InnoDB buffer pool free = 0 %
Current innodb_buffer_pool_size = 30 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
Max Memory Ever Allocated : 660 M
Configured Max Per-thread Buffers : 368 M
Configured Max Global Buffers : 288 M
Configured Max Memory Limit : 656 M
Physical Memory : 1010 M
Max memory limit seem to be within acceptable norms
Current MyISAM index space = 142 M
Current key_buffer_size = 128 M
Key cache miss rate is 1 : 352
Key buffer free ratio = 58 %
Your key_buffer_size seems to be fine
Query cache is enabled
Current query_cache_size = 128 M
Current query_cache_used = 85 M
Current query_cache_limit = 2 M
Current Query cache Memory fill ratio = 66.51 %
Current query_cache_min_res_unit = 4 K
MySQL won't cache query results that are larger than query_cache_limit in size
Current sort_buffer_size = 1 M
Current read_rnd_buffer_size = 1 M
Sort buffer seems to be fine
Current join_buffer_size = 516.00 K
You have had 957 queries where a join could not use an index properly
You have had 6 joins without keys that check for key usage after each row
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 = 8192 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
Current table_open_cache = 2048 tables
Current table_definition_cache = 256 tables
You have a total of 1842 tables
You have 2048 open tables.
Current table_cache hit rate is 13%
, while 100% of your table cache is in use
You should probably increase your table_cache
You should probably increase your table_definition_cache value.
Current max_heap_table_size = 128 M
Current tmp_table_size = 128 M
Of 17279 temp tables, 39% 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.
Current read_buffer_size = 1 M
Current table scan ratio = 182 : 1
read_buffer_size seems to be fine
Current Lock Wait ratio = 1 : 384
You may benefit from selective use of InnoDB.
If you have long running SELECT's against MyISAM tables and perform
frequent updates consider setting 'low_priority_updates=1'
If you have a high concurrency of inserts on Dynamic row-length tables
consider setting 'concurrent_insert=2'.
I will try to tweak and test for few days, after I find the solution, I will post in here again.