Question :
We are an email marketing company and we recently switched our setup to MySQL. We need to configure MySQL (my.cnf) for extreme performance.
We have tried to configure my.cnf but heavy queries got stuck for many hours without any result. Some queries take one or two hours to complete on our SQL server (8GB RAM).
It’s a dedicated MySQL server.
OS = Ubuntu
Installed RAM = 512GB
Table type = MyISAM
We have very large tables (a few tables having more then 70 million rows). Almost every time new tables to match so indexes won’t help that much, although the necessary indexes exist.
We do not have any application to connect our database, just 2 users who write adhoc queries directly.
Below are some variables we have changed from the default values.
key_buffer_size = 250G
read_buffer_size = 2G
read_rnd_buffer_size = 50M
join_buffer_size = 25M
tmp_table_size = 5G
sort_buffer_size = 2G
innodb_buffer_pool_size = 2G
query_cache_limit = 10M
query_cache_size = 100M
max_connections = 20
Below is the MySQLTuner recommendation:
-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.5.29-0ubuntu0.12.04.2
[OK] Operating on 64-bit architecture
-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 1909G (Tables: 940)
[--] Data in InnoDB tables: 2G (Tables: 3)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[!!] Total fragmented tables: 3
-------- Performance Metrics -------------------------------------------------
[--] Up for: 6m 59s (9 q [0.021 qps], 6 conn, TX: 10K, RX: 625)
[--] Reads / Writes: 100% / 0%
[--] Total buffers: 252.1G global + 4.1G per thread (20 max threads)
[OK] Maximum possible memory usage: 333.6G (66% of installed RAM)
[OK] Slow queries: 0% (0/9)
[OK] Highest usage of available connections: 5% (1/20)
[OK] Key buffer size / total MyISAM indexes: 250.0G/131.6G
[!!] Query cache efficiency: 0.0% (0 cached / 4 selects)
[OK] Query cache prunes per day: 0
[OK] Temporary tables created on disk: 0% (0 on disk / 2 total)
[OK] Thread cache hit rate: 83% (1 created / 6 connections)
[OK] Table cache hit rate: 78% (26 open / 33 opened)
[OK] Open file limit used: 1% (18/1K)
[OK] Table locks acquired immediately: 100% (36 immediate / 36 locks)
[!!] Connections aborted: 16%
[!!] InnoDB data size / buffer pool: 2.2G/2.0G
-------- Recommendations -----------------------------------------------------
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
MySQL started within last 24 hours - recommendations may be inaccurate
Enable the slow query log to troubleshoot bad queries
Your applications are not closing MySQL connections properly
Variables to adjust:
query_cache_limit (> 10M, or use smaller result sets)
innodb_buffer_pool_size (>= 2G)
Any help would be greatly appreciated.
Answer :
Look at this line
[OK] Key buffer size / total MyISAM indexes: 250.0G/131.6G
The sum of all your MyISAM indexes is 131.6G
You should lower key_buffer_size to 140G. This will give back 110G.
I have a little suggestion for you. You may want to consider using a dedicate keycache for each large table. See my Nov 16, 2012
post Cache all mysql table
Look at this line
[!!] InnoDB data size / buffer pool: 2.2G/2.0G
innodb_buffer_pool_size could be raised to 2560M (That’s 2.5G)
Look at these lines
read_buffer_size=2G
sort_buffer_size = 2G
Why is so big? If you change both of these to 32M, you can increase max_connections. In fact, do the following right now:
SET @ThrityTwoMeg = 1024 * 1024 * 32
SET GLOBAL read_buffer_size = @ThrityTwoMeg;
SET GLOBAL sort_buffer_size = @ThrityTwoMeg;
SET GLOBAL join_buffer_size = @ThrityTwoMeg;
Then, go rerun mysqltuner.pl
and you will see a dramatic difference from 4.1G per thread
BTW go change join_buffer_size
to 32M in my.cnf
Give it a Try !!!
UPDATE 2013-04-11 16:53 EDT
I just thought of another change you can make to increase SELECT speed against MyISAM tables. For every MyISAM you need to read a lot from, do this to the table:
ALTER TABLE mydb.mytable ROW_FORMAT=Fixed;
Believe it or not, this will bloat the table 80-100% in size, but SELECTs will go 20-25% faster. I have written about this many times. Here is just few of my posts: