MySQL突然每个请求2000毫秒,而不是200

更新 :终于想起来看看慕尼黑,似乎硬盘之一是问题的根源毕竟,除非我完全读这个错误。 这是munin输出: http : //imagizer.imageshack.com/img536/1070/9d5c62.png 。 我是否正确地认为我的一个硬盘可能需要更换,或者其他的东西能解决那些I / O尖峰?



我有一个非常强大的服务器(四核i7,32GB RAM),在LAMP堆栈上运行Drupal 7网站(pixelscrapper.com),利用Varnish,Memcached,APC和CloudFlare。 我们每天获得大约2万次网页浏览量,通常这个网站已经在3-4秒内为authentication用户加载,服务器总时间约为0.5秒,在php和mysql之间平均分配(大约0.2秒在MySQL每个请求)…所有通过New Relic(精简版,所以我不能看到数据库跟踪)报告。

3-4秒的页面加载时间,在MySQL中0.2秒已经持续了好几个月。

然后几天前,该网站开始花费更多的时间来加载,并看看新的遗物,我注意到,MySQL现在每个请求大约2秒,而不是0.2秒。 这是没有任何重大的网站改变…只是定期的网站使用。

所以我的问题是,什么可能突然导致MySQL花费2秒每个请求,而不是0.2秒,没有变化部署到网站,并没有重大的stream量变化?

我的最好的直觉是,这可能是由以下原因造成的:

  1. 根据my.cnf中当前的内存分配情况,某些表增长过大,或者总的db增长过大,所以以前在内存中的内存现在正在抖动硬盘。
  2. 某些硬件问题,如导致磁盘访问的其中一个HDD出现问题(我在RAID中有两个HDD)。

关键是,基于看mysqltuner输出,内存分配似乎是好的,基于初步的驱动器testing,硬盘似乎不会被打破…所以…

有什么想法可能会导致这样的事情发生,我应该如何解决这个问题?

这里的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) 

这是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 = 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/ 

这是我的慢查询日志:


https://gist.github.com/JordanMagnuson/68e3ab30ff9b6ccc5a96

试图在sdb上运行硬盘检查,这不会完成…(最初我以为我已经运行了一个硬盘检查完成,但我错误地认为我正在testingsdb时,实际上是testingsda)。

所以在这种情况下,我的问题的答案是检查穆宁,注意颠簸(失败)的磁盘,并取而代之。

一切都如现在一样。