High Load mysql on Debian server stops every day. Why?

Posted by Oleg Abrazhaev on Server Fault See other posts from Server Fault or by Oleg Abrazhaev
Published on 2013-06-27T03:40:51Z Indexed on 2013/06/27 10:23 UTC
Read the original article Hit count: 422

Filed under:
|
|

I have Debian server with 32 gb memory. And there is apache2, memcached and nginx on this server.

Memory load always on maximum. Only 500m free. Most memory leak do MySql. Apache only 70 clients configured, other services small memory usage. When mysql use all memory it stops. And nothing works, need mysql reboot. Mysql configured use maximum 24 gb memory.

I have hight weight InnoDB bases. (400000 rows, 30 gb). And on server multithread daemon, that makes many inserts in this tables, thats why InnoDB.

There is my mysql config.

    [mysqld]
#
# * Basic Settings
#
default-time-zone = "+04:00"

user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
language    = /usr/share/mysql/english

skip-external-locking

default-time-zone='Europe/Moscow'
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#
# * Fine Tuning
#

#low_priority_updates   = 1
concurrent_insert   = ALWAYS

wait_timeout        = 600
interactive_timeout     = 600

#normal
key_buffer_size     = 2024M
#key_buffer_size        = 1512M

#70% hot cache
key_cache_division_limit= 70

#16-32
max_allowed_packet  = 32M
#1-16M
thread_stack        = 8M
#40-50
thread_cache_size   = 50

#orderby groupby sort
sort_buffer_size        = 64M
#same
myisam_sort_buffer_size = 400M

#temp table creates when group_by
tmp_table_size      = 3000M
#tables in memory
max_heap_table_size     = 3000M

#on disk
open_files_limit    = 10000
table_cache             = 10000

join_buffer_size = 5M

# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched

myisam-recover      = BACKUP
#myisam_use_mmap    = 1

max_connections         = 200

thread_concurrency      = 8

#
# * Query Cache Configuration
#

#more ignored
query_cache_limit       = 50M
query_cache_size        = 210M
#on query cache
query_cache_type = 1

#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
#log        = /var/log/mysql/mysql.log
#
# Error logging goes to syslog. This is a Debian improvement :)
#
# Here you can see queries with especially long duration

log_slow_queries    = /var/log/mysql/mysql-slow.log
long_query_time = 1
log-queries-not-using-indexes

#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id      = 1
#log_bin        = /var/log/mysql/mysql-bin.log

server-id   = 1
log-bin     = /var/lib/mysql/mysql-bin 
#replicate-do-db = gate
log-bin-index = /var/lib/mysql/mysql-bin.index
log-error = /var/lib/mysql/mysql-bin.err
relay-log = /var/lib/mysql/relay-bin
relay-log-info-file = /var/lib/mysql/relay-bin.info
relay-log-index = /var/lib/mysql/relay-bin.index
binlog_do_db            = 24avia

expire_logs_days    = 10
max_binlog_size         = 100M

read_buffer_size    = 4024288

innodb_buffer_pool_size     = 5000M
innodb_flush_log_at_trx_commit  = 2
innodb_thread_concurrency   = 8

table_definition_cache  = 2000

group_concat_max_len    = 16M

#binlog_do_db       = gate
#binlog_ignore_db   = include_database_name
#
# * BerkeleyDB
#
# Using BerkeleyDB is now discouraged as its support will cease in 5.1.12.
#skip-bdb
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
# You might want to disable InnoDB to shrink the mysqld process by circa 100MB.
#skip-innodb
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem


[mysqldump]
quick
quote-names
max_allowed_packet  = 500M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]
key_buffer      = 32M
key_buffer_size     = 512M

#
# * NDB Cluster
#
# See /usr/share/doc/mysql-server-*/README.Debian for more information.
#
# The following configuration is read by the NDB Data Nodes (ndbd processes)
# not from the NDB Management Nodes (ndb_mgmd processes).
#
# [MYSQL_CLUSTER]
# ndb-connectstring=127.0.0.1

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

Please, help me make it stable.

Memory used

 /etc/mysql # free
          total       used       free     shared    buffers     cached
Mem:      32930800   32766424     164376          0     139208   23829196
-/+ buffers/cache:    8798020   24132780
Swap:     33553328      44660   33508668

Maybe my problem not in memory, but MySQL stops every day. As you can see, cache memory free 24 gb.

Thank to Michael Hampton? for correction.

Load overage on server 3.5. Maybe hdd or another problem? Maybe my config not optimal for 30gb InnoDB ?

I'm already try mysqltuner and tunung-primer.sh , but they marked all green.

Mysqltuner output

mysqltuner 

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

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.5.24-9-log
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster 
[--] Data in MyISAM tables: 112G (Tables: 1528)
[--] Data in InnoDB tables: 39G (Tables: 340)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[!!] Total fragmented tables: 344

