Frage Datenbankoptimierung

AWOHille
Posts: 257
Joined: 2011-09-05 09:00

Frage Datenbankoptimierung

Post by AWOHille »

Hallo,

ich habe mir in den letzten Tagen versucht, meine MySQL-Datenbank zu optimieren. Ich denke mal, das dies soweit ganz gut gelungen ist. Trotzdem meine Frage, ob jemand mal schauen könnte, ob es noch Verbesserungsmöglichkeiten gibt. Hier mal die Ausgabe von tuning-primer und mysqltuner:

tuning-primer

Code: Select all

MySQL Version 5.1.49-3-log x86_64

Uptime = 1 days 6 hrs 29 min 24 sec
Avg. qps = 0
Total Questions = 94074
Threads Connected = 2

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.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 0 out of 94095 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 NOT enabled.
You will not be able to do point in time recovery
See http://dev.mysql.com/doc/refman/5.1/en/point-in-time-recovery.html

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

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

INNODB STATUS
Current InnoDB index space = 224 K
Current InnoDB data space = 1 M
Current InnoDB buffer pool free = 71 %
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 : 50 M
Configured Max Per-thread Buffers : 53 M
Configured Max Global Buffers : 34 M
Configured Max Memory Limit : 87 M
Physical Memory : 3.74 G
Max memory limit seem to be within acceptable norms

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

QUERY CACHE
Query cache is enabled
Current query_cache_size = 8 M
Current query_cache_used = 5 M
Current query_cache_limit = 1 M
Current Query cache Memory fill ratio = 65.52 %
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 21 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 = 2030 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 = 1000 tables
Current table_definition_cache = 256 tables
You have a total of 613 tables
You have 915 open tables.
The table_cache value seems to be fine
You should probably increase your table_definition_cache value.

TEMP TABLES
Current max_heap_table_size = 32 M
Current tmp_table_size = 32 M
Of 7157 temp tables, 21% were created on disk
Created disk tmp tables ratio seems fine

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

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


mysqltuner

Code: Select all

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.49-3-log
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 34M (Tables: 579)
[--] Data in InnoDB tables: 1M (Tables: 11)
[!!] Total fragmented tables: 26

-------- Security Recommendations -------------------------------------------
[OK] All database users have passwords assigned

-------- Performance Metrics -------------------------------------------------
[--] Up for: 1d 6h 28m 50s (94K q [0.857 qps], 5K conn, TX: 342M, RX: 15M)
[--] Reads / Writes: 74% / 26%
[--] Total buffers: 66.0M global + 2.7M per thread (20 max threads)
[OK] Maximum possible memory usage: 119.7M (3% of installed RAM)
[OK] Slow queries: 0% (0/94K)
[OK] Highest usage of available connections: 30% (6/20)
[OK] Key buffer size / total MyISAM indexes: 16.0M/14.5M
[!!] Key buffer hit rate: 92.3% (153K cached / 11K reads)
[OK] Query cache efficiency: 67.9% (42K cached / 62K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 1K sorts)
[OK] Temporary tables created on disk: 21% (1K on disk / 8K total)
[OK] Thread cache hit rate: 99% (6 created / 5K connections)
[!!] Table cache hit rate: 10% (915 open / 9K opened)
[OK] Open file limit used: 73% (1K/2K)
[OK] Table locks acquired immediately: 100% (27K immediate / 27K locks)
[OK] InnoDB data size / buffer pool: 1.7M/8.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
 Run OPTIMIZE TABLE to defragment tables for better performance
 Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
 table_cache (> 1000)


Hier noch die my.cf

Code: Select all

#
# 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      = 16M
max_allowed_packet   = 16M
thread_stack      = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
max_connections        = 20
table_cache            = 1000
open_files_limit       = 2000
tmp_table_size         = 32M
max_heap_table_size    = 32M
#thread_concurrency    = 10
#
# * Query Cache Configuration
#
query_cache_limit   = 1M
query_cache_size        = 8M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
general_log_file        = /var/log/mysql/mysql.log
general_log             = 1
#
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# 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.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id      = 1
#log_bin         = /var/log/mysql/mysql-bin.log
#expire_logs_days   = 10
#max_binlog_size         = 100M
#binlog_do_db      = include_database_name
#binlog_ignore_db   = include_database_name
#
# * 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!
#
# * 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   = 16M

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

[isamchk]
key_buffer      = 16M

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/


Warum machen tuning-primer und mysqltuner im Bereich table_cache so unterschiedliche Aussagen?

Gruß Hille
Top

User avatar
Joe User
Project Manager
Project Manager
Posts: 11519
Joined: 2003-02-27 01:00
Location: Hamburg

Re: Frage Datenbankoptimierung

Post by Joe User »

table_cache bitte erstmal auf 4096 und table_definition_cache auf 1024 setzen.
Dann MySQL neu starten und 48-72 Stunden warten und die Ausgaben nochmal posten.

Die Unterschiede kommen durch unterschiedliche Auswertungsverfahren.
PayPal.Me/JoeUserFreeBSD Remote Installation
Wings for LifeWings for Life World Run

„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
Top

AWOHille
Posts: 257
Joined: 2011-09-05 09:00

Re: Frage Datenbankoptimierung

Post by AWOHille »

So, 3 Tage sind vergangen.

mysqltuner:

