Рекомендации по оптимизации MySQL - PullRequest
1 голос
/ 22 декабря 2019

У меня есть Directadmin / CentOS 7.0 Dedicate с 128 ГБ ОЗУ и 2x CPU 10 core 2.0 ГГц

Я запустил сценарий MySQLTuner и следовал приведенным рекомендациям, но он по-прежнему рекомендует увеличение, сообщая при этоммне, что максимальное использование памяти MySQL опасно высоко.

Моя текущая конфигурация в моем файле my.cnf:

>>  MySQLTuner 1.7.19 - Major Hayden <major@mhtx.net>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering

[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 10.4.11-MariaDB
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ------------------------------------------------------------------
[OK] Log file /var/log/mysql.log exists
[--] Log file: /var/log/mysql.log(0B)
[OK] Log file /var/log/mysql.log is readable.
[!!] Log file /var/log/mysql.log is empty
[OK] Log file /var/log/mysql.log is smaller than 32 Mb
[OK] /var/log/mysql.log doesn't contain any warning.
[OK] /var/log/mysql.log doesn't contain any error.
[--] 0 start(s) detected in /var/log/mysql.log
[--] 0 shutdown(s) detected in /var/log/mysql.log

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +Aria +CSV +InnoDB +MEMORY +MRG_MyISAM +MyISAM +PERFORMANCE_SCHEMA +SEQUENCE
[--] Data in MyISAM tables: 426.0M (Tables: 34)
[--] Data in InnoDB tables: 175.6M (Tables: 29)
[OK] Total fragmented tables: 0

-------- Analysis Performance Metrics --------------------------------------------------------------
[--] innodb_stats_on_metadata: OFF
[OK] No stat updates during querying INFORMATION_SCHEMA.

-------- Security Recommendations ------------------------------------------------------------------
[OK] There are no anonymous accounts for any database users
[OK] All database users have passwords assigned
[!!] There is no basic password file list!

-------- CVE Security Recommendations --------------------------------------------------------------
[--] Skipped due to --cvefile option undefined

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 22m 0s (2M q [2K qps], 3K conn, TX: 2G, RX: 317M)
[--] Reads / Writes: 99% / 1%
[--] Binary logging is disabled
[--] Physical Memory     : 125.7G
[--] Max MySQL memory    : 131098.3G
[--] Other process memory: 0B
[--] Total buffers: 15.6G global + 32.0G per thread (4096 max threads)
[--] P_S Max memory usage: 0B
[--] Galera GCache Max memory usage: 0B
[!!] Maximum reached memory usage: 271.7G (216.19% of installed RAM)
[!!] Maximum possible memory usage: 131098.3G (104328.03% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[OK] Slow queries: 0% (0/2M)
[OK] Highest usage of available connections: 0% (8/4096)
[OK] Aborted connections: 0.00%  (0/3914)
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
[!!] Query cache may be disabled by default due to mutex contention.
[OK] Query cache efficiency: 48.9% (2M cached / 5M selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 43K sorts)
[!!] Joins performed without indexes: 415
[!!] Temporary tables created on disk: 64% (8K on disk / 12K total)
[OK] Thread cache hit rate: 99% (8 created / 3K connections)
[OK] Table cache hit rate: 96% (187 open / 193 opened)
[OK] table_definition_cache(400) is upper than number of tables(329)
[OK] Open file limit used: 0% (148/20K)
[OK] Table locks acquired immediately: 99% (70K immediate / 70K locks)

-------- Performance schema ------------------------------------------------------------------------
[--] Performance schema is disabled.
[--] Memory used by P_S: 0B
[--] Sys schema is installed.

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is enabled.
[--] Thread Pool Size: 40 thread(s).
[--] Using default value is good enough for your version (10.4.11-MariaDB)

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 23.4% (125M used / 536M cache)
[OK] Key buffer size / total MyISAM indexes: 512.0M/53.6M
[OK] Read Key buffer hit rate: 100.0% (121M cached / 27K reads)
[OK] Write Key buffer hit rate: 99.8% (636 cached / 635 writes)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 8.0G/175.6M
[OK] Ratio InnoDB log file size / InnoDB Buffer pool size: 1.0G * 2/8.0G should be equal to 25%
[OK] InnoDB buffer pool instances: 8
[--] Number of InnoDB Buffer Pool Chunk : 64 for 8 Buffer Pool Instance(s)
[OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances
[OK] InnoDB Read buffer efficiency: 99.99% (58380753 hits/ 58389392 total)
[!!] InnoDB Write Log efficiency: 125.23% (139 hits/ 111 total)
[OK] InnoDB log waits: 0.00% (0 waits / 250 writes)

-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is enabled.
[OK] Aria pagecache size / total Aria indexes: 128.0M/368.0K
[OK] Aria pagecache hit rate: 97.7% (357K cached / 8K reads)

-------- TokuDB Metrics ----------------------------------------------------------------------------
[--] TokuDB is disabled.

-------- XtraDB Metrics ----------------------------------------------------------------------------
[--] XtraDB is disabled.

-------- Galera Metrics ----------------------------------------------------------------------------
[--] Galera is disabled.

-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] Binlog format: MIXED
[--] XA support enabled: ON
[--] Semi synchronous replication Master: OFF
[--] Semi synchronous replication Slave: OFF
[--] This is a standalone server

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
    MySQL was started within the last 24 hours - recommendations may be inaccurate
    Reduce your overall MySQL memory footprint for system stability
    Dedicate this server to your database for highest performance.
    Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
    We will suggest raising the 'join_buffer_size' until JOINs not using indexes are found.
             See https://dev.mysql.com/doc/internals/en/join-buffer-size.html
             (specially the conclusions at the bottom of the page).
    Temporary table size is already large - reduce result set size
    Reduce your SELECT DISTINCT queries without LIMIT clauses
    Performance schema should be activated for better diagnostics
Variables to adjust:
  *** MySQL's maximum memory usage is dangerously high ***
  *** Add RAM before increasing MySQL buffer variables ***
    query_cache_size (=0)
    query_cache_type (=0)
    join_buffer_size (> 32.0G, or always use indexes with JOINs)
    performance_schema = ON enable PFS

и это my.cnf config

# include all files from the config directory
#
!includedir /etc/my.cnf.d

[mysqld]
max_connections = 4096
key_buffer_size = 512M
max_allowed_packet = 1024M
query_cache_limit = 256M
query_cache_size = 5G
query_cache_type = 1
innodb_log_file_size=1G
innodb_buffer_pool_size=8G
max_heap_table_size=2G
join_buffer_size=32G
tmp_table_size=2G
thread_cache_size=512

Кто-нибудь есть какие-либо рекомендации, что делать сейчас?

Ответы [ 2 ]

1 голос
/ 22 декабря 2019

join_buffer_size=32G мне кажется высоким и, вероятно, является причиной предупреждения о памяти, особенно учитывая max_connections = 4096, и MySQLTuner в основном умножает эти два числа для оценки потребления памяти. Я думаю, что max_connections также высоко и далеко не соответствует тому, что требуется в соответствии с информацией, предоставленной прямо сейчас, см. Highest usage of available connections: 0% (8/4096).

MySQLTuner дает некоторые советы относительно улучшения запросов, которым я бы следовал в первую очередь. (Убедитесь, что JOIN-файлы используют индексы, уменьшите размер набора результатов,…)

После этого перезапустите сервер и дайте ему поработать в течение 24 часов. Затем снова запустите MySQLTuner, чтобы получить новые рекомендации.

0 голосов
/ 22 декабря 2019

Предложение для вашего раздела my.cnf [mysqld]

max_connections = 256
key_buffer_size = 192M
max_allowed_packet = 1024M
query_cache_limit = 1M
query_cache_size = 96M
query_cache_type = 1
queyr_cache_min_res_unit=512
innodb_log_file_size=1G
innodb_log_buffer_size=512M
innodb_buffer_pool_size=1G
max_heap_table_size=64M
join_buffer_size=256K
tmp_table_size=64M
thread_cache_size=256
performance_schema=ON
skip_name_resolve=1

Эти изменения значительно уменьшат максимально возможное использование памяти в 131 терабайт, рассчитанное MySQLTuner, и уменьшат нагрузку на ЦП при сообщении TOP.

Отказ от ответственности: я являюсь автором контента веб-сайта, упомянутого в моем профиле, сетевом профиле, где у нас есть загружаемые БЕСПЛАТНЫЕ служебные скрипты для помощи в настройке производительности, часто задаваемые вопросы и контактная информация.

...