• This forum has a zero tolerance policy regarding spam. If you register here to publish advertising, your user account will be deleted without further questions.

MySQL Performance Tuning mit Tuning-Primer.sh Script

noto

New Member
MySQL Performance Tuning mit Tuning-Primer.sh Script

Quelle

Das Script ist von den MySQL Programmieren. Es analysiert und macht Verbesserungsvorschläge.

Anleitung: (Installation)

#per SSH mit root einloggen, dann mit

cd /usr
cd bin


#in das /usr/bin Verzeichnis wechseln. Nun kopieren wir tuning-primer.sh in das
#/bin Verzeichnis

wget http://www.day32.com/MySQL/tuning-primer.sh

#und setzen die Zugriffsrechte mit

chmod 755 tuning-primer.sh

#nun rufen wir das Script auf mit

tuning-primer.sh

oder

./tuning-primer.sh

Ausgabe Beispiel:

SLOW QUERIES
Current long_query_time = 2 sec.
You have 0 out of 40657 that take longer than 2 sec. to complete
The slow query log is enabled.
Your long_query_time 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

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

MEMORY USAGE
Max Memory Ever Allocated : 9 M
Configured Max Per-thread Buffers : 26 M
Configured Max Global Buffers : 4 M
Configured Max Memory Limit : 31 M
Total System Memory : 10 G
Max memory limit seem to be within acceptable norms

KEY BUFFER
Current MyISAM index space = 1 M
Current key_buffer_size = 1 M
Key cache miss rate is 1 : 190
Key buffer fill ratio = 6.00 %
Your key_buffer_size seems to be too high.
Perhaps you can use these resources elsewhere


QUERY CACHE
Query cache is enabled
Current query_cache_size = 512 K
Current query_cache_used = 364 K
Current query_cach_limit = 1 M
Current Query cache fill ratio = 71.28 %
MySQL won't cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 512 K
Current record/read_rnd_buffer_size = 256 K
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 132.00 K
You have had 0 queries where a join could not use an index properly
Your joins seem to be using indexes properly


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 = 256 tables
You have a total of 227 tables
You have 50 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 16 M
Current tmp_table_size = 32 M
Of 1091 temp tables, 84% were created on disk
Effective in-memory tmp_table_size is limited to max_heap_table_size.
Perhaps you should increase your max_heap_table_size and/or tmp_table_size to reduce the number of disk-based temporary tables

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

TABLE LOCKING
Current Lock Wait ratio = 1 : 424
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

Hilfreiche Links:

MySQL Variables
MySQL Optimieren von Thomas Schefter
 
macht er die optimalen Einstellungen von alleine oder ist dies nur als Anzeige was man verbessern könnte ?

BIG THX
 
Script macht Optimierungsvorschläge. Einstellungen muss man in der my.cnf sebst eintragen. SQL zu optimieren benötigt etwas Zeitaufwand und ist auch von der PHP Anwendung selbst abhängig.

Wie soll die /etc/my.cnf aussehen?

Bei vServern/rootDS mit wenig RAM sollte man mit kleinen Werten beginnen und dann /usr/bin/tuning-primer.sh laufen lassen

Beispiel my.cnf
Code:
[mysqld]

key_buffer = 2M

sort_buffer_size = 32K
myisam_sort_buffer_size = 32K

read_buffer_size = 16K
read_rnd_buffer_size = 32K

query_cache_size = 2M
thread_cache = 8
table_cache = 512

max_connections = 20
low_priority_updates = 1
long_query_time = 2
mit tuning-primer.sh beobachten wir nun das Verhalten von MySQL und fügen bei Bedarf in der my.cnf neue Variables hinzu oder ändern deren Werte. Eine Datenbank ist dynamisch d.h. Tabellen werden mit der Zeit grösser. Daher sollte man tuning-primer.sh regelmässig laufen lassen z.B. jede Woche.

Ausgabe Beispiel:
Code:
MEMORY USAGE
Max Memory Ever Allocated : 8 M [COLOR="Blue"]#momentan benutzt[/COLOR]
Configured Max Per-thread Buffers : 25 M
Configured Max Global Buffers : 4 M
[COLOR="Red"]Configured Max Memory Limit[/COLOR] : 30 M [COLOR="Blue"]#maximal nutzbar[/COLOR]
Total System Memory : 1 G
Configured Max Memory Limit, also wieviel RAM man maximal MySQL zur Verfügung stellen will, errechnet sich vereinfacht aus key_buffer + (sort_buffer + read_buffer) x max_connections = RAM


