Mysql

MySQL 最大可能的記憶體使用量高於已安裝的 RAM

  • September 24, 2017

我正在使用 debian 8 Jessie 和 MariaDB。我的 mysqltuner 似乎表明 MariaDB 可以使用 142% 的 RAM:

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +ARCHIVE +Aria +BLACKHOLE +CSV +FEDERATED +InnoDB +MRG_MyISAM 
[--] Data in InnoDB tables: 2G (Tables: 79)
[--] Data in MyISAM tables: 96M (Tables: 146)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 52)
[!!] Total fragmented tables: 34

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

-------- Performance Metrics -------------------------------------------------
[--] Up for: 1d 16h 44m 38s (73M q [502.853 qps], 196K conn, TX: 572B, RX: 14B)
[--] Reads / Writes: 97% / 3%
[--] Total buffers: 17.3G global + 56.2M per thread (500 max threads)
[!!] Maximum possible memory usage: 44.8G (142% of installed RAM)
[OK] Slow queries: 0% (2K/73M)
[OK] Highest usage of available connections: 28% (141/500)
[OK] Key buffer size / total MyISAM indexes: 1.0G/32.6M
[OK] Key buffer hit rate: 100.0% (132M cached / 53K reads)
[OK] Query cache efficiency: 44.9% (50M cached / 113M selects)
[!!] Query cache prunes per day: 260596
[OK] Sorts requiring temporary tables: 0% (2K temp sorts / 2M sorts)
[OK] Temporary tables created on disk: 21% (6K on disk / 28K total)
[OK] Thread cache hit rate: 99% (141 created / 196K connections)
[OK] Table cache hit rate: 72% (500 open / 692 opened)
[OK] Open file limit used: 17% (429/2K)
[OK] Table locks acquired immediately: 99% (25M immediate / 25M locks)
[OK] InnoDB buffer pool / data size: 16.0G/2.4G
[!!] InnoDB log waits: 30

innodb_buffer_pool_size的是 16Go,對於 32Go RAM 應該沒問題,我不知道該怎麼做才能優化它。

問題是,我在伺服器中的記憶體一般使用率始終低於 89%(加上記憶體)。MariaDB 實際上使用了 50.6% 的 RAM。

這是我調整的 my.cnf 中的主要變數,可能會對此產生影響:

max_connections = 100
max_heap_table_size = 64M
read_buffer_size = 4M
read_rnd_buffer_size = 32M
sort_buffer_size = 8M
query_cache_size = 256M
query_cache_limit = 4M
query_cache_type = 1
query_cache_strip_comments =1
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 64M
nnodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 16G
thread_cache_size   = 4M
max_connections     = 500
join_buffer_size    = 12M
interactive_timeout = 30
wait_timeout        = 30
open_files_limit    = 800
innodb_file_per_table
key_buffer_size     = 1G
table_open_cache    = 500
innodb_log_file_size    = 256M

我的配置有問題嗎?

通過從您的 my.cnf 中刪除以下內容以允許預設值為您的系統服務,可以進一步減少記憶體佔用。

sort_buffer_size
read_buffer_size
read_rnd_buffer_size
join_buffer_size

考慮在 my.cnf 中更改或添加以下內容

key_buffer_size = 164M   # you already have 132m cached per MySqlTuner
thread_cache_size = 100  # CAP suggested in 8.0 to avoid overload 

在 1 天 16 小時的正常執行時間內,創建了 141 個執行緒來服務 196K 連接。這將降低用於創建/斷開連接的高 CPU 使用率。

現在將 innodb_buffer_pool_size 保持在 16G 就可以了,因為每個 MySQLTuner 只有 2.4G 的數據。

SEO DEVS 推薦的其他項目都超級棒。

使用 mysqlcalculator.com 快速檢查大致的 RAM 使用率

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