and I appreciate in advance for your help on this. I have a VPS with the following specs:
OS: Centos 7.x CPU Model: Common KVM processor CPU Details: 6 Core(2200 MHz) Distro Name: CentOS Linux release 7.9.2009 (Core) Kernel Version: 3.10.0-1160.25.1.el7.x86_64 Database: Server type: MariaDB Server version: 10.2.38-MariaDB - MariaDB Server
And here is mu sqltuner output from letting it run after 48 hours and uptime.
>> 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 ~]
Now, I want to say that I use WP All Import to inject products into the site. I start imports with cronjobs, and I have 3 or 4 that run every night to update the stock and delete the products that are no longer part of the offer. When these imports run, my CPU utilisation is at 70 - 80%. I want to make sure my DB is not the culprit here, so any help is appreciated. Below please find my.conf for mariadb.
#
# 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
Thank you for the help in advance.
Since the initial question, I had chanced the my.conf file a little after I did some research into DB Optimization. Here is the updated my.conf file:
# 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
Rules for memory allocation.
innodb_buffer_pool_size
such that most of RAM is in use during normal time and even for spikes in activity. (I often say "set it to 70% of available RAM", but you are asking for more details.)There are 3 situations (based on innodb_buffer_pool_size and dataset size):