- Apache (9)
- DNS / BIND (2)
- General Linux (7)
- Mail (8)
- Postfix (1)
- Qmail (4)
- Sendmail (3)
- MySQL (7)
- News (1)
- Other (2)
- Perl (1)
- PHP (5)
- Plesk (13)
- Redhat Linux (8)
- Ruby (1)
- Scripts (4)
- Security (4)
- iptables (2)
TopicNavigationUser login |
MySQL Performance TuningMatt Mongomery at MySQL has developed a great MySQL "tuning primer" that will suggest basic performance tuning settings. It is available at: http://www.day32.com/MySQL/tuning-primer.sh MySQL should be allowed at least 48 hours of normal operation before running, to allow for the best suggestions. Here is an example of real-world usage: [root@server1 root]# wget http://www.day32.com/MySQL/tuning-primer.sh
--20:41:15-- http://www.day32.com/MySQL/tuning-primer.sh
=> `tuning-primer.sh'
Resolving www.day32.com... 209.61.186.89
Connecting to www.day32.com|209.61.186.89|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 34,309 (34K) [application/x-sh]
100%[====================================>] 34,309 --.--K/s
20:41:15 (279.14 KB/s) - `tuning-primer.sh' saved [34309/34309]
[root@server1 root]# bash tuning-primer.sh
-- MYSQL PERFORMANCE TUNING PRIMER --
- By: Matthew Montgomery -
MySQL Version 3.23.58
Uptime = 23 days 21 hrs 28 min 54 sec
Avg. qps = 17
Total Questions = 36204146
Threads Connected = 5
Server has been running for over 48hrs.
It should be safe to follow these recommendations
To find out more information on how each of these
runtime variables effects performance visit:
http://dev.mysql.com/doc/refman/4.1/en/server-system-variables.html
SLOW QUERIES
Current long_query_time = 10 sec.
You have 526 out of 36204146 that take longer than 10 sec. to complete
The slow query log is NOT enabled.
Your long_query_time may be too high, I typically set this under 5 sec.
MAX CONNECTIONS
Current max_connections = 200
Current threads_connected = 5
Historic max_used_connections = 166
The number of used connections is 83% of the configured maximum.
Your max_connections variable seems to be fine.
WORKER THREADS
Current thread_cache_size = 0
Current threads_cached = 0
Current threads_per_sec = 1
Historic threads_per_sec = 0
Your thread_cache_size is fine
MEMORY USAGE
Max Memory Ever Allocated : 28 M
Configured Max Memory Limit : 30 M
Total System Memory : 2028 M
KEY BUFFER
Current MyISAM index space = 239 M
Current key_buffer_size = 7 M
Key cache miss rate is 1 / 126
Key buffer fill ratio = Unknown %
Your key_buffer_size seems to be fine
QUERY CACHE
You are using MySQL 3.23.58, no query cache is supported.
I recommend an upgrade to MySQL 4.0 or better
SORT OPERATIONS
Current sort_buffer_size = 2 M
Current record/read_rnd_buffer_size = 128.00 K
Sort buffer seems to be fine
JOINS
Current join_buffer_size = 128.00 K
You have had 108378 queries where a join could not use an index properly
You should enable "log-long-format"
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 accomidate larger joins in one pass.
TABLE CACHE
Current table_cache value = 64 tables
You have a total of 842 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
TEMP TABLES
Current tmp_table_size = 32 M
48% of tmp tables created were disk based
Perhaps you should increase your tmp_table_size
TABLE SCANS
Current read_buffer_size = 128.00 K
Current table scan ratio = 43 : 1
read_buffer_size seems to be fine
TABLE LOCKING
Current Lock Wait ratio = 1 : 3294
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'
[root@server1 root]# free -m
total used free shared buffers cached
Mem: 1001 881 119 0 81 548
-/+ buffers/cache: 252 749
Swap: 1027 58 969
As you can see, this server has plenty of free memory, so we are going to edit my.cnf with the suggested changes. First, we back up the old my.cnf: [root@server1 root]# cp -a /etc/my.cnf /etc/my.cnf.bak Old my.cnf: [mysqld] safe-show-database innodb_data_file_path=ibdata1:10M:autoextend datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock set-variable=max_connections=200 [mysql.server] user=mysql basedir=/var/lib [safe_mysqld] err-log=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid New my.cnf: [mysqld] safe-show-database innodb_data_file_path=ibdata1:10M:autoextend datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock set-variable=max_connections=200 set-variable=join_buffer_size=2M set-variable=table_cache=512 set-variable=tmp_table_size=64M [mysql.server] user=mysql basedir=/var/lib [safe_mysqld] err-log=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid Restart MySQL for the changes to take effect, and then rerun the script in a few days to determine if further tweaking is necessary. |
Linux JournalSlashdot |