Beispiel:

wir wollen MySQL 512 MB zur Verfügung stellen.

key_buffer = 128M + (read_buffer = 4M + sort_buffer = 4 M) x max_connections = 512 MB

128 + (4 + 4) x max_connections = 512

wir stellen die Formel nach max_connections um

max_connections = (RAM - key_buffer) : (read_buffer + sort_buffer)

max connections = (512 - 128) : (4 + 4)

max_connections = 384 : 8

max_connections = 48

benötigen wir mehr als 48 max_connections, müssen wir mehr RAM zur Verfügung stellen oder read_buffer und sort_buffer kleiner machen.

Regel

je weniger RAM zur Verfügung steht und je mehr max_connections benötigt werden, desto kleiner müssen read_buffer, sort_buffer u. key_buffer sein.
 
Last edited by a moderator:
Beispielkonfiguration (Server mit 1 GB RAM und ~ 50 gleichzeitigen Client Verbindungen)

Ziel ist, daß Apache + MySQL eine möglichst hohe Anzahl an Seitenaufrufen/Anfragen gleichzeitig bearbeiten können ohne daß der RAM ausgeht und es zu Fehlermeldungen kommt. Um dies zu erreichen muß man den Speicherverbrauch (RAM) von Apache und MySQL limitieren.

1.

Zuerst optimieren wir Apache.

/etc/httpd/conf/httpd.conf oder /etc/apache2/server-tuning.conf Einstellungen ändern.
Code:
Timeout 30
KeepAlive On
MaxKeepAliveRequests 150
KeepAliveTimeout 2 [COLOR="Red"]eventuell auch auf 1[/COLOR]

HostnameLookups off
und Apache neu starten /etc/init.d/httpd restart

2.

mit
Code:
ps -ylC httpd --sort:rss
oder
Code:
ps axu --sort:command
ermitteln wir wieviele httpd Prozesse (CMD) wir haben und wieviel RAM diese benötigen.
Code:
S   UID   PID  PPID  C PRI  NI  [COLOR="Red"]RSS[/COLOR]    SZ WCHAN  TTY          TIME CMD
S    48 27683 32483  0  76   0 11576 8011 semtim ?        00:00:00 httpd
S    48 27734 32483  0  76   0 11956 8018 -      ?        00:00:00 httpd
S     0 32483     1  0  76   0 15796 7985 -      ?        00:00:46 httpd
der Wert RSS ist der Speicherverbrauch in KB, hier also 11 MB und 15 MB

3.

nun müssen wir Apache RAM zuweisen. 1 GB stehen zur Verfügung, davon ziehen wir pauschal 125 MB ab für Qmail + Apache (ohne Plesk, Bind, Spamassassin, Dr. Web!). Bleiben noch 875 MB für Apache httpd Prozesse und MySQL.

Angenommen du benötigst 50 httpd Prozesse (MaxClients), dann wären das (5 + 50) * 15 MB ~ 825 MB RAM. Deine /etc/httpd/conf/httpd.conf oder /etc/apache2/server-tuning.conf
könnte dann so aussehen.
Code:
<IfModule prefork.c>
StartServers       5
MinSpareServers    5 [COLOR="Red"]httpd Prozesse[/COLOR]
MaxSpareServers    10
ServerLimit       50
MaxClients        50 [COLOR="Red"]httpd Prozesse[/COLOR] maximal können 50 Seitenbesucher gleichzeitig bedient werden
MaxRequestsPerChild  8000
<IfModule>
5 + 50 = 55 httpd Prozesse a ~ 15 MB

4.

Für MySQL blieben dann noch ~ 50 MB RAM übrig (1000 MB - 125 MB - 825 MB = 50 MB). Auch hierzu ein Beispiel für die /etc/my.cnf
Code:
[mysqld]

key_buffer = 15M
net_buffer_length = 8K

sort_buffer_size = 32K
myisam_sort_buffer_size = 32K

read_buffer_size = 16K
read_rnd_buffer_size = 32K
join_buffer_size = 512K

query_cache_size = 4M
thread_cache = 32
table_cache = 512
max_allowed_packet = 256K

