MySQL Performance Tuning

Aus Wiki Thomas-Krenn.AG
Wechseln zu: Navigation, Suche

Dieser Artikel beschäftigt sich mit verschiedenen Möglichkeiten, wie die Performance eines MySQL-Servers analysiert und optimiert werden kann. Es werden sowohl Tipps bezüglich Literatur als auch verschiedene Tools vorgestellt.

Inhaltsverzeichnis

Theorie

MySQL Training/Zertifizierung

Von MySQL werden verschiedene Trainings angeboten, welche auch mit einer Zertifizierung/Prüfung abgeschlossen werden können.

Folgende Trainings werden unter anderem angeboten:

Alle Infos zu den aktuellen Traninings finden Sie hier: http://www.mysql.com/training

Literatur

Monitoring Software

Hier ein Beispiel Graph von der Mysql Cacti Auswertung:

Mysql-cacti-graph.png

Tuning Tools

mysqltuner.pl

Dieses Perl Skript ermöglicht schnell und einfach einen Überblick über den Zustand des MySQL Server zu erhalten. Im Bereich Recommendations des Skript-Outputs bekommen Sie wertvolle Hinweise wie Sie mit einfachen Konfigurationsverbesserungen die Performance Ihres MySQL Servers steigern.

Es kann ganz einfach in zwei Schritten ausgeführt werden.

Zuerst muss die aktuelle Version mit wget heruntergeladen werden:

server:~# wget http://mysqltuner.pl

Alternativ kann mysqltuner unter Ubuntu und Debian auch direkt aus dem Repository installiert werden:

server:~# apt-get install mysqltuner

Danach wird der MySQL-Tuner gestartet, wobei eventuell MySQL Login Daten eingegeben werden müssen.

Hier ein Beispiel-Output eines nicht weiter optimierten MySQL Servers:

server:~# perl mysqltuner.pl 

 >>  MySQLTuner 1.0.1 - Major Hayden <major@mhtx.net>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering
Please enter your MySQL administrative login: root
Please enter your MySQL administrative password: XXXXXXXX

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.0.51a-24+lenny2+spu1
[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: 1M (Tables: 26)
[--] Data in InnoDB tables: 22M (Tables: 39)
[--] Data in MEMORY tables: 0B (Tables: 1)
[!!] Total fragmented tables: 10

-------- Performance Metrics -------------------------------------------------
[--] Up for: 11d 16h 28m 56s (8M q [8.714 qps], 597K conn, TX: 2B, RX: 1B)
[--] Reads / Writes: 93% / 7%
[--] Total buffers: 58.0M global + 2.6M per thread (100 max threads)
[OK] Maximum possible memory usage: 320.5M (15% of installed RAM)
[OK] Slow queries: 0% (0/8M)
[OK] Highest usage of available connections: 19% (19/100)
[OK] Key buffer size / total MyISAM indexes: 16.0M/1.9M
[OK] Key buffer hit rate: 99.4% (266K cached / 1K reads)
[OK] Query cache efficiency: 70.2% (4M cached / 6M selects)
[!!] Query cache prunes per day: 2132
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 586K sorts)
[!!] Temporary tables created on disk: 30% (24K on disk / 81K total)
[OK] Thread cache hit rate: 99% (1K created / 597K connections)
[!!] Table cache hit rate: 14% (64 open / 433 opened)
[OK] Open file limit used: 0% (6/1K)
[OK] Table locks acquired immediately: 100% (2M immediate / 2M locks)
[!!] InnoDB data size / buffer pool: 22.1M/8.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    Enable the slow query log to troubleshoot bad queries
    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:
    query_cache_size (> 16M)
    tmp_table_size (> 32M)
    max_heap_table_size (> 16M)
    table_cache (> 64)
    innodb_buffer_pool_size (>= 22M)

Mehr Informationen über das Skript selbst finden Sie hier: http://mysqltuner.com/

mysql-primer.sh

Eine Alternative mit etwas ausführlicherem Output ist das MySQL Performance Tuning Primer Script. Es ist ein bash-Skript welches unter Umständen eine Installation des Kommandos "bc" benötigt.

Es kann hier heruntergeladen werden: http://www.day32.com/MySQL/tuning-primer.sh

Hier ein Beispiel Output eines nicht weiter optimierten MySQL-Servers:

server:~# bash tuning-primer.sh 

Using login values from ~/.my.cnf
- INITIAL LOGIN ATTEMPT FAILED -
Testing for stored webmin passwords:
 None Found
Could not auto detect login info!
Found Sockets: /var/run/mysqld/mysqld.sock
Using: /var/run/mysqld/mysqld.sock
Would you like to provide a different socket?: [y/N] 
Do you have your login handy ? [y/N] : y
User: root
Password: XXXXXX
 
Would you like me to create a ~/.my.cnf file for you? [y/N] : 
 
	-- MYSQL PERFORMANCE TUNING PRIMER --
	     - By: Matthew Montgomery -

MySQL Version 5.0.51a-24+lenny2+spu1 i486

Uptime = 11 days 16 hrs 45 min 23 sec
Avg. qps = 8
Total Questions = 8816468
Threads Connected = 1

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.0/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 NOT enabled.
Current long_query_time = 10 sec.
You have 0 out of 8816491 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
See http://dev.mysql.com/doc/refman/5.0/en/point-in-time-recovery.html

WORKER THREADS
Current thread_cache_size = 8
Current threads_cached = 7
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 100
Current threads_connected = 1
Historic max_used_connections = 19
The number of used connections is 19% of the configured maximum.
Your max_connections variable seems to be fine.

INNODB STATUS
Current InnoDB index space = 3 M
Current InnoDB data space = 22 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 : 91 M
Configured Max Per-thread Buffers : 262 M
Configured Max Global Buffers : 42 M
Configured Max Memory Limit : 304 M
Physical Memory : 2.00 G
Max memory limit seem to be within acceptable norms

KEY BUFFER
Current MyISAM index space = 1 M
Current key_buffer_size = 16 M
Key cache miss rate is 1 : 163
Key buffer free ratio = 88 %
Your key_buffer_size seems to be fine

QUERY CACHE
Query cache is enabled
Current query_cache_size = 16 M
Current query_cache_used = 6 M
Current query_cache_limit = 1 M
Current Query cache Memory fill ratio = 38.54 %
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 = 132.00 K
You have had 191 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 = 1024 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_cache value = 64 tables
You have a total of 83 tables
You have 64 open tables.
Current table_cache hit rate is 4%
, while 100% of your table cache is in use
You should probably increase your table_cache

TEMP TABLES
Current max_heap_table_size = 16 M
Current tmp_table_size = 32 M
Of 56876 temp tables, 30% were created on disk
Effective in-memory tmp_table_size is limited to max_heap_table_size.
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.

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

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

Weitere Informationen finden Sie hier: http://www.day32.com/MySQL/


Share/Save/Bookmark  Feedback zu diesem Artikel geben
Meine Werkzeuge
Namensräume
Varianten
Aktionen
Navigation
Kategorien
Drucken/exportieren
Werkzeuge