I am working on a web app that uses a remote MySQL(5.1) server (dedicated server for database). At times, web server crashes due to high CPU usage. In our application logs, there are some traces that shows there is some problem in communicating with MySQL server.
But, no errors found in MySQL logs and server was accessible from a local machine.
So, I have used mysql tuner to check if there is any problem in database configuration. The tuner result is as follows,
[--] Skipped version check for MySQLTuner script
Please enter your MySQL administrative login: root
Please enter your MySQL administrative password: [OK] Currently running supported MySQL version 5.1.73
[OK] Operating on 64-bit architecture
-------- Log file Recommendations ------------------------------------------------------------------
[--] Log file: /var/log/mysqld.log(304K)
[OK] Log file /var/log/mysqld.log exists
[OK] Log file /var/log/mysqld.log is readable.
[OK] Log file /var/log/mysqld.log is not empty
[OK] Log file /var/log/mysqld.log is smaller than 32 Mb
[!!] /var/log/mysqld.log contains 27 warning(s).
[!!] /var/log/mysqld.log contains 188 error(s).
[--] 87 start(s) detected in /var/log/mysqld.log
[--] 1) 180115 16:07:08 [Note] /usr/libexec/mysqld: ready for connections.
[--] 2) 180103 11:08:40 [Note] /usr/libexec/mysqld: ready for connections.
[--] 3) 180103 7:37:06 [Note] /usr/libexec/mysqld: ready for connections.
[--] 4) 180102 10:36:27 [Note] /usr/libexec/mysqld: ready for connections.
[--] 5) 171109 17:10:16 [Note] /usr/libexec/mysqld: ready for connections.
[--] 6) 171031 5:43:04 [Note] /usr/libexec/mysqld: ready for connections.
[--] 7) 171023 10:00:56 [Note] /usr/libexec/mysqld: ready for connections.
[--] 8) 171010 7:48:13 [Note] /usr/libexec/mysqld: ready for connections.
[--] 9) 170920 6:57:47 [Note] /usr/libexec/mysqld: ready for connections.
[--] 10) 170914 9:50:08 [Note] /usr/libexec/mysqld: ready for connections.
[--] 82 shutdown(s) detected in /var/log/mysqld.log
[--] 1) 180115 16:06:57 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 2) 180103 11:08:25 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 3) 180102 10:39:22 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 4) 171109 17:10:13 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 5) 171031 5:42:58 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 6) 171023 10:00:53 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 7) 171010 7:48:11 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 8) 170920 6:57:40 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 9) 170914 9:49:38 [Note] /usr/libexec/mysqld: Shutdown complete
[--] 10) 170804 13:23:47 [Note] /usr/libexec/mysqld: Shutdown complete
-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +CSV +InnoDB +MRG_MYISAM
[--] Data in MyISAM tables: 2M (Tables: 851)
[--] Data in InnoDB tables: 9G (Tables: 4306)
[OK] Total fragmented tables: 0
-------- Security Recommendations ------------------------------------------------------------------
[!!] User '@localhost' is an anonymous account.
[!!] User '@localhost' has no password set.
[!!] User 'readonly@%' has no password set.
[!!] User 'root@127.0.0.1' has no password set.
[!!] User 'root@ip-xx-xxx-xxx-x' has no password set.
[!!] User '@localhost' has user name as password.
[!!] User 'readonly@%' hasn't specific host restriction.
[!!] There is no basic password file list!
-------- CVE Security Recommendations --------------------------------------------------------------
[--] Skipped due to --cvefile option undefined
-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 28d 18h 49m 49s (265M q [106.609 qps], 28M conn, TX: 485G, RX: 40G)
[--] Reads / Writes: 88% / 12%
[--] Binary logging is disabled
[--] Physical Memory : 7.8G
[--] Max MySQL memory : 7.2G
[--] Other process memory: 147.1M
[--] Total buffers: 4.0G global + 2.7M per thread (1200 max threads)
[--] P_S Max memory usage: 0B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 5.0G (64.32% of installed RAM)
[!!] Maximum possible memory usage: 7.2G (92.79% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available
[OK] Slow queries: 0% (1K/265M)
[OK] Highest usage of available connections: 31% (372/1200)
[OK] Aborted connections: 0.00% (75/28625593)
[!!] 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 / 57M selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (11K temp sorts / 3M sorts)
[!!] Joins performed without indexes: 58834
[OK] Temporary tables created on disk: 0% (147K on disk / 58M total)
[!!] Thread cache is disabled
[!!] Table cache hit rate: 0% (64 open / 8M opened)
[OK] Open file limit used: 0% (2/6K)
[OK] Table locks acquired immediately: 99% (42M immediate / 42M locks)
-------- Performance schema ------------------------------------------------------------------------
[--] Performance schema is disabled.
[--] Memory used by P_S: 0B
[--] Sys schema isn't installed.
-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is disabled.
-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 18.3% (1M used / 8M cache)
[OK] Key buffer size / total MyISAM indexes: 8.0M/1.1M
[OK] Read Key buffer hit rate: 99.9% (251M cached / 180K reads)
[!!] Write Key buffer hit rate: 0.0% (96M cached / 542 writes)
-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 8
[!!] InnoDB File per table is not activated
[!!] InnoDB buffer pool / data size: 4.0G/9.1G
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (0.244140625 %): 5.0M * 2/4.0G should be equal 25%
[--] InnoDB Buffer Pool Chunk Size not used or defined in your version
[OK] InnoDB Read buffer efficiency: 100.00% (818222561475 hits/ 818225469097 total)
[!!] InnoDB Write Log efficiency: 42.33% (2251283 hits/ 5318531 total)
[!!] InnoDB log waits: 0.00% (59 waits / 7569814 writes)
-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is disabled.
-------- TokuDB Metrics ----------------------------------------------------------------------------
[--] TokuDB is disabled.
-------- XtraDB Metrics ----------------------------------------------------------------------------
[--] XtraDB is disabled.
-------- RocksDB Metrics ---------------------------------------------------------------------------
[--] RocksDB is disabled.
-------- Spider Metrics ----------------------------------------------------------------------------
[--] Spider is disabled.
-------- Connect Metrics ---------------------------------------------------------------------------
[--] Connect is disabled.
-------- Galera Metrics ----------------------------------------------------------------------------
[--] Galera is disabled.
-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] This is a standalone server.
-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
Control warning line(s) into /var/log/mysqld.log file
Control error line(s) into /var/log/mysqld.log file
Remove Anonymous User accounts - there are 1 anonymous accounts.
Set up a Password for user with the following SQL statement ( SET PASSWORD FOR 'user'@'SpecificDNSorIp' = PASSWORD('secure_password'); )
Set up a Secure Password for user@host ( SET PASSWORD FOR 'user'@'SpecificDNSorIp' = PASSWORD('secure_password'); )
Restrict Host for user@% to user@SpecificDNSorIp
Reduce your overall MySQL memory footprint for system stability
Enable the slow query log to troubleshoot bad queries
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
Set thread_cache_size to 4 as a starting value
Increase table_open_cache gradually to avoid file descriptor limits
Read this before increasing table_open_cache over 64:
Beware that open_files_limit (6000) variable
should be greater than table_open_cache (64)
Read this before changing innodb_log_file_size and/or innodb_log_files_in_group:
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_limit (> 1M, or use smaller result sets)
join_buffer_size (> 128.0K, or always use indexes with joins)
thread_cache_size (start at 4)
table_open_cache (> 64)
innodb_file_per_table=ON
innodb_buffer_pool_size (>= 9G) if possible.
innodb_log_file_size should be (=512M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.
innodb_log_buffer_size (>= 1M)
With this result, I believe increasing innodb_buffer_pool
will fix my problem. But, to increase this I need to increase RAM of the instance. (current RAM: 8GB, DB size: 9.1GB).
UPDATE: my.cnf file
[client]
socket=/home/mysqldbloc/mysql.sock
[mysqld]
innodb_buffer_pool_size=4096M
datadir=/home/mysqldbloc
socket=/home/mysqldbloc/mysql.sock
user=mysql
lower_case_table_names=1
symbolic-links=0
max_connections=1200
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-slow-queries=/var/run/mysqld/mysqld-slow.log
So, how much RAM should I allocate to this instance so that there wont be any communication problem? Also, currently our web application is very slow. Will increase in RAM make it fast?