max_connections = 50 [COLOR="Red"]Verhältnis MaxClients zu max_connections ist hier 1:1[/COLOR]
low_priority_updates = 1
long_query_time = 2
diese Konfiguration benötigt ~ 41 MB RAM. Nun Tuning Primer Script laufen lassen und
Code:
[COLOR="Red"]Configured Max Memory Limit : 50 M[/COLOR]
kontrollieren. Wir wollen MySQL ja maximal 50 MB zur Verfügung stellen. Resultierend aus max_connections und den buffers/caches darf Configured Max Memory Limit nicht höher als 50 M sein! Liegen wir über 50 M müssen die buffers von MySQL kleiner gemacht werden. Oder man weist MySQL mehr RAM zu und Apache bekommt weniger. Dann veringern sich natürlch bei Apache die MaxClients, also die Anzahl der möglichen httpd Prozesse.

Das Verhältnis MaxClients (Apache) zu max_connections (MySQL) kann 1:1 oder 2:1 oder 3:1 sein. MaxClients = 50 entspricht bei einem Verhältnis von 2:1 max_connections = 25

5.

alle nicht benötigten Apache Module mit # ausklammern damit diese nicht mehr beim Start von Apache geladen werden und Resourcen verbrauchen.

Apache 2.2 Modules
Apache 1.3 Modules

Apache Module die man i.d. Regel ausklammern kann.
Code:
[COLOR="Red"]#[/COLOR]auth_anon_module
auth_dbm_module
include_module
mime_magic_module
expires_module
usertrack_module
status_module
autoindex_module
negotation_module
spelling_module
userdir_module

proxy_module
proxy_ftp_module
proxy_http_module
proxy_connect_module
frontpage_module
jedes Module einzeln ausklammern und danach Apache neu starten. Kommt es zur Fehlermeldung, ausklammern rückgängig machen.

Weiteres Konfigurationsbeispiel gibt es hier
 
Last edited by a moderator:
Was kann ich noch tun um RAM Verbrauch zu mindern?

Wenn nicht benötigt, Plesk, Spamassassin, Dr. Web und Bind stoppen.

Code:
[COLOR="Blue"]#Plesk stoppen [stop] [start] [status] [restart][/COLOR]
/etc/init.d/psa stop

Hinsweis: um sich in Plesk einloggen zu können muss Plesk zuvor gestartet sein. Sollte der RAM dafür nicht reichen, einfach Qmail und/oder httpd solange stoppen.
Code:
[COLOR="Blue"]#Qmail stoppen [stop] [start] [status] [restart][/COLOR]
/etc/init.d/qmail stop
 
Last edited by a moderator:
Wie kann ich den RAM Verbrauch kontrollieren?

mit
Code:
cat /proc/user_beancounters
kann man sich die Beancounters anzeigen lassen.

Der Wert privvmpages sollte stabil < 90% von barrier sein.
 
Last edited by a moderator:
KeepAliveTimeout 2
MaxClients 20

Alle 2 Sekunden werden 20 Besucher (Clients) bedient. Das sind in 10 Sekunden 100 Besucher! Und das bei weniger RAM Verbrauch.
Sorry, aber diese Interpretation der Einstellungen ist komplett falsch!
Der "KeepAliveTimeout" sagt rein gar nichts darüber aus, wieviele Clients abgearbeitet werden, sondern wie lange eine Verbindung zu einem Client bei einem KeepAlive (http/1.1) nach der letzten Übertragung noch offen gehalten wird.
Der "MaxClients" sagt, wieviele Clients ein Apache-Child-Prozess verarbeiten soll, bevor er 'stirbt'. Hier geht es darum evtl. auftretende Probleme nicht ewig als Altlasten mit sich zu schleppen, sondern z.B. nicht wieder freigegebenen Speicher einfach nach einer gewissen Zeit doch wieder zu erreichen. Auf diese Art und Weise werden vorallem kleinere Programmierfehler abgefangen.

Über die Menge an eingenommenen Speicher vom Apache bestimmen beim MPM-Prefork vorallem folgende Parameter: "MinSpareServers" als Untergrenze, "MaxSpareServers" als Obergrenze und vorallem "StartServers" als Startwert.
Natürlich fallen jeweils auch die Anzahl der Module ins Gewicht. Hier hilft es tatsächlich mal so richtig zu entschlacken.

huschi.
 
