mysql 使用所有内存并移至交换区

mysql 使用所有内存并移至交换区

我们有一台专用的 Linux 服务器用于 mysql 数据库。我们运行的任何脚本都存在严重的速度问题,而且随着我们运行的脚本越来越多,这种情况似乎越来越严重。我可以在本地计算机上运行这些脚本,它们的运行速度会提高一倍。

现在我觉得我们遇到了内存问题。随着我们继续运行脚本,内存使用率会越来越高(这显然是正常的),但当这些脚本结束时,它们不会释放内存。注意*这不是缓存内存。

由于我的代表点为 0,因此我无法发布任何图片,但运行 htop 显示我们当前正在使用 28245/32150MB,再次 - 这不是缓存内存并且当前没有运行脚本。

任何帮助将不胜感激。

来自服务器的my.cnf:

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
#
# * Basic Settings
#
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
lc-messages-dir = /usr/share/mysql
#skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address       = 41.76.208.223
#bind-address   = 127.0.0.1
#
# * Fine Tuning
#
key_buffer      = 384M
max_allowed_packet  = 16M
thread_stack        = 192K
thread_cache_size       = 384
skip-name-resolve
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections        = 100
table_cache            = 1500 
table_definition_cache  = 1500
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit   = 4M
query_cache_size        = 128M
join_buffer_size    = 128M
max_heap_table_size = 128M
tmp_table_size      = 128M
read_buffer_size    = 32M 
innodb_buffer_pool_size = 25G
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
# Here you can see queries with especially long duration
#log_slow_queries   = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#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          = 2
log_bin             = /var/log/mysql/mysql-bin.log
log_bin_index           = /var/log/mysql/mysql-bin.log.index
relay_log           = /var/log/mysql/mysql-relay-bin
relay_log_index         = /var/log/mysql/mysql-relay-bin.index
expire_logs_days        = 10
max_binlog_size         = 100M
log_slave_updates       = 1
auto-increment-increment    = 2
auto-increment-offset       = 1
replicate-ignore-db             = mysql
replicate-ignore-db             = information_schema
replicate-ignore-db             = performance_schema
#binlog_do_db           = include_database_name
#binlog_ignore_db       = include_database_name
#
# * 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!
#
# * 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  = 16M

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

[isamchk]
key_buffer      = 16M

#
# * 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/

答案1

查看此处的配置,mysql 将耗尽机器上的几乎所有内存 - 如果它是仅运行 InnoDB 的专用 MySQL 服务器,那么就应该这样配置。

但当这些结束时它们不会释放内存

它们不会从 innodb 缓冲池中释放内存——这就是系统的工作方式。

如果您的系统正在使用交换,那么要么是 mysql 某处出现泄漏(您忘记告诉我们您使用的是什么版本)。更可能的是,其他东西占用了大量内存,并且没有释放它们。

答案2

是“innodb_buffer_pool_size = 25G”吗?

使用数据库的内部缓存可使数据库运行得更快,但代价是降低所有其他服务的速度,因为系统无法回收此内存,无法将其用于文件系统缓存,无法将其提供给进程。尝试降低 MySQL 占用率。

相关内容