mr.p3rfekt

Registered
Apr 1, 2022
2
0
1
turkey
cPanel Access Level
Root Administrator
Hello,

The SQL is always sucking the CPU at an average of 300% and sometimes it goes to 700%. Please advise.


Server specs:
Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz

Memory:
total used free shared buff/cache available
Mem: 65713840 6324576 30708140 53896 28681124 58795344
Swap: 33521660 16128 33505532
Total: 99235500 6340704 64213672


etc/my.cnf:

[mysqld]
log-error=/var/lib/mysql/host*.net.err
performance-schema=0
default-storage-engine=MyISAM
innodb_file_per_table=1
max_allowed_packet=2848578698
open_files_limit=100000

local-infile=0
connect_timeout=250
wait_timeout=300
interactive_timeout=300
slow-query-log=1
long_query_time=5
slow_query_log_file="mysql-slow.log"

sql_mode = ""
key_buffer_size = 128M
thread_stack = 128K
thread_cache_size = 8
max_heap_table_size = 256M
query_cache_limit = 4M
query_cache_size = 512M
innodb_buffer_pool_size = 2G




MySQLTuner 1.8.1 - Major Hayden <[email protected]>
>> Bug reports, feature requests, and downloads at http://mysqltuner.pl/
>> Run with '--help' for additional options and output filtering

