简体   繁体   English

在mongodb中插入文档时出现“打开文件过多”错误

[英]Getting 'too many open files' error when inserting documents in mongodb

I am creating a largish (80k collections, 200k documents per collection) database in Mongo. 我在Mongo中创建了一个大型数据库(每个集合80k个文档,每个集合200k个文档)。 When I start pushing documents into the database, I keep getting the following error after ~800k inserts. 当我开始将文档推入数据库时​​,在插入〜800k之后,我不断收到以下错误。

pymongo.errors.WriteError: 24: Too many open files

I have a decent sized server (2 vCPU, 32 GB RAM). 我有一个体面的服务器(2个vCPU,32 GB RAM)。 ulimit for file open is set to unlimited. 文件打开的ulimit设置为无限制。 And limit nofile 999999 999999 is set in /etc/init/mongodb.conf. 在/etc/init/mongodb.conf中设置了limit nofile 999999 999999

I have tried inserting sleep (with the hope that mongodb will close files after a bit) in the file insertion script but that hasn't helped either. 我曾尝试在文件插入脚本中插入sleep (希望mongodb稍候会关闭文件),但这也没有帮助。 The only thing that works is restarting Mongodb after the insertion has failed. 唯一可行的方法是插入失败后重新启动Mongodb。 Then the process can resume. 然后,该过程可以继续。

How can I make insertion process better without having to pause it after every few thousand inserts and restarting mongodb? 如何使插入过程更好,而不必每隔几千次插入并重新启动mongodb之后就暂停它?


Sharing the Python script that is transferring datapoint from redis to mongo 共享将数据点从Redis传输到mongo的Python脚本

while (redis_conn.llen(redis_key) > 0) :
            redis_json = redis_conn.lpop(redis_key)
            json_doc = json.loads(redis_point)
            collection_name = json_doc['collection_name']
            collection = mongodb[collection_name]
            document = { '1' : json_doc['1'], '2' : json_doc['2'] }
            mongo_write_response = collection.insert_one(document)

(For brevity I have simplified the document. The actual document has around 20 data points. (为简洁起见,我简化了文档。实际文档中包含大约20个数据点。

The problem seems to be with the installation of MongoDB. 问题似乎出在MongoDB的安装上。 I was using Debian 9 and used apt-get to install the version of MongoDB that ships bundled with the OS. 我使用的是Debian 9,并使用apt-get安装了操作系统随附的MongoDB版本。

Since MongoDB documentation said it does not support Debian 9 yet, downgraded the OS to Debian 8 and installed MongoDB community edition as per the documentation . 由于MongoDB文档表示尚不支持Debian 9,因此将操作系统降级为Debian 8并根据文档安装了MongoDB社区版。 It is working well now :) 现在运作良好:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM