Mysql性能糟糕

时间:2015-05-06 14:02:31

标签: mysql performance

我最近得到了新硬件,但我遇到了mysql的问题。它比旧服务器上的速度慢。当我在新服务器上运行sysbench工具时,我得到了这个:

sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --mysql-password= --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
sysbench 0.4.12:  multi-threaded system evaluation benchmark

No DB drivers specified, using mysql
Running the test with following options:
Number of threads: 8

Doing OLTP test.
Running mixed OLTP test
Doing read-only test
Using Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Threads started!
Time limit exceeded, exiting...
(last message repeated 7 times)
Done.

OLTP test statistics:
    queries performed:
        read:                            365694
        write:                           0
        other:                           52242
        total:                           417936
    transactions:                        26121  (435.14 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 365694 (6091.93 per sec.)
    other operations:                    52242  (870.28 per sec.)

Test execution summary:
    total time:                          60.0293s
    total number of events:              26121
    total time taken by event execution: 479.9747
    per-request statistics:
         min:                                  0.52ms
         avg:                                 18.38ms
         max:                                117.91ms
         approx.  95 percentile:              53.21ms

Threads fairness:
    events (avg/stddev):           3265.1250/19.37
    execution time (avg/stddev):   59.9968/0.01

旧服务器产生了这个:

sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --mysql-password= --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
sysbench 0.4.12:  multi-threaded system evaluation benchmark

No DB drivers specified, using mysql
Running the test with following options:
Number of threads: 8

Doing OLTP test.
Running mixed OLTP test
Doing read-only test
Using Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Threads started!
Time limit exceeded, exiting...
(last message repeated 7 times)
Done.

OLTP test statistics:
    queries performed:
        read:                            952294
        write:                           0
        other:                           136042
        total:                           1088336
    transactions:                        68021  (1133.58 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 952294 (15870.18 per sec.)
    other operations:                    136042 (2267.17 per sec.)

Test execution summary:
    total time:                          60.0052s
    total number of events:              68021
    total time taken by event execution: 479.5141
    per-request statistics:
         min:                                  3.27ms
         avg:                                  7.05ms
         max:                                 31.63ms
         approx.  95 percentile:               8.60ms

Threads fairness:
    events (avg/stddev):           8502.6250/11.10
    execution time (avg/stddev):   59.9393/0.00

旧服务器有E3-1230 cpu和16GB内存。新服务器有E5-1660 v3和32GB内存。 OS两者都是debian wheezy,而mysql版本是5.5.43。 My.cnf在下面

#
# 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
lc-messages-dir = /usr/share/mysql
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              = 256M
key_buffer_size         = 256M
sort_buffer_size    = 2M
read_rnd_buffer_size    = 4M
innodb_buffer_pool_size = 1G
max_allowed_packet      = 32M
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        = 300
table_cache            = 256M
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit       = 1M
query_cache_size        = 200M
#
# * 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 log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#slow_query_log_file = /var/log/mysql/mysql-slow.log
#slow_query_log      = 1
#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/

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

  

query_cache_size = 200M

关闭查询缓存。即使您选择继续使用,也不要因为修剪成本而将尺寸设置为大于50M。

  

table_cache = 256M

哎哟!你不需要25亿桌!改为几百(没有后缀)。

在两台机器上执行此操作,然后区分输出:

SHOW VARIABLES LIKE 'innodb%';

有些默认值随时间而变化;这应该指出它们。

答案 1 :(得分:0)

同意Rick你的配置可能不是最佳的,但如果你真的在两台机器上运行相同的mysql配置,那么这并不能解释这种差异。所有可能的原因都需要很长时间才能列出。假设你在两个系统(冷缓存)上以相同的方式收集统计信息,那么最可能的原因是IO相关,你可以使用磁盘基准测试工具验证这一点 - 如果你还没有你知道的东西,我会推荐afio适合这项任务的井。 Fixing the problem是一个更复杂的问题。

相关问题