[--] Skipped version check for MySQLTuner script
[!!] failed to execute: SHOW REPLICA STATUS\G
[!!] FAIL Execute SQL / return code: 256
[OK] Currently running supported MySQL version 10.3.34-MariaDB-log
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ------------------------------------------------------------------
[OK] Log file /var/lib/mysql/host.******.net.err exists
[--] Log file: /var/lib/mysql/host.******.net.err(73M)
[OK] Log file /var/lib/mysql/host.******.net.err is not empty
[!!] Log file /var/lib/mysql/host.******.net.err is bigger than 32 Mb
[OK] Log file /var/lib/mysql/host.******.net.err is readable.
[!!] /var/lib/mysql/host.******.net.err contains 6744 warning(s).
[!!] /var/lib/mysql/host.******.net.err contains 8604 error(s).
[--] 148 start(s) detected in /var/lib/mysql/host.******.net.err
[--] 1) 2022-03-31 15:03:42 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 2) 2022-03-30 12:19:26 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 3) 2022-03-29 16:35:34 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 4) 2022-03-29 16:31:16 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 5) 2022-03-29 15:16:41 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 6) 2022-03-22 22:50:23 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 7) 2022-03-18 17:49:44 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 8) 2022-03-16 10:35:49 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 9) 2022-03-14 11:43:00 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 10) 2022-03-12 10:47:27 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 38 shutdown(s) detected in /var/lib/mysql/host.******.net.err
[--] 1) 2022-03-31 15:03:41 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 2) 2022-03-30 12:19:24 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 3) 2022-03-29 16:35:33 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 4) 2022-03-29 16:31:14 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 5) 2022-03-29 15:16:39 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 6) 2022-03-22 22:50:22 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 7) 2022-03-18 17:49:43 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 8) 2022-02-13 21:30:40 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 9) 2022-02-13 21:30:37 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 10) 2022-02-09 21:30:41 0 [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.4G (Tables: 206)
[--] Data in InnoDB tables: 6.9G (Tables: 164)
[--] Data in MEMORY tables: 498.4K (Tables: 10)
[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
[!!] User 'memcache_test'@'localhost' has user name as password.
[!!] There is no basic password file list!

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

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 1d 0h 35m 58s (19M q [224.935 qps], 287K conn, TX: 4774G, RX: 2G)
[--] Reads / Writes: 97% / 3%
[--] Binary logging is disabled
[--] Physical Memory : 62.7G
[--] Max MySQL memory : 154.2G
[--] Other process memory: 0B
[--] Total buffers: 2.8G global + 1.0G per thread (151 max threads)
[--] P_S Max memory usage: 0B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 13.8G (22.04% of installed RAM)
[!!] Maximum possible memory usage: 154.2G (246.03% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[OK] Slow queries: 0% (0/19M)
[OK] Highest usage of available connections: 7% (11/151)
[OK] Aborted connections: 0.02% (59/287883)
[!!] 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: 37.6% (11M cached / 29M selects)
[!!] Query cache prunes per day: 463472
[OK] Sorts requiring temporary tables: 10% (127K temp sorts / 1M sorts)
[!!] Joins performed without indexes: 12927
[!!] Temporary tables created on disk: 38% (270K on disk / 708K total)
[OK] Thread cache hit rate: 99% (39 created / 287K connections)
[OK] Table cache hit rate: 99% (8M hits / 8M requests)
[!!] table_definition_cache(400) is lower than number of tables(647)
[OK] Open file limit used: 0% (484/100K)
[OK] Table locks acquired immediately: 99% (608K immediate / 608K 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: 16 thread(s).
[--] Using default value is good enough for your version (10.3.34-MariaDB-log)

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 55.3% (74M used / 134M cache)
[OK] Key buffer size / total MyISAM indexes: 128.0M/349.6M
[OK] Read Key buffer hit rate: 100.0% (512M cached / 48K reads)
[!!] Write Key buffer hit rate: 77.7% (46K cached / 35K writes)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[!!] InnoDB buffer pool / data size: 2.0G/6.9G
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (4.6875 %): 48.0M * 2/2.0G should be equal to 25%
[!!] InnoDB buffer pool instances: 8
[--] Number of InnoDB Buffer Pool Chunk : 16 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: 100.00% (65350991777 hits/ 65352444925 total)
[!!] InnoDB Write Log efficiency: 24.19% (87984 hits/ 363680 total)
[OK] InnoDB log waits: 0.00% (0 waits / 275696 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% (33M cached / 252K 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:
/var/lib/mysql/host.******.net.err is > 32Mb, you should analyze why or implement a rotation log strategy such as logrotate!
Control warning line(s) into /var/lib/mysql/host.******.net.err file
Control error line(s) into /var/lib/mysql/host.******.net.err file
Set up a Secure Password for 'memcache_test'@'localhost' user: SET PASSWORD FOR 'memcache_test'@'localhost' = PASSWORD('secure_password');
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
Increasing the query_cache size over 128M may reduce performance
We will suggest raising the 'join_buffer_size' until JOINs not using indexes are found.
See MySQL :: MySQL Internals Manual :: 10.5 How MySQL Uses the Join Buffer Cache
(specially the conclusions at the bottom of the page).
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
Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: MySQL :: MySQL 8.0 Reference Manual :: 15.6.5 Redo Log
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)
query_cache_size (> 512M) [see warning above]
join_buffer_size (> 256.0K, or always use indexes with JOINs)
tmp_table_size (> 16M)
max_heap_table_size (> 256M)
table_definition_cache(400) > 647 or -1 (autosizing if supported)
performance_schema = ON enable PFS
innodb_buffer_pool_size (>= 6.9G) if possible.
innodb_log_file_size should be (=256M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.
innodb_buffer_pool_instances(=2)
 
Last edited by a moderator:

kodeslogic

Well-Known Member
PartnerNOC
Apr 26, 2020
441
207
118
IN
cPanel Access Level
Root Administrator
Do you see any database appearing multiple times using the below command?

Code:
#mysqladmin proc stat
 

mr.p3rfekt

Registered
Apr 1, 2022
2
0
1
turkey
cPanel Access Level
Root Administrator
Do you see any database appearing multiple times using the below command?

Code:
#mysqladmin proc stat

YES I do see this:

[[email protected] ~]# mysqladmin proc stat
+--------+--------------+-----------+--------------+---------+------+--------------------------+------------------------------------------------------------------------------------------------------+----------+
| Id | User | Host | db | Command | Time | State | Info | Progress |
+--------+--------------+-----------+--------------+---------+------+--------------------------+------------------------------------------------------------------------------------------------------+----------+
| 1 | system user | | | Daemon | | InnoDB purge worker | | 0.000 |
| 2 | system user | | | Daemon | | InnoDB purge coordinator | | 0.000 |
| 3 | system user | | | Daemon | | InnoDB purge worker | | 0.000 |
| 4 | system user | | | Daemon | | InnoDB purge worker | | 0.000 |
| 5 | system user | | | Daemon | | InnoDB shutdown handler | | 0.000 |
| 400076 | halabtech_ar | localhost | HTT_ar | Query | 0 | Sending data | SELECT option_value FROM wp_options WHERE option_name = '_transient_global_styles_svg_filters_mharty | 0.000 |
| 400077 | HTT_ar | localhost | HTT_ar | Query | 0 | Sending data | SELECT option_value FROM wp_options WHERE option_name = 'mh_magazine_activated' LIMIT 1 | 0.000 |
| 400078 | HTT_ar | localhost | HTT_ar | Query | 0 | Sending data | SELECT option_value FROM wp_options WHERE option_name = 'mh_magazine_activated' LIMIT 1 | 0.000 |
| 400079 | HTT_ar | localhost | HTT_ar | Query | 0 | Sending data | SELECT option_value FROM wp_options WHERE option_name = 'fb_app_auth_token' LIMIT 1 | 0.000 |
| 400080 | HTT_ar | localhost | HTT_ar | Query | 0 | Sending data | SELECT option_value FROM wp_options WHERE option_name = 'fb_app_auth_token' LIMIT 1 | 0.000 |
| 400081 | root | localhost | | Query | 0 | Init | show processlist
 

kodeslogic

Well-Known Member
PartnerNOC
Apr 26, 2020
441
207
118
IN
cPanel Access Level
Root Administrator
The current output you shared looks normal, try the same command when CPU usage is 700% that time you will be able to detect/identify the database consuming high resources.
 
  • Like
Reactions: cPRex

anton_latvia

Well-Known Member
PartnerNOC
May 11, 2004
427
46
178
Latvia
cPanel Access Level
Root Administrator
I would change these settings in your my.cnf

query_cache_limit = 512Kb # no need to have it big. it will just eat all RAM with low efficiency
query_cache_size = 128M # of even 64M. Query cache gets really slow when it is bigger than 128Mb.
innodb_buffer_pool_size = 8G # you have enough RAM, let InnoDB use it.