The server where my database is running is suffering from CPU spikes. We're having trouble identifying what is causing these CPU spikes, and consequently how to mitigate them.
I've tried adding some indexes, but maybe I forgot one or two.
How do I check which table has any problems?
Once a day I have a huge CPU jump to 700%. We've been resolving it to date by restarting the server.
I can provide the necessary information to find the problem, but I don't know what info is needed.
This is the MySQLTuner report:
>> MySQLTuner 1.6.18 - Major Hayden <major@mhtx.net>
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with '--help' for additional options and output filtering
[[0;34m--[0m] Skipped version check for MySQLTuner script
[[0;32mOK[0m] Logged in using credentials from debian maintenance account.
[[0;32mOK[0m] Currently running supported MySQL version 10.1.47-MariaDB-0+deb9u1
[[0;32mOK[0m] Operating on 64-bit architecture
-------- Storage Engine Statistics -----------------------------------------------------------------
[[0;34m--[0m] Status: [0;32m+Aria [0m[0;32m+CSV [0m[0;32m+InnoDB [0m[0;32m+MEMORY [0m[0;32m+MRG_MyISAM [0m[0;32m+MyISAM [0m[0;32m+PERFORMANCE_SCHEMA [0m[0;32m+SEQUENCE [0m
[[0;34m--[0m] Data in InnoDB tables: 1G (Tables: 387)
[[0;34m--[0m] Data in MyISAM tables: 1K (Tables: 1)
[[0;32mOK[0m] Total fragmented tables: 0
-------- Security Recommendations ------------------------------------------------------------------
[[0;32mOK[0m] There are no anonymous accounts for any database users
[[0;32mOK[0m] All database users have passwords assigned
[[0;31m!![0m] User 'kacper@%' hasn't specific host restriction.
[[0;34m--[0m] There are 612 basic passwords in the list.
-------- CVE Security Recommendations --------------------------------------------------------------
[[0;32mOK[0m] NO SECURITY CVE FOUND FOR YOUR VERSION
-------- Performance Metrics -----------------------------------------------------------------------
[[0;34m--[0m] Up for: 2h 17m 38s (1M q [236.530 qps], 53K conn, TX: 1G, RX: 285M)
[[0;34m--[0m] Reads / Writes: 71% / 29%
[[0;34m--[0m] Binary logging is disabled
[[0;34m--[0m] Physical Memory : 62.8G
[[0;34m--[0m] Max MySQL memory : 12.6G
[[0;34m--[0m] Other process memory: 209.7M
[[0;34m--[0m] Total buffers: 328.0M global + 2.8M per thread (4096 max threads)
[[0;34m--[0m] P_S Max memory usage: 1G
[[0;34m--[0m] Galera GCache Max memory usage: 0B
[[0;32mOK[0m] Maximum reached memory usage: 7.1G (11.38% of installed RAM)
[[0;32mOK[0m] Maximum possible memory usage: 12.6G (20.10% of installed RAM)
[[0;32mOK[0m] Overall possible memory usage with other process is compatible with memory available
[[0;32mOK[0m] Slow queries: 0% (0/1M)
[[0;32mOK[0m] Highest usage of available connections: 51% (2102/4096)
[[0;32mOK[0m] Aborted connections: 0.02% (13/53000)
[[0;31m!![0m] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
[[0;32mOK[0m] Query cache efficiency: 30.4% (505K cached / 1M selects)
[[0;31m!![0m] Query cache prunes per day: 511609
[[0;32mOK[0m] Sorts requiring temporary tables: 5% (470 temp sorts / 9K sorts)
[[0;31m!![0m] Joins performed without indexes: 48
[[0;31m!![0m] Temporary tables created on disk: 76% (39K on disk / 51K total)
[[0;32mOK[0m] Thread cache hit rate: 89% (5K created / 53K connections)
[[0;32mOK[0m] Table cache hit rate: 81% (697 open / 860 opened)
[[0;32mOK[0m] Open file limit used: 0% (61/16K)
[[0;32mOK[0m] Table locks acquired immediately: 100% (998K immediate / 998K locks)
-------- Performance schema ------------------------------------------------------------------------
[[0;34m--[0m] Performance schema is enabled.
[[0;34m--[0m] Memory used by P_S: 1.1G
[[0;34m--[0m] Sys schema isn't installed.
-------- ThreadPool Metrics ------------------------------------------------------------------------
[[0;34m--[0m] ThreadPool stat is enabled.
[[0;34m--[0m] Thread Pool Size: 8 thread(s).
[[0;34m--[0m] Using default value is good enough for your version (10.1.47-MariaDB-0+deb9u1)
-------- MyISAM Metrics ----------------------------------------------------------------------------
[[0;31m!![0m] Key buffer used: 18.3% (3M used / 16M cache)
[[0;32mOK[0m] Key buffer size / total MyISAM indexes: 16.0M/124.0K
[[0;32mOK[0m] Read Key buffer hit rate: 97.5% (162 cached / 4 reads)
-------- AriaDB Metrics ----------------------------------------------------------------------------
[[0;34m--[0m] AriaDB is enabled.
[[0;32mOK[0m] Aria pagecache size / total Aria indexes: 128.0M/1B
[[0;31m!![0m] Aria pagecache hit rate: 83.9% (241K cached / 38K reads)
-------- InnoDB Metrics ----------------------------------------------------------------------------
[[0;34m--[0m] InnoDB is enabled.
[[0;31m!![0m] InnoDB buffer pool / data size: 128.0M/1.9G
[[0;31m!![0m] InnoDB buffer pool <= 1G and innodb_buffer_pool_instances(!=1).
[[0;34m--[0m] InnoDB Buffer Pool Chunk Size not used or defined in your version
[[0;32mOK[0m] InnoDB Read buffer efficiency: 99.87% (15073372350 hits/ 15093280124 total)
[[0;31m!![0m] InnoDB Write Log efficiency: 15.47% (49147 hits/ 317764 total)
[[0;32mOK[0m] InnoDB log waits: 0.00% (0 waits / 366911 writes)
-------- TokuDB Metrics ----------------------------------------------------------------------------
[[0;34m--[0m] TokuDB is disabled.
-------- Galera Metrics ----------------------------------------------------------------------------
[[0;34m--[0m] Galera is disabled.
-------- Replication Metrics -----------------------------------------------------------------------
[[0;34m--[0m] Galera Synchronous replication: NO
[[0;34m--[0m] No replication slave(s) for this server.
[[0;34m--[0m] This is a standalone server.
-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
Restrict Host for user@% to user@SpecificDNSorIp
MySQL started within last 24 hours - recommendations may be inaccurate
Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
Adjust your join queries to always utilize indexes
When making adjustments, make tmp_table_size/max_heap_table_size equal
Reduce your SELECT DISTINCT queries which have no LIMIT clause
Variables to adjust:
query_cache_size (> 16M)
join_buffer_size (> 256.0K, or always use indexes with joins)
tmp_table_size (> 16M)
max_heap_table_size (> 16M)
innodb_buffer_pool_size (>= 1G) if possible.
innodb_buffer_pool_instances (=1)