针对 Woocommerce 商店的 MariaDB 优化,即将有超过 55,000 种商品在售

问题描述

我提前感谢您对此的帮助。我有一个具有以下规格的 VPS:

操作系统:Centos 7.x cpu型号:普通KVM处理器 cpu 详细信息:6 核(2200 MHz) 发行版名称:CentOS Linux release 7.9.2009 (Core) Kernel 版本:3.10.0-1160.25.1.el7.x86_64 数据库:服务器类型:MariaDB 服务器版本:10.2.38-MariaDB - MariaDB 服务器

这里是 mu sqltuner 输出,让它在 48 小时和正常运行时间后运行。

>>  MysqLTuner 1.7.21 - Major Hayden <major@mhtx.net>
 >>  Bug reports,feature requests,and downloads at 
 >>  Run with '--help' for additional options and output filtering

[--] Skipped version check for MysqLTuner script
[OK] Currently running supported MysqL version 10.2.38-MariaDB
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ------------------------------------------------------------------
[OK] Log file /var/lib/MysqL/MysqL_error.log exists
[--] Log file: /var/lib/MysqL/MysqL_error.log(61K)
[OK] Log file /var/lib/MysqL/MysqL_error.log is not empty
[OK] Log file /var/lib/MysqL/MysqL_error.log is smaller than 32 Mb
[OK] Log file /var/lib/MysqL/MysqL_error.log is readable.
[!!] /var/lib/MysqL/MysqL_error.log contains 102 warning(s).
[!!] /var/lib/MysqL/MysqL_error.log contains 207 error(s).
[--] 6 start(s) detected in /var/lib/MysqL/MysqL_error.log
[--] 1) 2021-02-09  6:43:49 139979222657216 [Note] /usr/sbin/MysqLd: ready for connections.
[--] 2) 2021-02-09  6:42:32 140586002757824 [Note] /usr/sbin/MysqLd: ready for connections.
[--] 3) 2021-02-09  6:39:56 139691500861632 [Note] /usr/sbin/MysqLd: ready for connections.
[--] 4) 2021-02-08 16:40:22 139959792539840 [Note] /usr/sbin/MysqLd: ready for connections.
[--] 5) 2021-02-08 16:18:40 139803044288704 [Note] /usr/sbin/MysqLd: ready for connections.
[--] 6) 2021-02-08 15:07:22 140335421376704 [Note] /usr/sbin/MysqLd: ready for connections.
[--] 6 shutdown(s) detected in /var/lib/MysqL/MysqL_error.log
[--] 1) 2021-02-09  7:05:42 139975468152576 [Note] /usr/sbin/MysqLd: Shutdown complete
[--] 2) 2021-02-09  6:43:47 140582005065472 [Note] /usr/sbin/MysqLd: Shutdown complete
[--] 3) 2021-02-09  6:42:31 139687510402816 [Note] /usr/sbin/MysqLd: Shutdown complete
[--] 4) 2021-02-09  6:39:54 139955810617088 [Note] /usr/sbin/MysqLd: Shutdown complete
[--] 5) 2021-02-08 16:40:20 139799045744384 [Note] /usr/sbin/MysqLd: Shutdown complete
[--] 6) 2021-02-08 16:18:38 140331682969344 [Note] /usr/sbin/MysqLd: Shutdown complete

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +Aria +CSV +InnoDB +MEMORY +MRG_MyISAM +MyISAM +PERFORMANCE_SCHEMA +SEQUENCE
[--] Data in MyISAM tables: 1.8M (Tables: 31)
[--] Data in InnoDB tables: 2.5G (Tables: 118)
[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: 2d 8h 26m 4s (28M q [140.461 qps],115K conn,TX: 1056G,RX: 12G)
[--] Reads / Writes: 97% / 3%
[--] Binary logging is disabled
[--] Physical Memory     : 7.6G
[--] Max MysqL memory    : 9.1G
[--] Other process memory: 0B
[--] Total buffers: 6.3G global + 18.9M per thread (151 max threads)
[--] P_S Max memory usage: 0B
[--] galera GCache Max memory usage: 0B
[!!] Maximum reached memory usage: 6.9G (89.75% of installed RAM)
[!!] Maximum possible memory usage: 9.1G (118.77% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[OK] Slow queries: 0% (4/28M)
[OK] Highest usage of available connections: 20% (31/151)
[!!] Aborted connections: 3.23%  (3732/115532)
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
[OK] Query cache is disabled by default due to mutex contention on multiprocessor machines.
[OK] Sorts requiring temporary tables: 0% (6K temp sorts / 4M sorts)
[OK] No joins without indexes
[!!] Temporary tables created on disk: 84% (2M on disk / 3M total)
[OK] Thread cache hit rate: 99% (31 created / 115K connections)
[OK] Table cache hit rate: 88% (254 open / 286 opened)
[OK] table_deFinition_cache(400) is upper than number of tables(307)
[OK] Open file limit used: 0% (72/32K)
[OK] Table locks acquired immediately: 99% (59K immediate / 59K locks)

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

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

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 18.9% (25M used / 134M cache)
[OK] Key buffer size / total MyISAM indexes: 128.0M/988.0K
[OK] Read Key buffer hit rate: 98.6% (55K cached / 804 reads)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 3
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 6.0G/2.5G
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (1.5625 %): 48.0M * 2/6.0G should be equal to 25%
[OK] InnoDB buffer pool instances: 6
[--] Number of InnoDB Buffer Pool Chunk : 48 for 6 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: 100.00% (8044167577 hits/ 8044254584 total)
[OK] InnoDB Write log efficiency: 97.32% (16217444 hits/ 16663260 total)
[OK] InnoDB log waits: 0.00% (0 waits / 445816 writes)

-------- Aria Metrics ------------------------------------------------------------------------------
[--] Aria Storage Engine is enabled.
[OK] Aria pagecache size / total Aria indexes: 128.0M/0B
[OK] Aria pagecache hit rate: 99.3% (152M cached / 1M 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: Not Activated
[--] Semi synchronous replication Slave: Not Activated
[--] This is a standalone server

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
    Control warning line(s) into /var/lib/MysqL/MysqL_error.log file
    Control error line(s) into /var/lib/MysqL/MysqL_error.log file
    Reduce your overall MysqL memory footprint for system stability
    Dedicate this server to your database for highest performance.
    Reduce or eliminate unclosed connections and network issues
    Configure your accounts with ip or subnets only,then update your configuration with skip-name-resolve=1
    When making adjustments,make tmp_table_size/max_heap_table_size equal
    Reduce your SELECT disTINCT queries which have no LIMIT clause
    Performance schema should be activated for better diagnostics
    Consider installing Sys schema from https://github.com/MysqL/MysqL-sys for MysqL
    Consider installing Sys schema from https://github.com/FromDual/mariadb-sys for MariaDB
    Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: 
Variables to adjust:
  *** MysqL's maximum memory usage is dangerously high ***
  *** Add RAM before increasing MysqL buffer variables ***
    tmp_table_size (> 16M)
    max_heap_table_size (> 16M)
    performance_schema = ON enable PFS
    innodb_log_file_size should be (=768M) if possible,so InnoDB total log files size equals to 25% of buffer pool size.
[root@vps1-tunershop ~]

现在,我想说我使用WP All Import将产品注入网站。我从 cronjobs 开始导入,我每天晚上运行 3 或 4 个来更新库存并删除不再是报价的一部分的产品。当这些导入运行时,我的 cpu 利用率为 70 - 80%。我想确保我的数据库不是这里的罪魁祸首,因此感谢您的帮助。请在下面找到 mariadb 的 my.conf。

#
# This group is read both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include *.cnf from the config directory
#
!includedir /etc/my.cnf.d
#My Settings below

[MysqLd]

#innodb setttings
default-storage-engine = innodb
innodb_buffer_pool_size = 6G         #folosim cam 70% 80% din ram-ii valabili
innodb_buffer_pool_instances    = 6
innodb_thread_concurrency = 3  #limiteaza numarul procesoarelor pe care lucreaza DB-ul astfel reducand impactul la procesor
innodb_temp_data_file_path     = ibtmp1:64M:autoextend:max:10G # seteaza marimea si cat se extinde tabelele create temporar.

innodb_file_per_table = 1
innodb_flush_method             = O_DIRECT

提前感谢您的帮助。

自从最初提出问题以来,在对数据库优化进行了一些研究后,我偶然发现了 my.conf 文件。这是更新后的 my.conf 文件

# This group is read both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include *.cnf from the config directory
#
!includedir /etc/my.cnf.d
#My Settings below

[MysqLd]

skip-name-resolve                             # Skip reverse DNS lookup - recomandare de la sqltuner apreciata de forumuri ***
tmp_table_size = 64M                              #recomandat de MysqLtuner la mai mult de 16. incercam cu 64
max_heap_table_size = 64M                   #recomandat de MysqLtuner la mai mult de 16. incercam cu 64

#dam DRUMUL LA PERFORMANCE SCHEMA PENTRU UN DIAGNOSTIC MAI BUN AL sqlTUNER

performance_schema=ON
performance-schema-instrument='stage/%=ON'
performance-schema-consumer-events-stages-current=ON
performance-schema-consumer-events-stages-history=ON
performance-schema-consumer-events-stages-history-long=ON

innodb_log_file_size = 768M # recomandare de la MysqLtuner


#RATES PER SECOND OPTIMISATION FROM https://dba.forumming.com/question/5688/help-with-MysqL-39-s-maximum-memory-usage-which-is-dangerously-high

join_buffer_size=256K  # from 140M for row pointers
thread_cache_size=40  # from 8 to avoid thread starvation
query_cache_limit=0  # from 4M since you have QC turned OFF
innodb_lru_scan_depth=100  # from 1024 to reduce cpu busy every SECOND
key_cache_age_threshold=7200  # from 300 seconds to reduce key_reads RPS
key_cache_division_limit=50  # from 100 percent for HOT/WARM caches
key_cache_block_size=16K  # from 1K to evict bigger block when full
open_files_limit=30000  # from 1024 to reduce opened_files RPS
table_open_cache=10000  # from 407 to reduce opened_tables RPS
table_deFinition_cache=2000  # from 603 to reduce opened_table_deFinitions RPS

#Altele la fel de importante care sunt foarte bune de folosit. Alea comentate nu sunt sigur de ele

#basedir                         = /usr
bind_address               = 127.0.0.1 # Change to 0.0.0.0 to allow remote connections
datadir                          = /var/lib/MysqL
max_allowed_packet              = 256M
max_connect_errors              = 1000000
skip_external_locking

#innodb setttings

default-storage-engine = innodb
innodb_buffer_pool_size = 6G         #folosim cam 70% 80% din ram-ii valabili
innodb_buffer_pool_instances    = 6
innodb_thread_concurrency = 3  #limiteaza numarul procesoarelor pe care lucreaza DB-ul astfel reducand impactul la procesor
innodb_temp_data_file_path     = ibtmp1:64M:autoextend:max:10G # seteaza marimea si cat se extinde tabelele create temporar.

innodb_file_per_table = 1
innodb_flush_method             = O_DIRECT

innodb_flush_log_at_trx_commit  = 0
innodb_log_buffer_size          = 16M
innodb_stats_on_Metadata        = 0

#innodb_thread_concurrency      = 6    # Optional: Set to the number of cpus on your system (minus 1 or 2) to better
                                        # contain cpu usage. E.g. if your system has 8 cpus,try 6 or 7 and check
                                        # the overall load produced by MysqL/MariaDB.
innodb_read_io_threads          = 64
innodb_write_io_threads         = 64
#innodb_io_capacity             = 1000  # Max is 2000

## CONNECTION SETTINGS
max_connections                 = 100   # UPD - Important: high no. of connections = high RAM consumption

back_log                        = 512
thread_cache_size               = 100
thread_stack                    = 192K

interactive_timeout             = 180
wait_timeout                    = 180

# BUFFER SETTINGS

innodb_sort_buffer_size         = 2M    # Trebuie retestat
join_buffer_size                = 4M    # Trebuie retestat
read_buffer_size                = 3M    # Trebuie retestat
read_rnd_buffer_size            = 4M    # Trebuie retestat
sort_buffer_size                = 4M    # Trebuie retestat

# === Search Settings ===

ft_min_word_len                 = 3     # Minimum length of words to be indexed for search results

解决方法

内存分配规则。

  • 不要分配过多的 RAM,以免发生交换。交换对于 MySQL/MariaDB 性能来说很糟糕。
  • 一定要调整 innodb_buffer_pool_size 以便大部分 RAM 在正常时间使用,甚至在活动高峰期也是如此。 (我经常说“将其设置为可用 RAM 的 70%”,但您要求了解更多详细信息。)
  • 不要打扰更改其他设置;它们增加了“正确处理”的复杂性。

有3种情况(根据innodb_buffer_pool_size和dataset size):

  • 微小的数据集 -- buffer_pool 比必要的大 --> 浪费了一些 RAM,但那又怎样;它对其他任何事情都没有用。它为您提供了一些成长空间。
  • 中型数据集——大多数活动在 RAM 中完成;系统将运行良好。
  • 大数据集 -- 系统可能受 I/O 限制。添加 RAM 是一种昂贵且暴力的解决方案。但是,某些软件技术(例如,更好的索引)可能会有所帮助,例如适用于 WordPress 和 WooCommerce 的 this

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...