I run three main tables in engine=memory for speed purposes. I do this as they are read only, built when the MySQL is started, and thus never need to be written to.
There are other on disk tables, such as user preferences, forum postings etc.
This all works fine and I am happy with the speed. But after a few days the amount of memory used by MySQL doubles, such that some of the swap file is accessed.
This is what mysqltuner reports shortly after starting:
-------- General Statistics --------------------------------------------------
[–] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.5.9-log
[OK] Operating on 64-bit architecture
-------- Storage Engine Statistics -------------------------------------------
[–] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[–] Data in MyISAM tables: 389M (Tables: 180)
[–] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[–] Data in MEMORY tables: 1G (Tables: 3)
[!!] InnoDB is enabled but isn’t being used
[!!] Total fragmented tables: 6
-------- Security Recommendations -------------------------------------------
[OK] All database users have passwords assigned
-------- Performance Metrics -------------------------------------------------
[–] Up for: 56m 45s (106K q [31.295 qps], 2K conn, TX: 1B, RX: 30M)
[–] Reads / Writes: 90% / 10%
[–] Total buffers: 581.0M global + 8.8M per thread (28 max threads)
[OK] Maximum possible memory usage: 827.8M (10% of installed RAM)
This shows that the 3 tables are taking 1Gb of memory and that MySQL will take a further possible 827M. Add to that indexes I guess, then the total memory usage for MySQL will be around 2Gb.
If I run top I see this to be the case:
Tasks: 168 total, 1 running, 167 sleeping, 0 stopped, 0 zombie
Cpu(s): 1.5%us, 0.5%sy, 0.0%ni, 97.5%id, 0.2%wa, 0.0%hi, 0.3%si, 0.0%st
Mem: 8164764k total, 5101708k used, 3063056k free, 38072k buffers
Swap: 4096564k total, 19948k used, 4076616k free, 2544960k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3001 mysql 15 0 2269m 1.9g 5392 S 6.0 24.3 1:57.47 mysqld
Each day the server is updated with light forum postings, low count user registrations / preferences, pretty basic stuff.
In the evening the main MEMORY databases are updated with new results. This is performed by dropping and importing a .DBF file with dbf2mysql.
All works well but after a few days the amount of memory used by MySQL more than doubles to 5Gb.
I can not pinpoint exactly why this happens. I think it is like memory leakage, where memory is used but gradually not returned to the pool. MySQL memory take increases, such that the O/S does not have enough for caching and other apps and thus dips into the swap.
If I restart MySQL all is fine again until in a few days times it hits 5Gb again.