Code: Select all

 >> MySQLTuner 1.2.0 - Major Hayden <major@mhtx.net>
 >> Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >> Run with '--help' for additional options and output filtering

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.49-3-log
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 34M (Tables: 579)
[--] Data in InnoDB tables: 1M (Tables: 11)
[!!] Total fragmented tables: 29

-------- Security Recommendations -------------------------------------------
[OK] All database users have passwords assigned

-------- Performance Metrics -------------------------------------------------
[--] Up for: 3d 2h 27m 54s (142K q [0.530 qps], 7K conn, TX: 551M, RX: 26M)
[--] Reads / Writes: 76% / 24%
[--] Total buffers: 66.0M global + 2.7M per thread (20 max threads)
[OK] Maximum possible memory usage: 119.7M (3% of installed RAM)
[OK] Slow queries: 0% (4/142K)
[OK] Highest usage of available connections: 70% (14/20)
[OK] Key buffer size / total MyISAM indexes: 16.0M/14.7M
[OK] Key buffer hit rate: 96.9% (358K cached / 11K reads)
[OK] Query cache efficiency: 71.0% (64K cached / 90K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 1K sorts)
[!!] Temporary tables created on disk: 32% (4K on disk / 14K total)
[OK] Thread cache hit rate: 99% (15 created / 7K connections)
[!!] Table cache hit rate: 13% (1K open / 8K opened)
[OK] Open file limit used: 20% (1K/8K)
[OK] Table locks acquired immediately: 99% (33K immediate / 33K locks)
[OK] InnoDB data size / buffer pool: 1.7M/8.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
 Run OPTIMIZE TABLE to defragment tables for better performance
 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:
 tmp_table_size (> 32M)
 max_heap_table_size (> 32M)
 table_cache (> 4096)


tuning-primer:

Code: Select all

MySQL Version 5.1.49-3-log x86_64

Uptime = 3 days 2 hrs 29 min 40 sec
Avg. qps = 0
Total Questions = 142147
Threads Connected = 2

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 4 out of 142168 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 NOT enabled.
You will not be able to do point in time recovery
See http://dev.mysql.com/doc/refman/5.1/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 = 20
Current threads_connected = 2
Historic max_used_connections = 14
The number of used connections is 70% of the configured maximum.
Your max_connections variable seems to be fine.

INNODB STATUS
Current InnoDB index space = 224 K
Current InnoDB data space = 1 M
Current InnoDB buffer pool free = 71 %
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 : 71 M
Configured Max Per-thread Buffers : 53 M
Configured Max Global Buffers : 34 M
Configured Max Memory Limit : 87 M
Physical Memory : 3.74 G
Max memory limit seem to be within acceptable norms

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

QUERY CACHE
Query cache is enabled
Current query_cache_size = 8 M
Current query_cache_used = 7 M
Current query_cache_limit = 1 M
Current Query cache Memory fill ratio = 91.17 %
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 10 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 = 8222 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 = 4096 tables
Current table_definition_cache = 1024 tables
You have a total of 613 tables
You have 1097 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 32 M
Current tmp_table_size = 32 M
Of 9796 temp tables, 31% 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.

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

TABLE LOCKING
Current Lock Wait ratio = 1 : 11100
Your table locking seems to be fine


Was sollte noch optimiert werden?

Gruß Hille
Last edited by AWOHille on 2011-11-06 20:58, edited 1 time in total.
Top

ddm3ve
Moderator
Moderator
Posts: 1115
Joined: 2011-07-04 10:56

Re: Frage Datenbankoptimierung

Post by ddm3ve »

Hast Du überhaupt ein performance Problem mit der Datenbank?

The slow query log is enabled.
Current long_query_time = 2.000000 sec.
You have 4 out of 142168 that take longer than 2.000000 sec. to complete
Your long_query_time seems to be fine
02:32:12 21.12.2012 und dann sind Deine Probleme alle unwichtig.
Top

AWOHille
Posts: 257
Joined: 2011-09-05 09:00

Re: Frage Datenbankoptimierung

Post by AWOHille »

Nein, eigentlich nicht. Fragst du wegen der 4 slow query?
Top

ddm3ve
Moderator
Moderator
Posts: 1115
Joined: 2011-07-04 10:56

Re: Frage Datenbankoptimierung

Post by ddm3ve »

Nein, das mit den 4 Abfragen ist ein Anzeichen, dass Du offensichtlich kein Problem hat.

Die Parameter sind grundsätzlich erstmal ok so.
Der Schlüssel zu einer wirklich schnellen Datenbank liegt n erster Linie in einem guten Datenbankdesign und einer schlüssigen Indizierung dazu gehört dann auch die richtige Engine.
02:32:12 21.12.2012 und dann sind Deine Probleme alle unwichtig.
Top

User avatar
Joe User
Project Manager
Project Manager
Posts: 11519
Joined: 2003-02-27 01:00
Location: Hamburg

Re: Frage Datenbankoptimierung

Post by Joe User »

Das Einzige was noch zu optimieren wäre, wäre das Dantenbankdesign um die on-disk-Temp-Tables zu reduzieren. Das musst Du aber in Deinen Apps machen.

Mittels der my.cnf sind derzeit keine nennenswerten Optimierungen mehr zu erreichen.
Last edited by Joe User on 2011-11-07 01:32, edited 1 time in total.
PayPal.Me/JoeUserFreeBSD Remote Installation
Wings for LifeWings for Life World Run

„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
Top

AWOHille
Posts: 257
Joined: 2011-09-05 09:00

Re: Frage Datenbankoptimierung

Post by AWOHille »

OK, danke!
Top