Optimization

MysqlTunner 和 query_cache_size 的困境

  • October 13, 2012

在繁忙的 mysql 伺服器上 MySQLTuner 1.2.0 總是建議添加 query_cache_size 無論我如何增加值(我嘗試了高達 512MB)。另一方面,它警告說:

Increasing the query_cache size over 128M may reduce performance

這是最後的結果:

>>  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.5.25-1~dotdeb.0-log
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster 
[--] Data in InnoDB tables: 6G (Tables: 195)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[!!] Total fragmented tables: 51

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

-------- Performance Metrics -------------------------------------------------
[--] Up for: 1d 19h 17m 8s (254M q [1K qps], 5M conn, TX: 139B, RX: 32B)
[--] Reads / Writes: 89% / 11%
[--] Total buffers: 24.2G global + 92.2M per thread (1200 max threads)
[!!] Maximum possible memory usage: 132.2G (139% of installed RAM)
[OK] Slow queries: 0% (2K/254M)
[OK] Highest usage of available connections: 32% (391/1200)
[OK] Key buffer size / total MyISAM indexes: 128.0M/92.0K
[OK] Key buffer hit rate: 100.0% (8B cached / 0 reads)
[OK] Query cache efficiency: 79.9% (181M cached / 226M selects)
[!!] Query cache prunes per day: 1033203
[OK] Sorts requiring temporary tables: 0% (341 temp sorts / 4M sorts)
[OK] Temporary tables created on disk: 14% (760K on disk / 5M total)
[OK] Thread cache hit rate: 99% (676 created / 5M connections)
[OK] Table cache hit rate: 22% (1K open / 8K opened)
[OK] Open file limit used: 0% (49/13K)
[OK] Table locks acquired immediately: 99% (64M immediate / 64M locks)
[OK] InnoDB data size / buffer pool: 6.1G/19.5G

-------- Recommendations -----------------------------------------------------
General recommendations:
   Run OPTIMIZE TABLE to defragment tables for better performance
   Reduce your overall MySQL memory footprint for system stability
   Increasing the query_cache size over 128M may reduce performance
Variables to adjust:
 *** MySQL's maximum memory usage is dangerously high ***
 *** Add RAM before increasing MySQL buffer variables ***
   query_cache_size (> 192M) [see warning above]

該伺服器具有 76GB 記憶體和雙 E5-2650。負載通常低於 2。感謝您解釋建議和優化數據庫配置的提示。

MySQL Query Cache Sizing是一個您可能會發現有用的部落格條目。

一個高級總結是,一旦 query_cache 超過一定大小,MySQL 管理記憶體的時間就會比使用記憶體的時間多。每次影響查詢結果的寫入都會使記憶體中的結果無效。

如果您的應用程序主要讀取數據庫,那麼較大的查詢記憶體大小將是有益的。如果您的應用程序是寫繁重的,您將受益於較低的記憶體或根本沒有記憶體。

請注意,還有許多其他部落格文章討論了較大的 query_cache 大小,但最後他們都說您必須在您的環境中實際測試設置以獲得最佳設置。

引用自:https://serverfault.com/questions/437072