MongoDB - 文件大小巨大且不断增长
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6263729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MongoDB - file size is huge and growing
提问by Andrew
I have an application that use mongo for storing short living data. All data older than 45 minutes is removed by script something like:
我有一个使用 mongo 来存储短期数据的应用程序。所有超过 45 分钟的数据都被脚本删除,例如:
oldSearches = [list of old searches]
connection = Connection()
db = connection.searchDB
res = db.results.remove{'search_id':{"$in":oldSearches}})
I've checked current status -
我检查了当前状态 -
>db.results.stats()
{
"ns" : "searchDB.results",
"count" : 2865,
"size" : 1003859656,
"storageSize" : 29315124464,
"nindexes" : 1,
"ok" : 1
}
So, according to this 1gb of data occupies 29GB of storage. Data folder looks like this(You may see that many files are very old - last accessed in the middle of may):
所以,按照这 1GB 的数据占用 29GB 的存储空间。数据文件夹看起来像这样(您可能会看到许多文件很旧 - 最后一次访问是在 5 月中旬):
ls -l /var/lib/mongodb/
total 31506556
-rwxr-xr-x 1 mongodb nogroup 6 2011-06-05 18:28 mongod.lock
-rw------- 1 mongodb nogroup 67108864 2011-05-13 17:45 searchDB.0
-rw------- 1 mongodb nogroup 134217728 2011-05-13 14:45 searchDB.1
-rw------- 1 mongodb nogroup 2146435072 2011-05-20 20:45 searchDB.10
-rw------- 1 mongodb nogroup 2146435072 2011-05-28 00:00 searchDB.11
-rw------- 1 mongodb nogroup 2146435072 2011-05-27 13:45 searchDB.12
-rw------- 1 mongodb nogroup 2146435072 2011-05-29 16:45 searchDB.13
-rw------- 1 mongodb nogroup 2146435072 2011-06-07 13:50 searchDB.14
-rw------- 1 mongodb nogroup 2146435072 2011-06-06 01:45 searchDB.15
-rw------- 1 mongodb nogroup 2146435072 2011-06-07 13:50 searchDB.16
-rw------- 1 mongodb nogroup 2146435072 2011-06-07 13:50 searchDB.17
-rw------- 1 mongodb nogroup 2146435072 2011-06-06 09:07 searchDB.18
-rw------- 1 mongodb nogroup 268435456 2011-05-13 14:45 searchDB.2
-rw------- 1 mongodb nogroup 536870912 2011-05-11 00:45 searchDB.3
-rw------- 1 mongodb nogroup 1073741824 2011-05-29 23:37 searchDB.4
-rw------- 1 mongodb nogroup 2146435072 2011-05-13 17:45 searchDB.5
-rw------- 1 mongodb nogroup 2146435072 2011-05-18 17:45 searchDB.6
-rw------- 1 mongodb nogroup 2146435072 2011-05-16 01:45 searchDB.7
-rw------- 1 mongodb nogroup 2146435072 2011-05-17 13:45 searchDB.8
-rw------- 1 mongodb nogroup 2146435072 2011-05-23 16:45 searchDB.9
-rw------- 1 mongodb nogroup 16777216 2011-06-07 13:50 searchDB.ns
-rw------- 1 mongodb nogroup 67108864 2011-04-23 18:51 test.0
-rw------- 1 mongodb nogroup 16777216 2011-04-23 18:51 test.ns
According to "top" mongod uses 29G of virtual memory ( and 780Mb of RSS)
根据“顶级”mongod 使用 29G 的虚拟内存(和 780Mb 的 RSS)
Why do i have such abnormal values? Do i need to run something additional to .remove() function to clean up database from old values?
为什么我会有这么不正常的价值观?我是否需要在 .remove() 函数之外运行一些额外的东西来清理数据库中的旧值?
回答by Tomasz Nurkiewicz
Virtual memory sizeand resident size will appear to be very large for the mongod process. This is benign: virtual memory space will be just larger than the size of the datafiles open and mapped; resident size will vary depending on the amount of memory not used by other processes on the machine.
mongod 进程的虚拟内存大小和常驻大小看起来非常大。这是良性的:虚拟内存空间将仅大于打开和映射的数据文件的大小;驻留大小将根据机器上其他进程未使用的内存量而有所不同。
http://www.mongodb.org/display/DOCS/Caching
http://www.mongodb.org/display/DOCS/Caching
When you remove an object from MongoDB collection, the space it occupied is not automatically garbage collected and new records are only appended to the end of data files, making them grow bigger and bigger. This explains it all:
当你从 MongoDB 集合中移除一个对象时,它占用的空间不会被自动垃圾收集,新记录只会附加到数据文件的末尾,使它们变得越来越大。这说明了一切:
http://www.mongodb.org/display/DOCS/Excessive+Disk+Space
http://www.mongodb.org/display/DOCS/Excessive+Disk+Space
For starters, simply use:
对于初学者,只需使用:
db.repairDatabase()