The Tuning Primer is a shell script that allows you to review the MySQL settings and make adjustments to increase Magento database performance and stability. The script will analyze MySQL statistics and provide you with recommendations on how to fine-tune your MySQL server.
The uptime of your MySQL should be more than 48 hours for correct script work. Only in this case there will be enough information for analysis. Tuning Primer script is compatible with all versions of MySQL starting from 3.23.
What settings could be fine-tuned using the Tuning Primer script
Currently the script handles recommendations for the following:
- Slow Query Log
- Max Connections
- Worker Threads
- Memory Usage
- Key Buffer
- Query Cache
- Sort Buffer
- Temp Tables
- Table (Open & Definition) Cache
- Table Scans (read_buffer)
- Table Locking
- Innodb Status
How to speed up your Magento database using the Tuning Primer shell script
2 - Upload it to your server and execute it using SSH console:
3 - Script will ask MySQL login and password. Enter MySQL access from your Magento store (you can find it in Magento configuration file: /app/etc/local.xml).
4 - After script execution it will show you optimization recommendations. Here is a real script output for a Magento installation on dedicated server:
MySQL Version 5.X.XX-community i686
Uptime = 3 days 20 hrs 50 min 1 sec
Server has been running for over 48hrs. It should be safe to follow these recommendations
The slow query log is NOT enabled.
Current long_query_time = 10 sec.
You have 53 out of 20231077 that take longer than 10 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 = 8
Current threads_cached = 6
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine
Current max_connections = 500
Current threads_connected = 2
Historic max_used_connections = 69
The number of used connections is 13% of the configured maximum.
Your max_connections variable seems to be fine.
Current InnoDB index space = 279 M
Current InnoDB data space = 2.47 G
Current InnoDB buffer pool free = 0 %
Current innodb_buffer_pool_size = 8 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 : 227 M
Configured Max Per-thread Buffers : 1.31 G
Configured Max Global Buffers : 42 M
Configured Max Memory Limit : 1.35 G
Physical Memory : 23.58 G
Max memory limit seem to be within acceptable norms
Current MyISAM index space = 10 M
Current key_buffer_size = 16 M
Key cache miss rate is 1 : 13
Key buffer free ratio = 81 %
Your key_buffer_size seems to be fine
Query cache is enabled
Current query_cache_size = 16 M
Current query_cache_used = 15 M
Current query_cache_limit = 1 M
Current Query cache Memory fill ratio = 96.30 %
Current query_cache_min_res_unit = 4 K
However, 2878688 queries have been removed from the query cache due to lack of memory
Perhaps you should raise query_cache_size MySQL won't cache query results that are larger than query_cache_limit in size
Current sort_buffer_size = 2 M
Current read_rnd_buffer_size = 256 K
Sort buffer seems to be fine
Current join_buffer_size = 132.00 K
You have had 36574 queries where a join could not use an index properly
You have had 16 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.
OPEN FILES LIMIT
Current open_files_limit = 2500 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 = 64 tables
Current table_definition_cache = 256 tables
You have a total of 330 tables
You have 64 open tables.
Current table_cache hit rate is 0%, 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 = 16 M
Current tmp_table_size = 16 M
Of 1392672 temp tables, 23% were created on disk
Created disk tmp tables ratio seems fine
Current read_buffer_size = 128 K
Current table scan ratio = 527 : 1
read_buffer_size seems to be fine
Current Lock Wait ratio = 1 : 638404
Your table locking seems to be fine
After this you will need to change your MySQL configuration file (my.cnf) according to Tuning script recommendations and restart MySQL engine:
New MySQL fine-tuned settings will be activated after MySQL server restart.