mysql版本 5.1.48,linux 32bit, 4G
数据量其实不大,整个mysql的数据加起来才100M,共有表60张,全是innodb的
每隔30秒top一次发现mysqld的VIRT和RES不停地增加,最后导致mysql内存爆表,重启。内存从674M涨到676M,发现innodb buffer pool的使用情况一切正常,个人怀疑是每个连接占用的内存无法释放导致的,但是无法提供证据,请有经验的大神指点一下,如何深度剖析mysql内存的占用,以下是我做的监控记录:
TOP命令:
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
18226 mysql     15   0 2704m 674m 4468 S 225.7 16.9   2983:38 mysqld.Show innodb status:SEMAPHORESOS WAIT ARRAY INFO: reservation count 13163327, signal count 13017415
Mutex spin waits 0, rounds 3603652498, OS waits 6344367
RW-shared spins 136422, OS waits 51286; RW-excl spins 15900633, OS waits 3011610TRANSACTIONSTrx id counter 2 1479203927
Purge done for trx's n:o < 2 1479177033 undo n:o < 0 0
History list length 17
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0 0, not started, process no 18226, OS thread id 1844444048
MySQL thread id 137516, query id 643136045 localhost adm
show innodb status
---TRANSACTION 2 1479203926, not started, process no 18226, OS thread id 1848441744 estimating records in index range
mysql tables in use 10, locked 0
MySQL thread id 137458, query id 643136043 localhost adm statistics
SELECT SpotId FROM placement WHERE HeadendId=216 AND NetworkId=87 AND SpotId='00032081239' AND ScheduleDate=20150605
---TRANSACTION 2 1479203924, not started, process no 18226, OS thread id 1747975056 returning various info to MySQL
mysql tables in use 20, locked 0
MySQL thread id 136634, query id 643136041 localhost adm Sending data
SELECT MIN(ScheduleTime) FROM placement WHERE SpotId = '00039677662' AND ScheduleDate>= 20150606 AND ScheduleDate<=20150607 AND ScheduleTime >= 1433598234 AND (StatusCode = 0 OR PIPStatusCode = 0) AND HeadendId=214 AND NetworkId=206
---TRANSACTION 2 1479203619, ACTIVE 0 sec, process no 18226, OS thread id 1850002320 fetching rows, thread declared inside InnoDB 479
mysql tables in use 10, locked 0
MySQL thread id 36026, query id 643135734 localhost 127.0.0.1 adm Sending data
select headendId, channelName, staticsDate, staticsHour, staticsMinute from staticsbyminute             where 1=1                   AND             ChannelName = 'AETVHDP'
Trx read view will not see trx with id >= 2 1479203620, sees < 2 1479203620
--------
FILE I/O
--------
I/O thread 0 state: waiting for i/o request (insert buffer thread)
I/O thread 1 state: waiting for i/o request (log thread)
I/O thread 2 state: waiting for i/o request (read thread)
I/O thread 3 state: waiting for i/o request (write thread)
Pending normal aio reads: 0, aio writes: 0,
 ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
