Author Topic: Tuning a MySQL Server  (Read 3562 times)

0 Members and 1 Guest are viewing this topic.

Offline Mad Penguin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1420
  • Karma: 10018
  • Gender: Male
    • View Profile
    • Linux in the UK
    • Awards
Tuning a MySQL Server
« on: March 29, 2010, 09:29:19 pm »
I think many people simply install MySQL and let it run with whatever application they've installed it 'for' and don't think twice about it. (I know I have in the past) What's not obvious is how much difference a little tweaking can make to your performance. A little tuning can easily double or triple the speed of applications like Sugar, Wordpress or SMF for example.

Trouble is, MySQL is pretty complex and the number of parameters that 'can' be tweaked is HUGE, so where does one start?!  I've attached a script I came across recently which is solid gold for anyone new(ish) to MySQL, just download it and run it with;
Code: [Select]
sh ./tuning-primer.sh
And follow it's recommendations where appropriate!

Here's the output from a fairly well tuned server, just to give you an idea.

root@sqla:~# ./tuning-primer.sh
 
   -- MYSQL PERFORMANCE TUNING PRIMER --
        - By: Matthew Montgomery -

MySQL Version 5.1.37-1ubuntu5-log x86_64

Uptime = 4 days 4 hrs 42 min 59 sec
Avg. qps = 2
Total Questions = 949761
Threads Connected = 18

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/5.1/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
The slow query log is enabled.
Current long_query_time = 2.000000 sec.
You have 1490 out of 949782 that take longer than 2.000000 sec. to complete
Your long_query_time seems to be fine

BINARY UPDATE LOG
The binary update log is enabled
Binlog sync is not enabled, you could loose binlog records during a server crash

WORKER THREADS
Current thread_cache_size = 4
Current threads_cached = 1
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 256
Current threads_connected = 18
Historic max_used_connections = 39
The number of used connections is 15% of the configured maximum.
Your max_connections variable seems to be fine.

INNODB STATUS
Current InnoDB index space = 136 M
Current InnoDB data space = 553 M
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

MEMORY USAGE
Max Memory Ever Allocated : 558 M
Configured Max Per-thread Buffers : 791 M
Configured Max Global Buffers : 438 M
Configured Max Memory Limit : 1.20 G
Physical Memory : 990 M

nMax memory limit exceeds 90% of physical memory

KEY BUFFER
Current MyISAM index space = 126 M
Current key_buffer_size = 300 M
Key cache miss rate is 1 : 339
Key buffer free ratio = 75 %
Your key_buffer_size seems to be fine

QUERY CACHE
Query cache is enabled
Current query_cache_size = 128 M
Current query_cache_used = 46 M
Current query_cache_limit = 8 M
Current Query cache Memory fill ratio = 36.20 %
Current query_cache_min_res_unit = 4 K
MySQL won't cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 2 M
Current read_rnd_buffer_size = 256 K
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 516.00 K
You have had 3 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 = 3266 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_open_cache = 1500 tables
Current table_definition_cache = 1500 tables
You have a total of 1006 tables
You have 1022 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 128 M
Current tmp_table_size = 128 M
Of 80944 temp tables, 5% were created on disk
Created disk tmp tables ratio seems fine

TABLE SCANS
Current read_buffer_size = 128 K
Current table scan ratio = 351 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 0 : 950062
Your table locking seems to be fine


 


SimplePortal 2.3.3 © 2008-2010, SimplePortal