Mysql läuft heiß

Mikka

New Member
Hallo,

habe einen Strato root server:
Betriebssystem: openSUSE 10.2
MySQL - 5.0.26

Momentan läuft MySQL bei 80%-180%. Ich müsste jetzt rausfinden wie diese Auslastung zustande kommt, da Sie in unregelmäßigen Abständen (momentan sogar mehrmals täglich) vorkommt. Meine Vermutung ist ein externer Angriff, da das Problem schonmal vor nem halben Jahr war und dann von heute auf morgen weg war. Und momentan tritt es seit 1 Woche wieder täglich auf. meistens in den frühen abendstunden.

Meine Frage als Einsteiger ist wie finde ich das Problem gezielt?

Anbei mal noch ein Screen
 
mtop geht nicht.. und Tuning-Primer gibt folgendes aus:




Code:
MySQL Version 5.0.26 i686

Uptime = 0 days 5 hrs 20 min 0 sec
Avg. qps = 38
Total Questions = 739254
Threads Connected = 1

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:
[url=http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html]MySQL :: MySQL 5.0 Reference Manual :: 5.1.3 System Variables[/url]
Visit [url=http://www.mysql.com/products/enterprise/advisors.html]MySQL :: MySQL Enterprise Advisors[/url]
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 739268 that take longer than 10 sec. to complete
Your long_query_time may be too high, I typically set this under 5 sec.

BINARY UPDATE LOG
The binary update log is NOT enabled.
You will not be able to do point in time recovery
See [url=http://dev.mysql.com/doc/refman/5.0/en/point-in-time-recovery.html]MySQL :: MySQL 5.0 Reference Manual :: 6.3 Point-in-Time Recovery[/url]

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

MAX CONNECTIONS
Current max_connections = 100
Current threads_connected = 1
Historic max_used_connections = 6
The number of used connections is 6% 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 : 35 M
Configured Max Per-thread Buffers : 155 M
Configured Max Global Buffers : 26 M
Configured Max Memory Limit : 181 M
Physical Memory : 994.83 M
Max memory limit seem to be within acceptable norms

KEY BUFFER
Current MyISAM index space = 18 M
Current key_buffer_size = 16 M
Key cache miss rate is 1 : 755
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 supported but not enabled
Perhaps you should set the query_cache_size

SORT OPERATIONS
Current sort_buffer_size = 512 K
Current read_rnd_buffer_size = 508 K
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 132.00 K
You have had 215 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 1222 tables
You have 64 open tables.
Current table_cache hit rate is 1%, 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 231699 temp tables, 98% 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 = 252 K
Current table scan ratio = 1138 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 1 : 4567
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 concurrency of inserts on Dynamic row-length tables
consider setting 'concurrent_insert=2'.
 
Last edited by a moderator:
zu Mtop: ich hab mal probiert ob ich die installation hinbekomme.. aber es klappt nicht.. mache das auch zum ersten mal.. aber ich hab gegoogelt und gelesen man braucht da ein Perl modul oder sowas.. klärt mich mal einer auf?

Am besten ne kurze schritt für schritt anleitung (Jeder fängt mal an)
 
Eigentlich bringt mtop auch nur die Ausgabe von "show processlist". Also einfach "mysql -uroot -p" (statt root evtl. admin bei Plesk) eingeben für die MySQL-Console.
Und darin o.g. Befehl eingeben. Mit "exit" kommst Du da wieder raus.

Wenn MySQL dauerhaft auf 80% läuft, dann sieht mir das eher nach einem Amok-Thread aus. Ein vollständiges Beenden (/etc/init.d/mysql stop && killall mysqld) mit anschließendem Neustart sollte es beheben.

huschi.
 
also in die mysql console bin ich rein gekommen.. aber dann war auch schon ende *gg*

hab jetzt mal mysql beendet und neu gestartet. Mal gucken obs hilft. Aber einen Server Rebbot hab ich die Tage schon öfters gemacht gehabt, dabei wird ja auch Mysql neu gestartet.. kommt doch letzten endes aufs gleiche raus oder?
 
bis eben lief alles ohne Probleme.. jetzt is wieder alles lahm geworden.. und siehe da:
Code:
Tasks: 200 total, 8 running, 190 sleeping, 0 stopped, 2 zombie
Cpu(s): 78.9%us, 20.8%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.3%si, 0.0%st
Mem: 1018716k total, 963196k used, 55520k free, 93604k buffers
Swap: 2104496k total, 472k used, 2104024k free, 532184k cached
 
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
6291 mysql 15 0 118m 25m 4936 S 174 2.6 11:20.45 mysqld
25314 vipbanne 16 0 5784 3956 1568 R 2 0.4 0:00.06 exchange.cgi
22987 wwwrun 15 0 69916 13m 3844 S 2 1.4 0:02.51 httpd2-prefork
23305 wwwrun 15 0 0 0 0 Z 1 0.0 0:00.55 httpd2-pr <defunct>
23640 wwwrun 15 0 71284 14m 4560 S 1 1.5 0:03.90 httpd2-prefork
22009 wwwrun 15 0 75000 18m 5256 S 1 1.8 0:04.45 httpd2-prefork
23353 wwwrun 15 0 69880 13m 3888 R 1 1.4 0:03.92 httpd2-prefork
23780 wwwrun 15 0 68936 12m 3312 S 1 1.2 0:00.61 httpd2-prefork
24752 wwwrun 15 0 78204 21m 6176 S 1 2.2 0:00.63 httpd2-prefork
24877 wwwrun 15 0 68936 12m 3308 S 1 1.2 0:00.10 httpd2-prefork
24935 wwwrun 15 0 68936 12m 3312 S 1 1.2 0:00.09 httpd2-prefork
25006 wwwrun 15 0 68936 12m 3292 S 1 1.2 0:00.04 httpd2-prefork
25311 vipbanne 17 0 0 0 0 Z 1 0.0 0:00.12 exchange. <defunct>
6372 root 15 0 2376 1120 768 R 0 0.1 0:24.18 top
23150 wwwrun 15 0 69616 13m 4124 S 0 1.4 0:00.82 httpd2-prefork
23700 wwwrun 15 0 68936 12m 3316 S 0 1.2 0:00.36 httpd2-prefork
23753 wwwrun 15 0 69104 13m 3896 S 0 1.3 0:00.45 httpd2-prefork
h1321327:~ #
MOD: Bitte benutzt CODE Tags für solche Sachen!
 
Last edited by a moderator:
Hallo!
Der Eintrag
Code:
25311 vipbanne 17 0 0 0 0 Z 1 0.0 0:00.12 exchange. <defunct>
ist irgendwie besorgniserregend. Gibt es auf deinem Server einen Benutzer vipbanne?

mfG
Thorsten
 
Bitte lesen und anwenden:
Eigentlich bringt mtop auch nur die Ausgabe von "show processlist". Also einfach "mysql -uroot -p" (statt root evtl. admin bei Plesk) eingeben für die MySQL-Console.
Und darin o.g. Befehl eingeben. Mit "exit" kommst Du da wieder raus.

huschi.
 
hat jemand vielleicht Zeit mir per ICQ zu helfen? So zieht sich das ganze ewig lange und mein dienst is schon fast 1 Woche offline.. Ich krieg täglich 10 emails mit beschwerden und würde das gerne schnell gelöst haben. Meine ICQ nr. ist 258-687-607
 
Mein Anliegen wäre immer noch aktuell. Wäre auch bereit, enn das Problem gelöst wird, als Dankeschön für die Mühe dem Helfer entgegen zu kommen. Zum Beispiel in Form von Werbung oder einer kleinen Bezahlung. Mir ist es aber momentan wichtig das Problem schnellstens zu lösen.
 
Hallo,

deine Tuningprimer Ausgabe ist nicht aussagekräftig, da der Server zu diesem Zeitpunkt nur 5 Stunden lief. 1 Tag sollte es mindestens sein, besser wäre aber eine Woche ohne Neustart des Mysql Servers.

Anhand deiner Angaben dort würde ich mal etwas wie das hier testen:

Code:
key_buffer              = 40M
query_cache_limit       = 6M
query_cache_size        = 25M
query_cache_type        = 1

read_buffer_size        = 3M
sort_buffer_size        = 3M
join_buffer_size        = 2M

# use this for testing
#join_buffer_size        = 8M

max_heap_table_size     = 25M
tmp_table_size          = 25M
## see http://bugs.mysql.com/bug.php?id=4291
#memory_tmp_table_size	= 16M

table_cache             = 1600
open_files_limit        = 3400

max_allowed_packet      = 2M
thread_stack            = 196K

thread_cache_size       = 6
max_connections         = 18

#Configured Max Memory Limit, also wieviel RAM man maximal MySQL zur Verfügung stellen will, errechnet sich aus key_buffer + (sort_buffer + read_buffer) x max_connections = RAM 40 + (3 + 3) * 18

## http://dev.mysql.com/doc/refman/5.1/de/server-parameters.html

## for debugging purposes ONLY! May cause high system load ##

#log-slow-queries=/var/log/mysql/slow_queries.log
long_query_time = 3
#log-queries-not-using-indexes = 1

## /DEBUG
 
Code:
TABLE LOCKING
Current Lock Wait ratio = 1 : 4567
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 concurrency of inserts on Dynamic row-length tables
consider setting 'concurrent_insert=2'.

Dieser HInweis ist doch schon nicht schlecht. Scheinbar hast Du min. eine Tabelle, in der Du viel liest/schreibst und die vom Typ MyISAM ist. MyISAM blockiert zu schreiben immer die ganze Tabelle. InnoDB kann das ganze auch zeilenbasiert und wäre für diese Tabelle wahrscheinlich vorteilhaft.

Wie es aussieht, machst Du auch einige Joins, wo die join_buffer_size zu klein ist.
In der my.cnf nach join_buffer_size suchen und auf 2M setzen oder wenn nicht vorhanden einfügen
Code:
join_buffer_size                = 2M

Wie Wildcat geschrieben hat "table_cache" und "open_files_limit" hochsetzen. "key_buffer" würde ich erst einmal nicht hochsetzen, sondern weiterhin so lassen und beobachten.

"tmp_table_size" ist viel zu klein und sollte, wenn genügend RAM vorhanden ist, vergrößert werden (vielleicht 512M). "max_heap_table_size" kannst Du im Gegensatz auch mal probeweise auf 8M runtersetzen.
 
So mysql wurde gestern abend optimiert und heute morgen läuft der wieder bei 133 % und mehr

Code:
13838 mysql     15   0  266m  69m 5104 S  133  7.0 781:10.28 mysqld

Code:
# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# You can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /var/lib/mysql) or
# ~/.my.cnf to set user-specific options.
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password	= your_password
port		= 3306
socket		= /var/lib/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
set-variable=local-infile=0
port		= 3306
socket		= /var/lib/mysql/mysql.sock

skip-bdb
skip-locking


key_buffer              = 40M
query_cache_limit       = 6M
query_cache_size        = 25M
query_cache_type        = 1

read_buffer_size        = 3M
sort_buffer_size        = 3M
join_buffer_size        = 2M

# use this for testing
#join_buffer_size        = 8M

max_heap_table_size     = 25M
tmp_table_size          = 25M
## see http://bugs.mysql.com/bug.php?id=4291
#memory_tmp_table_size	= 16M

table_cache             = 1600
open_files_limit        = 3400

max_allowed_packet      = 2M
thread_stack            = 196K

thread_cache_size       = 8
max_connections         = 60

#Configured Max Memory Limit, also wieviel RAM man maximal MySQL zur Verfügung stellen will, errechnet sich aus key_buffer + (sort_buffer + read_buffer) x max_connections = RAM 40 + (3 + 3) * 18

## http://dev.mysql.com/doc/refman/5.1/de/server-parameters.html

## for debugging purposes ONLY! May cause high system load ##

#log-slow-queries=/var/log/mysql/slow_queries.log
long_query_time = 3
#log-queries-not-using-indexes = 1

## /DEBUG

myisam_sort_buffer_size = 8M

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
# 
#skip-networking

# Replication Master Server (default)
# binary logging is required for replication
# log-bin=mysql-bin

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id	= 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave - required
#master-host     =   <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =   <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =   <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin

# Point the following paths to different dedicated disks
#tmpdir		= /tmp/		
#log-update 	= /path-to-dedicated-directory/hostname

# Uncomment the following if you are using BDB tables
#bdb_cache_size = 4M
#bdb_max_lock = 10000

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /var/lib/mysql/
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql/
#innodb_log_arch_dir = /var/lib/mysql/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

# The safe_mysqld script
[safe_mysqld]
err-log=/var/lib/mysql/mysqld.log

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

Code:
        -- MYSQL PERFORMANCE TUNING PRIMER --
             - By: Matthew Montgomery -

MySQL Version 5.0.26 i686

Uptime = 0 days 10 hrs 32 min 49 sec
Avg. qps = 170
Total Questions = 6459267
Threads Connected = 21

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
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 = 3 sec.
You have 69 out of 6459478 that take longer than 3 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 = 2
Current threads_per_sec = 1
Historic threads_per_sec = 0
Your thread_cache_size is fine

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

MEMORY USAGE
Max Memory Ever Allocated : 285 M
Configured Max Per-thread Buffers : 506 M
Configured Max Global Buffers : 75 M
Configured Max Memory Limit : 581 M
Physical Memory : 994.83 M
Max memory limit seem to be within acceptable norms

KEY BUFFER
Current MyISAM index space = 18 M
Current key_buffer_size = 40 M
Key cache miss rate is 1 : 18513
Key buffer fill ratio = 3.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 = 25 M
Current query_cache_used = 3 M
Current query_cache_limit = 6 M
Current Query cache Memory fill ratio = 15.97 %
Current query_cache_min_res_unit = 4 K
Your query_cache_size seems to be too high.
Perhaps you can use these resources elsewhere
MySQL won't cache query results that are larger than query_cache_limit in size

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

JOINS
Current join_buffer_size = 2.00 M
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 = 3400 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 = 1600 tables
You have a total of 1222 tables
You have 1447 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 24 M
Current tmp_table_size = 25 M
Of 3019506 temp tables, 99% 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 = 2 M
Current table scan ratio = 249 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 1 : 175
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 concurrency of inserts on Dynamic row-length tables
consider setting 'concurrent_insert=2'.
 
Back
Top