MySQL总内存分配用量?内存泄漏?

时间:2015-01-10 04:14:08

标签: mysql memory memory-management

我使用5.6.21-70.0进行性能测试。

我跑的时候

  

mysqlslap -a --concurrency = 40 - number-of-queries 1000 --iterations = 500 --engine = innodb --debug-info -utest -p

进行一些性能测试,ram增长超过最大内存使用量,永不释放

完成mysqlslap时 记忆显示使用78%

我有一个1G的物理内存而且 NOT 使用 swap

  

KiB Mem:1016656总计,953808使用,62848免费,30324缓冲

     

KiB Swap:0总计,0使用,0免费。 41384缓存Mem

     

PID用户PR NI VIRT RES SHR S%CPU %MEM TIME + COMMAND
  26049 mysql 20 0 1544156 778316 3992 S 16.3 76.6 6:24.01 mysqld

**似乎mysqld使用大约700M内存?为什么它超过最大内存使用量? 为什么mysql永远不会释放内存? **

我的mysqlturning.pl显示:

  

[确定]可用连接的最高使用率:70%(42/60)

     

[确定]密钥缓冲区大小/总MyISAM索引:32.0M / 98.0K

     

[ - ]读/写:40%/ 60%

     

[ - ]总缓冲区:全局336.0M +每线程1.1M(最多60个线程)

     

[确定]最大内存使用量: 403.5M (已安装RAM的40%)

----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 274726912; in additional pool allocated 0
Total memory allocated by read views 96
Internal hash tables (constant factor + variable factor)
    Adaptive hash index 4446416     (4425832 + 20584)
    Page hash           277432 (buffer pool 0 only)
    Dictionary cache    1170261     (1107952 + 62309)
    File system         815920  (812272 + 3648)
    Lock system         665656  (664936 + 720)
    Recovery system     0   (0 + 0)
Dictionary memory allocated 62309
Buffer pool size        16383
Buffer pool size, bytes 268419072
Free buffers            1024
Database pages          15358
Old database pages      5649
Modified db pages       0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 407, not young 484
0.00 youngs/s, 0.00 non-youngs/s
Pages read 614, created 17947, written 20737
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 15358, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]

my my.cnf ----

 # Generated by Percona Configuration Wizard (http://tools.percona.com/) version REL5-20120208

 [mysql]

 # CLIENT #
 port                           = 3306
 socket                         = /data/data/mysql.sock

 [mysqld]

 # GENERAL #
 user                           = mysql
 default-storage-engine         = InnoDB
 socket                         = /data/data/mysql.sock
 pid-file                       = /data/data/mysql.pid
 character-set-server=utf8
 collation-server=utf8_general_ci

 # MyISAM #
 key-buffer-size                = 32M
 myisam-recover                 = FORCE,BACKUP

 # SAFETY #
 max-allowed-packet             = 16M
 max-connect-errors             = 1000000
 skip-name-resolve
 sql-mode                       = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY
 sysdate-is-now                 = 1
 innodb                         = FORCE

 # DATA STORAGE #
 datadir                        = /data/data/

 # BINARY LOGGING #
 log-bin                        = /data/data/mysql-bin
 expire-logs-days               = 14
 sync-binlog                    = 1

 # CACHES AND LIMITS #
 tmp-table-size                 = 32M
 max-heap-table-size            = 32M
 query-cache-type               = 0
 query-cache-size               = 0
 max-connections                = 60
 thread-cache-size              = 50
 open-files-limit               = 65535
 table-definition-cache         = 1024
 table-open-cache               = 2048

 # INNODB #
 innodb-flush-method            = O_DIRECT
 innodb-log-files-in-group      = 2
 innodb-log-file-size           = 64M
 innodb-flush-log-at-trx-commit = 1
 innodb-file-per-table          = 1
 innodb-buffer-pool-size        = 64M

 # LOGGING #
 log-error                      = /data/data/mysql-error.log
 log-queries-not-using-indexes  = 0 # slow will not log the query which do not use index
 long-query-time                = 1
 slow-query-log                 = 1
 slow-query-log-file            = /data/data/mysql-slow.log

2 个答案:

答案 0 :(得分:2)

我发现了为什么发生内存泄漏。 现在我只有1GB内存,没有交换。

performance_schema 导致在启动时为内存分配大约400M。和innodb将占用高达400M的内存

所以,因为my.cnf使用

table-definition-cache= 1024
table-open-cache= 2048 
max-connections= 60

它会导致分配高 performance_schema , 更多信息请参阅

ref1

ref2

答案 1 :(得分:0)

尝试在InnoDB表上运行FLUSH TABLES,它会根据.ibd文件关闭文件。我希望它会释放内存使用!!

您可能正在使用32位机器,它通常会提供3G,但您使用40%的物理内存已经足够了,我认为您需要扩展呼吸空间并且您肯定需要允许缓冲区大小大于数据或索引页面的大小。

尝试使用64位计算机并使用交换将使其更容易呼吸,包括数据/索引大小的更大容量的缓冲池。