Sehe ich das nun richtig?
Code:
<IfModule prefork.c>
StartServers       1
MinSpareServers    1
MaxSpareServers    2
ServerLimit       150
MaxClients        15
MaxRequestsPerChild  0
</IfModule>
Es wird ein Elternprozess gestartet. Dieser startet mindestens einen unbeschäftigten Kindprozess und maximal zwei unbeschäftigte Kindprozesse (diese stehen immer sofort zur Verfügung). Maximal sind 150 Kindprozesse gestartet. Maximal können 15 Clients gleichzeitig bedient werden (offene Verbindungen). Kind Prozesse werden niemals erneuert.

Quelle
 
Last edited by a moderator:
hab nochmal nachgelesen
Code:
<IfModule prefork.c>
StartServers       1
MinSpareServers    1
MaxSpareServers    2
ServerLimit       150
MaxClients        15
MaxRequestsPerChild  4000
</IfModule>
StartServers
1 Eltern Prozess wird gestartet welcher weitere Kind Prozesse startet

MinSpareServers
mindestens 1 nicht arbeitender Kind Prozess wird in Reserve gehalten

MaxSpareServers
maximal 2 nicht arbeitende Kind Prozesse werden in Reserve gehalten

ServerLimit
Obergrenze der MaxClients. MaxClients kann hier maximal 150 sein.

MaxCients
maximal werden 15 offene http/1.1 Verbindungen simultan hergestellt. Pro Kind Prozess (httpd2) eine offene Verbindung zum Client.

MaxRequetsPerChild
nach 4000 Requests oder persistenten http/1.1 Verbindungen wird der Kind Prozess eleminiert

Jeder Kind Prozess kann einen Client (Besucher) bedienen = offene http/1.1 Verbindung
Code:
KeepAlive On
MaxKeepAliveRequests 1000
KeepAliveTimeout 4
KeepAlive On
persistente http/1.1 Verbindung mit Client wird offen gehalten und Requests (Anfragen) verarbeitet

KeepAliveRequests
während einer persistenten Verbindung werden maximal 1000 Requests verarbeitet

KeepAliveTimeout
persistente http/1.1 Verbindung wird 4 Sekunden nach letztem Request beendet

Stimmt das so?
 
Last edited by a moderator:
StartServers
1 Eltern Prozess wird gestartet welcher pro Sekunde 1 Kind Prozess startet
Die ersten 5 Wörter stimmen; der Rest ist Quatsch.

MaxSpareServers
maximal 2 Kind Prozesse werden als Reserve gestartet
Nein. Maximal 2 sich langweilende Childs werden gehalten. Der Rest der rumtümpelden Childs werden geRIPed (getötet).

MaxCients
maximal werden 15 Kind Prozesse simultan gestartet
Nicht ganz, aber in etwa. Hier hat jeder Server-Prozess die Kontrolle über sich selbst. Im Gegensatz zum ServerLimit, welcher in die Kontrolle des obersten Elternprozess fällt.

Man beachte allerdings: Dies gilt jeweils nur für den MPM-Prefork. Das MPM-Worker hat ein anderes/besseres Speichermodell und da bewirken die Direktiven teilweise etwas ganz anderes.

huschi.
 
HEAP Tabellen + phpBB Forum

Bestimmte Queries und z.B. Sessions (von Foren) werden in Temp Tables vom Typ HEAP geschrieben (also in den RAM). HEAP Tables sind aber von der Zeilenanzahl begrenzt (max_heap_table_size) und werden bei überschreiten der Zeilenanzahl automatisch in MyISAM Tables konvertiert (also auf Festplatte 'swap' geschrieben).

max_heap_table_size zu erhöhen scheint nicht wirklich was zu bringen, da egal wie hoch der Wert eingestellt wurde, die HEAP Tabelle irgendwann voll ist und als MyISAM auf 'swap' (Festplatte) geschrieben wird. Zudem werden Queries wie ORDER BY und GROUP BY bei TEXT oder BLOB Spalten nicht von der HEAP Speicherengine unterstützt und generell als MyISAM Tabelle auf Festplatte geschrieben

Hier ein Beitrag zum Thema HEAP in einem Blog

Scheinbar sollen die Variables max_heap_table_size und tmp_table_size einen Bug haben. rofl

Und hier noch ein sehr guter Beitrag zu HEAP
 
Hallo,

