免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
1234下一页
最近访问板块 发新帖
查看: 27928 | 回复: 39
打印 上一主题 下一主题

关于mysql内存溢出,请高手支招 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-05-06 17:42 |只看该作者 |倒序浏览
有台服务器,只运行了一个mysql
服务器配置两颗4核E5410 8G内存 146G sas 15k转速的硬盘
系统为centos 5.2 64位
mysql 5.1.32 64位
平均每秒约1w次查询,优化的还不错,性能很好,负载4左右也很稳定
加载了google的 tcmalloc
现在的问题是,不知道什么原因,内存貌似失控了。内存的使用率,跟配置的完全不是一回事,一般48小时内就能把8G内存耗光,估计4天左右又能把4G的swap空间耗光,用到swap的时候,性能并没有下降。然后,就内存溢出了,挺郁闷。
目前的内存使用情况
free -m
             total       used       free     shared    buffers     cached
Mem:          7982       6999        983          0        237        955
-/+ buffers/cache:       5806       2175
Swap:         4094          6       4087
预计3天以后就能把物理内存和swap都能耗光,然后溢出
主要的表都用的innodb引擎。不多废话,把配置文件贴出来,请高手们不吝赐教

# Example MySQL config file for very large systems.
#
# This is for a large system with memory of 1G-2G where the system runs mainly
# MySQL.
#
# You can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /usr/local/mysql/data) or
# ~/.my.cnf to set user-specific options.
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
bind-address=192.168.0.2
socket          = /tmp/mysql.sock
skip-locking
key_buffer = 512M
max_allowed_packet = 1M
table_cache = 1024
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 16
set-variable=max_connections=1000
long_query_time = 1
log_slow_queries       = /backup/logs/mysql/mysql-slow.log
max_heap_table_size = 500M
tmp_table_size = 200M
back_log=400
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
skip-name-resolve

# Disable Federated by default
skip-federated

# Replication Master Server (default)
# binary logging is required for replication
#log-bin=mysql-bin

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id       = 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave - required
#master-host     =   <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =   <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =   <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
#
# binary logging format - mixed recommended
#binlog_format=mixed

# Point the following paths to different dedicated disks
#tmpdir         = /tmp/
#log-update     = /path-to-dedicated-directory/hostname

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/data/
#innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
innodb_data_file_path = ibdata1:1500M;ibdata2:1500M;ibdata3:1500M;ibdata4:1500M;ibdata5:1500M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/data/
#innodb_log_arch_dir = /usr/local/mysql/data/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 3072M
innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 256M
innodb_log_buffer_size = 20M
innodb_flush_log_at_trx_commit = 2
innodb_thread_concurrency = 1000
innodb_flush_method = O_DIRECT

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[ 本帖最后由 real_lufeng 于 2009-5-6 17:45 编辑 ]

论坛徽章:
1
白银圣斗士
日期:2015-11-23 08:33:04
2 [报告]
发表于 2009-05-06 18:45 |只看该作者
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/data/
#innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
innodb_data_file_path = ibdata1:1500M;ibdata2:1500M;ibdata3:1500M;ibdata4:1500M;ibdata5:1500M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/data/
#innodb_log_arch_dir = /usr/local/mysql/data/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 3072M
innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 256M
innodb_log_buffer_size = 20M
innodb_flush_log_at_trx_commit = 2
innodb_thread_concurrency = 1000
innodb_flush_method = O_DIRECT

主要参数 都在上面,适当调小观察下看看,连接数也适当调小。
看看慢查询里的有没有啥特费时的sql.

论坛徽章:
0
3 [报告]
发表于 2009-05-06 21:08 |只看该作者

回复 #2 枫影谁用了 的帖子

没有慢查询,好歹也是每秒近1w次的查询,有一条慢查询的话这机器就给拖死了
连接数不大,两台web,总共512个php-cgi进程,也就是说,最多也就并发512
你说的主要的参数,这里面跟默认相比,改动最大的也就是
innodb_buffer_pool_size
这个改成1G的时候倒是没注意过有没有出现现在的情况,不过1G不够用。之前调到4G,出现了溢出,又改到了3G
我挺纳闷的是,我机器有8G内存 4G swap,我配置的这些参数,到底是哪里的问题,才导致mysql能把这将近12G的内存用光

论坛徽章:
0
4 [报告]
发表于 2009-05-06 23:24 |只看该作者
将set-variable=max_connections=1000 调低些,例如改为500;然后打开慢查询日志。

另外检查看应用是否有未释放的链接。

[ 本帖最后由 stormcc 于 2009-5-6 23:26 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2009-05-06 23:26 |只看该作者
SQL优化了吗?

论坛徽章:
0
6 [报告]
发表于 2009-05-07 00:23 |只看该作者
那个MySQL是你自已编译的吧。
贴一下:
/path/mysql/bin/mysqlbug 的相关信息。

另外给你一个建义,先禁掉那个swap.让MySQL自已在内存中交换,不使用Swap.

论坛徽章:
0
7 [报告]
发表于 2009-05-07 07:29 |只看该作者

回复 #4 stormcc 的帖子

回4楼的兄弟
两台web总共开了512个php-cgi进程,所以,mysql的并发,最多也就512个,我觉得跟set-variable=max_connections=1000应该没多大关系的
满查询日志是打开的。偶尔会有一两个慢查询,一天下来不超过10个,都是偶尔卡住的简单的sql语句
sleep状态的进程基本没有,用过的链接应该是都释放了。

论坛徽章:
0
8 [报告]
发表于 2009-05-07 07:31 |只看该作者

回复 #5 ziggler 的帖子

回5楼的兄弟
优化过了,相当的优化

论坛徽章:
0
9 [报告]
发表于 2009-05-07 07:33 |只看该作者

回复 #6 Coolriver 的帖子

回6楼的兄弟。
是直接下载的二进制发行版
不过我加载了google的tcmalloc,据说在内存分配方面比glibc更有优势
窃以为关掉swap只会死的更快些

论坛徽章:
0
10 [报告]
发表于 2009-05-07 07:44 |只看该作者
目前的内存使用情况
Mem:   8174224k total,  8129184k used,    45040k free,   202740k buffers
Swap:  4192956k total,   297388k used,  3895568k free,   733040k cached

  PID USER PR  NI  VIRT  RES  SHR S %CPU %MEM TIME+ COMMAND
15684 mysql 15 0 7849m 6.8g 4808 S   26 86.6   1488:30 mysqld
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP