更新:最后我终于想起来看看 munin,看来其中一个硬盘才是问题的根源,除非我完全读错了。以下是 munin 的输出:http://imagizer.imageshack.com/img536/1070/9d5c62.png。我的想法是对的,我的一个硬盘可能需要更换,或者是否有其他原因导致了这些 I/O 峰值?
我有一台非常强大的服务器(四核 i7,32GB RAM),在 LAMP 堆栈上运行 Drupal 7 网站(pixelscrapper.com),使用 Varnish、Memcached、APC、CloudFlare。我们每天的页面浏览量约为 20,000,通常该网站在 3-4 秒内即可加载经过身份验证的用户,总服务器时间约占其中的 0.5 秒,在 php 和 mysql 之间相当均匀地分配(因此每个请求在 mysql 中约占 0.2 秒)... 所有这些都是通过 New Relic(精简版,所以我看不到数据库跟踪)报告的。
页面加载时间为 3-4 秒,而 mysql 中为 0.2 秒,这种情况已经持续了几个月。
几天前,该网站的加载时间开始变长,查看 New Relic 后,我注意到 mysql 现在每个请求大约需要 2 秒,而不是 0.2 秒。这完全没有对网站进行任何重大更改...只是常规的网站使用情况。
所以我的问题是,什么原因可能突然导致 mysql 每个请求花费 2 秒而不是 0.2 秒,而站点没有部署任何更改,并且流量也没有发生重大变化?
我最好的直觉是,这可能是由于以下原因造成的:
- 根据 my.cnf 中当前的内存分配,某些表变得太大,或者总数据库变得太大,因此以前在内存中的内容现在正在冲击 HDD。
- 一些硬件问题,例如其中一个 HDD 出现问题导致磁盘访问速度很慢(我在 RAID 中有两个 HDD)。
问题是,根据对 mysqltuner 输出的观察,内存分配似乎没有问题,并且根据初始驱动器测试,硬盘似乎没有损坏......所以......
对于可能导致此类事件发生的原因,您有什么想法吗?我该如何解决此问题?
以下是 mysqltuner 的输出(mysql 运行了 98 天):
-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.5.28-0ubuntu0.12.04.2-log
[OK] Operating on 64-bit architecture
-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 88B (Tables: 10)
[--] Data in InnoDB tables: 1G (Tables: 582)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[!!] Total fragmented tables: 148
-------- Performance Metrics -------------------------------------------------
[--] Up for: 98d 2h 0m 34s (1B q [156.130 qps], 14M conn, TX: 3596B, RX: 225B)
[--] Reads / Writes: 72% / 28%
[--] Total buffers: 5.2G global + 3.1M per thread (300 max threads)
[OK] Maximum possible memory usage: 6.1G (19% of installed RAM)
[OK] Slow queries: 0% (32K/1B)
[OK] Highest usage of available connections: 37% (113/300)
[OK] Key buffer size / total MyISAM indexes: 128.0M/2.4M
[OK] Key buffer hit rate: 100.0% (35M cached / 545 reads)
[OK] Query cache efficiency: 71.4% (820M cached / 1B selects)
[!!] Query cache prunes per day: 43794
[OK] Sorts requiring temporary tables: 0% (15K temp sorts / 63M sorts)
[!!] Joins performed without indexes: 85938
[OK] Temporary tables created on disk: 1% (302K on disk / 17M total)
[OK] Thread cache hit rate: 99% (113K created / 14M connections)
[!!] Table cache hit rate: 13% (2K open / 19K opened)
[OK] Open file limit used: 0% (69/33K)
[OK] Table locks acquired immediately: 99% (529M immediate / 529M locks)
[OK] InnoDB data size / buffer pool: 1.5G/4.0G
-------- Recommendations -----------------------------------------------------
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
Increasing the query_cache size over 128M may reduce performance
Adjust your join queries to always utilize indexes
Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
query_cache_size (> 1G) [see warning above]
join_buffer_size (> 512.0K, or always use indexes with joins)
table_cache (> 16384)
这是我的.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 = 128M
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 = 300
table_cache = 16384
max_heap_table_size = 256M
join_buffer_size = 512K
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 4M
query_cache_size = 1024M
#
# * 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 = 3
#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!
#
innodb_file_per_table
innodb_buffer_pool_size = 4G
innodb_flush_method = O_DIRECT
# This is crucial to avoid checkpointing all the time:
innodb_log_file_size = 512M
# Lock wait timeout. See http://stackoverflow.com/questions/6000336/how-to-debug-lock-wait-timeout-exceeded
innodb_lock_wait_timeout = 120
# * 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/
这是我的慢查询日志:
答案1
试图对 sdb 运行 HDD 检查,但无法完成...(最初我以为我已经运行了完成的 HDD 检查,但我错误地认为我在测试 sdb,而实际上我正在测试 sda)。
因此,在这种情况下,我的问题的答案是检查 Munin,注意故障磁盘,并更换它。
一切都和现在一样。