ich habe mir das Tool mal installiert und durchlaufen lassen, weil meine Datenbank scheinbar ziemlich langsam wird:(
Es läuft eigentlich nur ein vBulletin Board drauf, aber scheinbar sind dort einige Tabellen nicht ok.

Auszug:
Code:
MySQL Version 4.1.22-standard-log i686

Uptime = 2 days 1 hrs 36 min 52 sec
Avg. qps = 3
Total Questions = 694879
Threads Connected = 3

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 17 out of 694891 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.

WORKER THREADS
Current thread_cache_size = 0
Current threads_cached = 0
Current threads_per_sec = 3
Historic threads_per_sec = 0
Threads created per/sec are overrunning threads cached
You should raise thread_cache_size

MAX CONNECTIONS
Current max_connections = 500
Current threads_connected = 3
Historic max_used_connections = 23
The number of used connections is 4% of the configured maximum.
You are using less than 10% of your configured max_connections.
Lowering max_connections could help to avoid an over-allocation of memory
See "MEMORY USAGE" section to make sure you are not over-allocating

MEMORY USAGE
Max Memory Ever Allocated : 65 M
Configured Max Per-thread Buffers : 593 M
Configured Max Global Buffers : 38 M
Configured Max Memory Limit : 631 M
Total System Memory : 1 G
Max memory limit seem to be within acceptable norms

KEY BUFFER
Current MyISAM index space = 182 M
Current key_buffer_size = 16 M
Key cache miss rate is 1 : 107
Key buffer fill ratio = 50.00 %
Your key_buffer_size seems to be too high.
Perhaps you can use these resources elsewhere

QUERY CACHE
Query cache is enabled
Current query_cache_size = 12 M
Current query_cache_used = 11 M
Current query_cach_limit = 1 M
Current Query cache fill ratio = 97.00 %
However, 12538 queries have been removed from the query cache due to lack of memory
Perhaps you should raise query_cache_size
MySQL won't cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 512 K
Current record/read_rnd_buffer_size = 256 K
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 132.00 K
You have had 28 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 = 2500 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 3001 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 max_heap_table_size = 16 M
Current tmp_table_size = 32 M
Of 11308 temp tables, 3% were created on disk
Effective in-memory tmp_table_size is limited to max_heap_table_size.
Created disk tmp tables ratio seems fine

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

TABLE LOCKING
Current Lock Wait ratio = 1 : 2966
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'

Die my.cnf ist folgendermaßen aufgebaut:

Code:
[mysqld]
set-variable	=   default_character_set=latin1
set-variable	=   character-set-server=latin1
set-variable	=   key_buffer=16M
set-variable	=   max_allowed_packet=1M
set-variable	=   table_cache=128
set-variable	=   sort_buffer=512K
set-variable	=   net_buffer_length=8K
set-variable	=   myisam_sort_buffer_size=8M
set-variable          =   query_cache_size=12M
set-variable	=   max_connections=500
set-variable	=   long_query_time = 2

Der Server ist ein 3GHZ mit 1GB Ram und Linux Redhat.
Große Sorgen bereitet mir der Eintrag Joins, wie kann ich das am besten beheben, bzw. optimieren?
 
Große Sorgen bereitet mir der Eintrag Joins, wie kann ich das am besten beheben, bzw. optimieren?
Steht doch alles in dem Abschnitt. Entweder join_buffer_size erhöhen oder Indizes setzen. Und ausserdem, wird Dir dieses Script dies solange vorhalten, bis es endlich keine Joins auf nicht gesetzten Indizes mehr findet.

Du solltest aber auf einige andere Einstellungen achten, wie z.B. query_cache_size und table_cache.
Und Untersuche erstmal die "slow queries" anhand eines Logfiles.

huschi.
 
MySQL hat ~ 631 MB zur Verfügung, nutzt aber nur 65 MB weil die Buffers, Caches durch die my.cnf Variables limitiert sind und du nur ein Bruchteil der max_connections hast. (dein RAM langweilt sich ja)

Code:
MEMORY USAGE
[COLOR="Blue"]Max Memory Ever Allocated : 65 M[/COLOR]
Configured Max Per-thread Buffers : 593 M
Configured Max Global Buffers : 38 M
[COLOR="Blue"]Configured Max Memory Limit : 631 M[/COLOR]
Total System Memory : 1 G

Laut Tuning-Primer sollst du ändern:
Code:
thread_cache_size = 
max_connections = 
query_cache_size =
join_buffer_size =
table_cache =

probiere mal folgende Variablen in deiner my.cnf
Code:
default_character_set = latin1
character-set-server = latin1
max_allowed_packet = 1M
[COLOR="Blue"]table_cache = 3001[/COLOR]
[COLOR="Blue"]thread_cache_size = 10[/COLOR]
[COLOR="Blue"]query_cache_size = 20M[/COLOR]
key_buffer = 16M
[COLOR="Blue"]join_buffer_size = 2M[/COLOR]
sort_buffer = 512K
net_buffer_length = 8K
myisam_sort_buffer_size = 8M
[COLOR="Blue"]max_connections = 25[/COLOR]
[COLOR="Blue"]long_query_time = 2[/COLOR]
[COLOR="Blue"]log_slow_queries=/var/log/mysqld.slow.log[/COLOR]
alle Änderungen in blau

.. dann änderst du noch in der httpd.conf
Code:
Timeout 30
KeepAlive On
MaxKeepAliveRequests 1000
KeepAliveTimeout 2 [COLOR="Blue"]#kann auch 3 oder 4 sein[/COLOR]
 
Last edited by a moderator:
Hallo,

dies ist mein erster Beitrag hier, also bitte nicht schlagen, wenn meine Frage(n) blöd klingen.

Also ich habe folgendes Problem, ich habe einen Server, auf dem ich ein Board am Laufen habe mit einer mittelgroßen Community (ca. 5000 User).

Zur Zeit haben wir sehr große Probleme mit unserer Serverauslastung und es kommt sehr oft die Meldung "Serverlast zu hoch, versuchen Sie es später noch einmal" und ich weiß nicht wirklich wie ich dem entgegen wirken kann, da ich noch nicht solange im Geschäft bin (Server und Community habe ich nur übernommen, da unser Admin einfach keinen Bock mehr hatte und mir das Ganze aufs Auge gedrückt hat...)

Nunja lange Rede kurzer Sinn ich hab mich etwas umgeschaut was man denn optimieren könnte und bin dabei u.a. auf primer gestoßen und bei intensiverer Suche eben auf dieses Forum.

Die Anleitung hier ist wirklich spitze und ich konnte schon ein paar Sachen verbesseren, so kommt z.B. das "Serverlast zu hoch" gar nicht mehr, jedoch ist der Seitenaufbau immer noch sehr langsam.

Die Daten des Servers sind ja eigentlich sehr gut und ich verstehe nicht wieso er so lahm ist, insbesondere da wir max. 500 Leute gleichzeitig online haben:

Intel Dual Xeon 3.0Ghz
2048MB RAM
2x 250GB in Hardware RAID-0
2000GB Traffic
100mbit/s Anbindung

primer hat mir folgende Sachen ausgegeben und ich kann wie gesagt wenig damit anfangen:

Code:
Uptime = 1 days 0 hrs 37 min 7 sec
Avg. qps = 569
Total Questions = 50489171
Threads Connected = 7

Warning: Server has not been running for at least 48hrs.
It may not be safe to use 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

SLOW QUERIES
Current long_query_time = 2 sec.
You have 2070 out of 50489196 that take longer than 2 sec. to complete
The slow query log is enabled.
Your long_query_time seems to be fine

WORKER THREADS
Current thread_cache_size = 64
Current threads_cached = 61
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 500
Current threads_connected = 6
Historic max_used_connections = 159
The number of used connections is 31% of the configured maximum.
Your max_connections variable seems to be fine.

MEMORY USAGE
Max Memory Ever Allocated : 1003 M
Configured Max Per-thread Buffers : 1 G
Configured Max Global Buffers : 586 M
Configured Max Memory Limit : 1 G
Total System Memory : 1.97 G

Max memory limit exceeds 85% of total system memory

KEY BUFFER
Current MyISAM index space = 18 M
Current key_buffer_size = 512 M
Key cache miss rate is 1 : 111063
Key buffer fill ratio = 2.00 %
Your key_buffer_size seems to be too high.
Perhaps you can use these resources elsewhere

QUERY CACHE
Query cache is enabled
Current query_cache_size = 64 M
Current query_cache_used = 21 M
Current query_cach_limit = 2 M
Current Query cache fill ratio = 32.89 %
MySQL won't cache query results that are larger than query_cache_limit in size

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

JOINS
Current join_buffer_size = 132.00 K
You have had 0 queries where a join could not use an index properly
Your joins seem to be using indexes properly

OPEN FILES LIMIT
Current open_files_limit = 2558 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 = 1024 tables
You have a total of 371 tables
You have 1024 open tables.
Current table_cache hit rate is 36%, 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 = 64 M
Of 843424 temp tables, 0% were created on disk
Effective in-memory tmp_table_size is limited to max_heap_table_size.
Created disk tmp tables ratio seems fine

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

TABLE LOCKING
Current Lock Wait ratio = 1 : 10
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'
If you have a high concurrentcy of inserts on Dynamic row-length tables
consider setting 'concurrent_insert=2'.

Ich weiß mysql läuft noch keine 48 h, aber ich hab es schon mal durchlaufen lassen und da waren die Werte fast identisch (mysql lief zu dem Zeitpunkt ca. 6 Tage)...

hier auch noch meine my.conf:

Code:
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port		= 3306
socket		= /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket		= /var/run/mysqld/mysqld.sock
nice		= 0

[mysqld]
#
# * Basic Settings
#
user		= mysql
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
port		= 3306
basedir		= /usr
datadir		= /var/lib/mysql
tmpdir		= /tmp
language	= /usr/share/mysql/english
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address		= 127.0.0.1
#
# * Fine Tuning
#
key_buffer		= 512M
max_allowed_packet	= 16M
thread_stack		= 128K
thread_cache_size	= 64
max_connections     = 500
#max_connections        = 100
tmp_table_size        = 64M
table_cache            = 512
thread_concurrency     = 8
#
# * Query Cache Configuration
#
query_cache_limit       = 4M
query_cache_size        = 128M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
#log		= /var/log/mysql/mysql.log
#
# Error logging goes to syslog. This is a Debian improvement :)
#
# Here you can see queries with especially long duration
log_slow_queries	= /var/log/mysql/mysql-slow.log
long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
#server-id		= 1
#log_bin			= /var/log/mysql/mysql-bin.log
# WARNING: Using expire_logs_days without bin_log crashes the server! See README.Debian!
#expire_logs_days	= 10
#max_binlog_size         = 100M
#binlog_do_db		= include_database_name
#binlog_ignore_db	= include_database_name
#
# * BerkeleyDB
#
# Using BerkeleyDB is now discouraged as its support will cease in 5.1.12.
skip-bdb
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
# You might want to disable InnoDB to shrink the mysqld process by circa 100MB.
#skip-innodb
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem



[mysqldump]
quick
quote-names
max_allowed_packet	= 32M

[mysql]
#no-auto-rehash	# faster start of mysql but no tab completition

[isamchk]
key_buffer		= 256M

#
# * NDB Cluster
#
# See /usr/share/doc/mysql-server-*/README.Debian for more information.
#
# The following configuration is read by the NDB Data Nodes (ndbd processes)
# not from the NDB Management Nodes (ndb_mgmd processes).
#
# [MYSQL_CLUSTER]
# ndb-connectstring=127.0.0.1


#
# * IMPORTANT: Additional settings that can override those from this file!
#
!includedir /etc/mysql/conf.d/

Ich hoffe, dass ihr mir vllt helfen könnt und euch nicht schon wegen des veilen Zeugs, dass ich gepostet habe, abwendet von meinem Beitrag

EDIT: Da ich nicht weiß, ob es relevant ist oder nicht, habe ich sicherheitshalber noch die apache.conf (in der httpd.conf ist gähnende Leere) und die php.ini als Anhang hinzugefügt
 

Attachments

  • apache.und.php.zip
    23.2 KB · Views: 604
Last edited by a moderator:
teste mal

Apache
Code:
<IfModule prefork.c>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers       10
    MaxClients            125
    MaxRequestsPerChild  10000
</IfModule>

Timeout 30
KeepAlive On
MaxKeepAliveRequests 150
KeepAliveTimeout 1
125 *15 MB = 1875 MB RAM bleiben für MySQL noch ~ 125 MB RAM

my.cnf Variables
Code:
# * Fine Tuning

key_buffer		= 24M
sort_buffer_size = 256K
myisam_sort_buffer_size = 256K
net_buffer_length = 8K
max_allowed_packet	= 32M
read_buffer_size = 128 K
read_rnd_buffer_size = 128K
thread_stack		= 128K
thread_cache_size	= 256
thread_concurrency     = 8
max_connections     = 125
table_cache            = 2048
low_priority_updates = 1
concurrent_insert = 2

# * Query Cache Configuration

query_cache_limit       = 4M
query_cache_size        = 24M

# * Logging and Replication

long_query_time = 2
damit liegen wir etwa bei 125 MB RAM

Log slow queries würde ich deaktivieren. Und lass mal Tuning Primer nach 1 Tag laufen.

Wichtig sind
Code:
MAX CONNECTIONS
Historic max_used_connections = 159
und
Code:
MEMORY USAGE
Max Memory Ever Allocated :
[COLOR="Red"]Configured Max Memory Limit : 125 M[/COLOR]
Configured Max Memory Limit sollte ~ 125 MB sein rofl

Wenn du mehr als 125 max_connections benötigst, solltest du zuerst read_buffer + read_rnd_buffer kleiner machen. Und wenn das nicht reicht auch noch sort_buffer, myisam_sort_buffer kleiner machen. Nach Änderungen MySQL stoppen und neu starten. Höhere table_cache und thread_cache verbessern Performance bei vielen gleichzeitigen Verbindungen.

Code:
service mysqld stop
service mysqld start

Und das hier lesen! Server Tuning by MKDoc.org
 
Last edited by a moderator:
Also ich hab die Settings jetzt mal eingegeben, aber mit der my.cnf startet mysql nicht einmal, kommt immer failed...die apache.conf läuft hingegen

EDIT: Es lag augenscheinlich an dem:

read_buffer_size = 128 K

das habe ich rausgenommen und schon gehts...jetzt mal warten was primer morgen sagt
 
Last edited by a moderator:
So, also ein Tag ist vorbei und nun sagt primer folgendes:

Code:
MySQL Version 5.0.32-Debian_7~bpo.1-log i386

Uptime = 1 days 13 hrs 52 min 1 sec
Avg. qps = 505
Total Questions = 68965328
Threads Connected = 55

Warning: Server has not been running for at least 48hrs.
It may not be safe to use 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

SLOW QUERIES
Current long_query_time = 2 sec.
You have 773 out of 68969583 that take longer than 2 sec. to complete
The slow query log is enabled.
Your long_query_time seems to be fine

WORKER THREADS
Current thread_cache_size = 256
Current threads_cached = 78
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 150
Current threads_connected = 46
Historic max_used_connections = 124
The number of used connections is 82% of the configured maximum.
Your max_connections variable seems to be fine.

MEMORY USAGE
Max Memory Ever Allocated : 146 M
Configured Max Per-thread Buffers : 130 M
Configured Max Global Buffers : 38 M
Configured Max Memory Limit : 168 M
Total System Memory : 1.97 G
Max memory limit seem to be within acceptable norms

KEY BUFFER
Current MyISAM index space = 21 M
Current key_buffer_size = 24 M
Key cache miss rate is 1 : 633349
Key buffer fill ratio = 68.00 %
Your key_buffer_size seems to be too high.
Perhaps you can use these resources elsewhere

QUERY CACHE
Query cache is enabled
Current query_cache_size = 4 M
Current query_cache_used = 2 M
Current query_cach_limit = 4 M
Current Query cache fill ratio = 50.86 %
MySQL won't cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 256 K
Current record/read_rnd_buffer_size = 252 K
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 132.00 K
You have had 0 queries where a join could not use an index properly
Your joins seem to be using indexes properly

OPEN FILES LIMIT
Current open_files_limit = 4256 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 = 2048 tables
You have a total of 371 tables
You have 779 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 16 M
Current tmp_table_size = 64 M
Of 1119653 temp tables, 0% were created on disk
Effective in-memory tmp_table_size is limited to max_heap_table_size.
Created disk tmp tables ratio seems fine

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

TABLE LOCKING
Current Lock Wait ratio = 1 : 40
You may benefit from selective use of InnoDB.

Meckert also immer noch über den key_buffer obwohl der ja jetzt doch schon sehr klein ist.

Der Seitenaufbau meiner Seite hat sich auch schon etwas verbessert, lahmt aber immer noch ein wenig, positiv zu vermelden ist, dass ich bis jetzt noch keine "zu hohe Serverlast hatte", dafür schon mal ein fettes THX...
 
Back
Top