-------- Performance Metrics -------------------------------------------------
[--] Up for: 8h 18m 33s (14M q [478.333 qps], 259K conn, TX: 9B, RX: 5B)
[--] Reads / Writes: 84% / 16%
[--] Total buffers: 10.5G global + 81.1M per thread (200 max threads)
[OK] Maximum possible memory usage: 26.3G (83% of installed RAM)
[OK] Slow queries: 1% (259K/14M)
[!!] Highest connection usage: 100%  (201/200)
[OK] Key buffer size / total MyISAM indexes: 1.5G/5.6G
[OK] Key buffer hit rate: 100.0% (6B cached / 1M reads)
[OK] Query cache efficiency: 74.3% (8M cached / 11M selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 247K sorts)
[!!] Joins performed without indexes: 106025
[!!] Temporary tables created on disk: 49% (351K on disk / 715K total)
[OK] Thread cache hit rate: 99% (249 created / 259K connections)
[!!] Table cache hit rate: 15% (2K open / 13K opened)
[OK] Open file limit used: 15% (3K/20K)
[OK] Table locks acquired immediately: 99% (4M immediate / 4M locks)
[!!] InnoDB data size / buffer pool: 39.4G/5.9G

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    MySQL started within last 24 hours - recommendations may be inaccurate
    Reduce or eliminate persistent connections to reduce connection usage
    Adjust your join queries to always utilize indexes
    Temporary table size is already large - reduce result set size
    Reduce your SELECT DISTINCT queries without LIMIT clauses
    Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
    max_connections (> 200)
    wait_timeout (< 600)
    interactive_timeout (< 600)
    join_buffer_size (> 5.0M, or always use indexes with joins)
    table_cache (> 10000)
    innodb_buffer_pool_size (>= 39G)

Mysql primer output

-- MYSQL PERFORMANCE TUNING PRIMER --
         - By: Matthew Montgomery -

MySQL Version 5.5.24-9-log x86_64

Uptime = 0 days 8 hrs 20 min 50 sec
Avg. qps = 478
Total Questions = 14369568
Threads Connected = 16

Warning: Server has not been running for at least 48hrs.
It may not be safe to use these recommendations

To find out more information on how each of these
runtime variables effects performance visit:
http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html
Visit http://www.mysql.com/products/enterprise/advisors.html
for info about MySQL's Enterprise Monitoring and Advisory Service

SLOW QUERIES
The slow query log is enabled.
Current long_query_time = 1.000000 sec.
You have 260626 out of 14369701 that take longer than 1.000000 sec. to complete
Your long_query_time seems to be fine

BINARY UPDATE LOG
The binary update log is enabled
Binlog sync is not enabled, you could loose binlog records during a server crash

WORKER THREADS
Current thread_cache_size = 50
Current threads_cached = 45
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 200
Current threads_connected = 11
Historic max_used_connections = 201
The number of used connections is 100% of the configured maximum.
You should raise max_connections

INNODB STATUS
Current InnoDB index space = 214 M
Current InnoDB data space = 39.40 G
Current InnoDB buffer pool free = 0 %
Current innodb_buffer_pool_size = 5.85 G
Depending on how much space your innodb indexes take up it may be safe
to increase this value to up to 2 / 3 of total system memory

MEMORY USAGE
Max Memory Ever Allocated : 23.46 G
Configured Max Per-thread Buffers : 15.84 G
Configured Max Global Buffers : 7.54 G
Configured Max Memory Limit : 23.39 G
Physical Memory : 31.40 G
Max memory limit seem to be within acceptable norms

KEY BUFFER
Current MyISAM index space = 5.61 G
Current key_buffer_size = 1.47 G
Key cache miss rate is 1 : 5578
Key buffer free ratio = 77 %
Your key_buffer_size seems to be fine

QUERY CACHE
Query cache is enabled
Current query_cache_size = 200 M
Current query_cache_used = 101 M
Current query_cache_limit = 50 M
Current Query cache Memory fill ratio = 50.59 %
Current query_cache_min_res_unit = 4 K
MySQL won't cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 64 M
Current read_rnd_buffer_size = 256 K
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 5.00 M
You have had 106606 queries where a join could not use an index properly
You have had 8 joins without keys that check for key usage after each row
join_buffer_size >= 4 M
This is not advised
You should enable "log-queries-not-using-indexes"
Then look for non indexed joins in the slow query log.

OPEN FILES LIMIT
Current open_files_limit = 20210 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
Your open_files_limit value seems to be fine

TABLE CACHE
Current table_open_cache = 10000 tables
Current table_definition_cache = 2000 tables
You have a total of 1910 tables
You have 2151 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 2.92 G
Current tmp_table_size = 2.92 G
Of 366426 temp tables, 49% were created on disk
Perhaps you should increase your tmp_table_size and/or max_heap_table_size
to reduce the number of disk-based temporary tables
Note! BLOB and TEXT columns are not allow in memory tables.
If you are using these columns raising these values might not impact your 
ratio of on disk temp tables.

TABLE SCANS
Current read_buffer_size = 3 M
Current table scan ratio = 2846 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 1 : 185
You may benefit from selective use of InnoDB.
If you have long running SELECT's against MyISAM tables and perform
frequent updates consider setting 'low_priority_updates=1'

© Server Fault or respective owner

Related posts about mysql

Related posts about debian