5002 OS file reads, 446103 OS file writes, 254859 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 4.31 writes/s, 2.12 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2,
78 inserts, 78 merged recs, 7 merges
Hash table size 4425293, node heap has 415 buffer(s)
14986.78 hash searches/s, 68881.10 non-hash searches/s
---
LOG
---
Log sequence number 31 2765856743
Log flushed up to   31 2765677783
Last checkpoint at  31 2765677041
0 pending log writes, 0 pending chkp writes
187153 log i/o's done, 1.56 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 1169575771; in additional pool allocated 1048576
Dictionary memory allocated 305848
Buffer pool size   65536
Free buffers       57897
Database pages     7224
Modified db pages  195
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages read 5548, created 2946, written 587829
0.00 reads/s, 0.00 creates/s, 3.94 writes/s
Buffer pool hit rate 1000 / 1000
--------------
ROW OPERATIONS
--------------
1 queries inside InnoDB, 0 queries in queue
2 read views open inside InnoDB
Main thread process no. 18226, id 1861864336, state: sleeping
Number of rows inserted 195686, updated 15855021, deleted 96811, read 3094509184
0.00 inserts/s, 90.93 updates/s, 0.00 deletes/s, 31728.26 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
..
以下是我收集的部分参数
Com_alter_table 0
Com_alter_tablespace 0
Com_backup_table 0
Com_create_table 0
Com_drop_table 0
Com_load_master_table 0
Com_lock_tables 0
Com_rename_table 0
Com_restore_table 0
Com_show_create_table 0
Com_show_open_tables 0
Com_show_table_status 0
Com_show_tables 0
Com_unlock_tables 0
Created_tmp_disk_tables 0
Created_tmp_files 17
Created_tmp_tables 0
Innodb_buffer_pool_pages_data 7224
Innodb_buffer_pool_pages_dirty 195
Innodb_buffer_pool_pages_flushed 587829
Innodb_buffer_pool_pages_free 57897
Innodb_buffer_pool_pages_misc 415
Innodb_buffer_pool_pages_total 65536
Innodb_buffer_pool_read_ahead_rnd 1
Innodb_buffer_pool_read_ahead_seq 18
Innodb_buffer_pool_read_requests 1237235030
Innodb_buffer_pool_reads 4398
Innodb_buffer_pool_wait_free 0
Innodb_buffer_pool_write_requests 45684383
Innodb_data_fsyncs 254859
Innodb_data_pending_fsyncs 0
Innodb_data_pending_reads 0
Innodb_data_pending_writes 0
Innodb_data_read 101273600
Innodb_data_reads 5002
Innodb_data_writes 446103
Innodb_data_written 4025841152
Innodb_dblwr_pages_written 587829
Innodb_dblwr_writes 22312
Innodb_log_waits 0
Innodb_log_write_requests 3692581
Innodb_log_writes 175746
Innodb_os_log_fsyncs 186578
Innodb_os_log_pending_fsyncs 0
Innodb_os_log_pending_writes 0
Innodb_os_log_written 1937939968
Innodb_page_size 16384
Innodb_pages_created 2946
Innodb_pages_read 5548
Innodb_pages_written 587829
Innodb_row_lock_current_waits 0
Innodb_row_lock_time 22396
Innodb_row_lock_time_avg 67
Innodb_row_lock_time_max 19822
Innodb_row_lock_waits 331
Innodb_rows_deleted 96811
Innodb_rows_inserted 195686
Innodb_rows_read 3094510812
Innodb_rows_updated 15855021
Open_table_definitions 35
Open_tables 53
Opened_table_definitions 0
Opened_tables 0
Slave_open_temp_tables 0
Table_locks_immediate 2111426231
Table_locks_waited 2.第二次记录
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
18226 mysql     16   0 2716m 676m 4468 S 196.2 17.0   2985:05 mysqld.Per second averages calculated from the last 32 secondsSEMAPHORESOS WAIT ARRAY INFO: reservation count 13175423, signal count 13029262
Mutex spin waits 0, rounds 3607436745, OS waits 6348512
RW-shared spins 136428, OS waits 51289; RW-excl spins 15914334, OS waits 3014856TRANSACTIONSTrx id counter 2 1479387100
Purge done for trx's n:o < 2 1479358657 undo n:o < 0 0
History list length 4
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0 0, not started, process no 18226, OS thread id 1850395536
MySQL thread id 137548, query id 643318851 localhost adm
show innodb status
---TRANSACTION 2 1479387098, not started, process no 18226, OS thread id 1848441744
mysql tables in use 10, locked 0
MySQL thread id 137458, query id 643318850 localhost adm
SELECT SpotId FROM placement WHERE HeadendId=214 AND NetworkId=242 AND SpotId='00036437318' AND ScheduleDate=20150605
---TRANSACTION 2 1479387099, not started, process no 18226, OS thread id 1747975056
mysql tables in use 10, locked 0
MySQL thread id 136634, query id 643318852 localhost adm
SELECT MIN(ScheduleTime) FROM placement WHERE SpotId = '00039677896' AND ScheduleDate>= 20150606 AND ScheduleDate<=20150607 AND ScheduleTime >= 1433598234 AND (StatusCode = 0 OR PIPStatusCode = 0) AND HeadendId=214 AND NetworkId=94
--------
FILE I/O
--------
I/O thread 0 state: waiting for i/o request (insert buffer thread)
I/O thread 1 state: waiting for i/o request (log thread)
I/O thread 2 state: waiting for i/o request (read thread)
I/O thread 3 state: waiting for i/o request (write thread)
Pending normal aio reads: 0, aio writes: 0,
 ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
5002 OS file reads, 446316 OS file writes, 254946 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 6.66 writes/s, 2.72 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2,
78 inserts, 78 merged recs, 7 merges
Hash table size 4425293, node heap has 415 buffer(s)
12718.98 hash searches/s, 78359.40 non-hash searches/s
---
LOG
---
Log sequence number 31 2772442138
Log flushed up to   31 2772440193
Last checkpoint at  31 2767603531
0 pending log writes, 0 pending chkp writes
187218 log i/o's done, 2.03 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 1169481491; in additional pool allocated 1048576
Dictionary memory allocated 305848
Buffer pool size   65536
Free buffers       57897
Database pages     7224
Modified db pages  304
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages read 5548, created 2946, written 588395
0.00 reads/s, 0.00 creates/s, 17.69 writes/s
Buffer pool hit rate 1000 / 1000
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Main thread process no. 18226, id 1861864336, state: sleeping
Number of rows inserted 195686, updated 15931799, deleted 96811, read 3115284472
0.00 inserts/s, 2399.24 updates/s, 0.00 deletes/s, 649207.46 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================