我正在使用 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
我的配置有什么不正确吗?
答案1
通过从 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 利用率
答案2
您已过度设置,并且 SQL 数据库设置为可能过载,而且您有一个重复的最大连接。对于 32gb 服务器,my.cnf 应该更像这样。更改您的设置以匹配以下设置。
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
max_connections = 250
table_cache = 4K
wait_timeout = 1200
query_cache_limit = 1M
query_cache_size = 128M
join_buffer_size = 2M
expire_logs_days = 10
max_binlog_size = 100M
innodb_buffer_pool_size = 26G
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
希望这可以帮助