RhymeGuy

Registered
Oct 7, 2019
2
0
1
San Jose
cPanel Access Level
Root Administrator
Hi!

Using top -c I have noticed high mysqld usage

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
17397 mysql 20 0 1508216 233996 3408 S 159.2 12.4 26:12.56 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid


This is output of mysqltuner.pl script:

Code:
[[email protected] ~]# ./mysqltuner.pl
 >>  MySQLTuner 1.7.19 - Major Hayden <[email protected]>
 >>  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 5.7.27
[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: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA
[--] Data in MyISAM tables: 17.1M (Tables: 363)
[--] Data in InnoDB tables: 49.2M (Tables: 490)
[--] Data in MEMORY tables: 0B (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
[!!] There is no basic password file list!
 
-------- CVE Security Recommendations --------------------------------------------------------------
[--] Skipped due to --cvefile option undefined
 
-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 4m 37s (59K q [216.065 qps], 59 conn, TX: 105M, RX: 155M)
[--] Reads / Writes: 99% / 1%
[--] Binary logging is disabled
[--] Physical Memory     : 1.8G
[--] Max MySQL memory    : 338.9M
[--] Other process memory: 0B
[--] Total buffers: 169.0M global + 1.1M per thread (151 max threads)
[--] P_S Max memory usage: 0B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 174.6M (9.50% of installed RAM)
[OK] Maximum possible memory usage: 338.9M (18.44% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available
[OK] Slow queries: 0% (0/59K)
[OK] Highest usage of available connections: 3% (5/151)
[!!] Aborted connections: 3.39%  (2/59)
[!!] 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.
[!!] Query cache efficiency: 0.0% (0 cached / 59K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (7 temp sorts / 9K sorts)
[OK] No joins without indexes
[!!] Temporary tables created on disk: 32% (939 on disk / 2K total)
[OK] Thread cache hit rate: 91% (5 created / 59 connections)
[OK] Table cache hit rate: 93% (824 open / 880 opened)
[OK] table_definition_cache(1400) is upper than number of tables(1142)
[OK] Open file limit used: 6% (698/10K)
[OK] Table locks acquired immediately: 100% (75K immediate / 75K locks)
 
-------- Performance schema ------------------------------------------------------------------------
[--] Performance schema is disabled.
[--] Memory used by P_S: 0B
[--] Sys schema is installed.
 
-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is disabled.
 
-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 29.4% (2M used / 8M cache)
[OK] Key buffer size / total MyISAM indexes: 8.0M/6.1M
[OK] Read Key buffer hit rate: 99.9% (696K cached / 920 reads)
 
-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 128.0M/49.2M
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (75 %): 48.0M * 2/128.0M should be equal to 25%
[OK] InnoDB buffer pool instances: 1
[--] Number of InnoDB Buffer Pool Chunk : 1 for 1 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.83% (442047 hits/ 442796 total)
[!!] InnoDB Write Log efficiency: 79.72% (448 hits/ 562 total)
[OK] InnoDB log waits: 0.00% (0 waits / 114 writes)
 
-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is disabled.
 
-------- 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: ROW
[--] XA support enabled: ON
[--] Semi synchronous replication Master: Not Activated
[--] Semi synchronous replication Slave: Not Activated
[--] This is a standalone server
 
-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
    MySQL was started within the last 24 hours - recommendations may be inaccurate
    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
    Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: https://bit.ly/2TcGgtU
Variables to adjust:
    query_cache_size (=0)
    query_cache_type (=0)
    query_cache_limit (> 1M, or use smaller result sets)
    tmp_table_size (> 16M)
    max_heap_table_size (> 16M)
    performance_schema = ON enable PFS
    innodb_log_file_size should be (=16M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.
File /etc/my.cnf contains:
Code:
[mysqld]
performance-schema=0
default-storage-engine=MyISAM
innodb_file_per_table=1
[mysqld]
performance-schema=0
What should I do to optimize this?
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
14,307
2,238
363
cPanel Access Level
Root Administrator
Hello there, @RhymeGuy,

One of my favorite ways to see MySQL usage on a machine is to run this command:

mysqladmin proc status

as this will show you the user running the command, how long it has been running, the database, and the query. It will also give you a summary of what MySQL doing, including how many queries per second are being run and how many open tables there are, which can help you identify if MySQL is reaching any limits.

Seeing one process using high resources doesn't necessarily mean there is an issue. If that only happens every so often it could just mean there is a CPU intensive query that is being run that uses a large amount of CPU. If you see the high usage again, running the mysqladmin proc status command may show you exactly what is happening.

It's best to let the system run a bit longer as the mysqltuner tool will tell you, as your output did, that the MySQL service wasn't online for at least 24 hours, so the data and recommendations may not be complete enough for the tuner script to get a full picture of your server's situation.

If you need more details on any of this, just let us know!
 

anton_latvia

Well-Known Member
PartnerNOC
May 11, 2004
432
47
178
Latvia
cPanel Access Level
Root Administrator
I would login to MySQL shell (run "mysql" from console) and run:
SQL:
show full processlist;
this will show you current running queries. You will need to run it several times and see, if some queries appear often or stay for a while. With that information you should analyze both queries or databases. There is no single reason for the high load. For example your MySQL config is pretty empty and can be improved by enabling query cache and adding more memory. High load can come from the overloaded filesystem or lack of CPU or bad table indexing or any kind of abuse. Bad indexes, bad queries, bad MySQL config is first thing to check.

I would add these lines to your /etc/my.cnf to begin with. remember to restart MySQL server afterwards.
Code:
query_cache_type=1
query_cache_limit=512K
query_cache_size=64M
query_cache_min_res_unit=256
key_buffer=64M
key_buffer_size=64M
innodb_buffer_pool_size=512M
innodb_thread_concurrency=0
innodb_log_file_size=128M