MongoDB GridFS 删除操作太慢,而 mongod 进程占用 100% CPU

MongoDB GridFS delete operation too slow while mongod process takes up 100% CPU

我正在使用 Python(Debian 7.8 amd64 上的 CPython 2.7.3)和 pymongo 驱动程序(版本 2.7.2)连接到 MongoDB(db 版本 v2.4.12)数据库,仅用于在 GridFS 存储集合中存储文件。虽然 mongodb 可以立即找到具有给定 filename 的文件对象的 _id,但根据其 _id 请求删除该文件需要不寻常的 10 秒才能完成,在此期间mongod 占用 100% CPU 时间。

我不是 mongodb 专家,也没有对其进行任何性能优化,但我仍然认为这里有问题。我错过了什么,我该如何查明并解决这个问题?

我要补充一点,这个集合中有数百万个文件,大小将近 700GB,磁盘上剩余的可用 space 运行 非常少。

我遇到了同样的问题,并通过添加可显着加快 GridFS 速度的索引解决了该问题。
添加索引的命令是:

db.fs.chunks.createIndex( { files_id: 1, n: 1 }, { unique: true } );  // This allows GridFS to find the chunks in order very quickly.

db.fs.files.createIndex( { filename: 1, uploadDate: 1 } );  // This allows GridFS to find the files quickly. 

对于这样大小的集合,创建索引需要一些时间。祝您愉快。