Menü Schließen

MySQL – Tuning Primer und Temp Tables optimieren

MySQL Logo

System ist ein Debian Wheezy mit MySQL in Version 5.5

Ziel ist es die Performance zu steigern / optimieren, weshalb ich das tuning-primer Script in der Version 1.6-r1 laufen lies. Ein Punkt der hier auffiel ist folgender:

TEMP TABLES
Current max_heap_table_size = 16 M
Current tmp_table_size = 16 M
Of 8270366 temp tables, 39% were created on disk
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.

Weitere Prüfung des aktuellen Status lassen sich auch direkt in der Konsole vornehmen:

# mysql -u USERNAME-ROOT -p
mysql> SELECT @@max_heap_table_size;
+———————–+
| @@max_heap_table_size |
+———————–+
|              16777216 |
+———————–+
1 row in set (0.00 sec)

#mysql> SELECT @@tmp_table_size;
+——————+
| @@tmp_table_size |
+——————+
|         16777216 |
+——————+
1 row in set (0.00 sec)

Ok, bestätigt 16MB ist die aktuelle Einstellung. Da aktuell ca. 40 Prozent auf der Festplatte zwischengespeichert werden und nicht in den beiden obigen MySQL Tabellen, werde ich den Wert vorerst auf 24M setzen.

Die beiden Parameter max_heap_table_size und tmp_table_size konnte ich in meiner Konfiguration unter /etc/mysql/my.cnf nicht finden, also habe ich sie unter dem Abschnitt Fine Tuning eingetragen. Denkbar wäre auch eine eigene Datei..

max_heap_table_size=24M
tmp_table_size=24M

Ebenso lassen sich die Werte per Konsole für Global und Userdef. eintragen:

SET GLOBAL max_heap_table_size=24576;
SET GLOBAL tmp_table_size=24576;
SET max_heap_table_size=24576;
SET tmp_table_size=24576;

Danach den MySQL Dienst neustarten:

# /etc/init.d/mysql restart
[ ok ] Stopping MySQL database server: mysqld.
[ ok ] Starting MySQL database server: mysqld ..
[info] Checking for tables which need an upgrade, are corrupt or were
not closed cleanly..

und eine kurze Überprüfung, ob die beiden neuen Optionen übernommen wurden:

# mysql> SELECT @@tmp_table_size;
+——————+
| @@tmp_table_size |
+——————+
| 25165824 |
+——————+
1 row in set (0.00 sec)

# mysql> SELECT @@max_heap_table_size;
+———————–+
| @@max_heap_table_size |
+———————–+
| 25165824 |
+———————–+
1 row in set (0.00 sec)

OK das sieht gut aus und sollte funktionieren. Damit eine positive oder auch negative Änderung bzw. Auswirkung festgestellt werden kann, sollte das tuning-primer Script, nach ein paar Tagen nochmal ausgeführt werden.

Prüfung nach ein paar Tagen

TEMP TABLES
Current max_heap_table_size = 24 M
Current tmp_table_size = 24 M
Of 791382 temp tables, 43% were created on disk
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.

Vergleicht man beide Werte, dann ist die Anzahl der Tabellen die auf der Festplatte erstellt werden nun höher. Das mag wohl daran liegen, dass zuvor wesentlich mehr Tabellen im Temp lagen. Hier sollte ggf. noch ein paar Tage beobachtet werden, bzw. die Werte minimal erhöht werden.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert