0

我正在使用Ruby 的delayed_job_mongoid gem 在后台排队一些map/reduce 作业。作业过程很好,大约一分钟内完成。

现在我正在尝试在处理作业时查询它们的状态,但我发现在 map/reduce 运行时我在延迟作业表上执行的任何查询都挂在那里,阻塞直到所有作业完成.

因此,例如,如果我在 map/reduce 运行时执行 db.delayed_jobs.find(),它会一直坐在那里,直到最后一个作业完成,然后它最终会显示表的内容(此时它是空的)。几乎就像在作业运行时整个表都被锁定了一样。这不是我所期望的。

我已经检查过了,我没有用完数据库连接。有谁知道发生了什么?

4

1 回答 1

0

This is actually a limitation of how MongoDB's map reduce works at the moment. For the time being, MongoDB still has DB level locking and map reduce jobs in particular take out both a read and write lock unless the job is explicitly non-atomic.

You can read more about how to make the mapReduce command non-atomic here (caveat: this is only available in MongoDB v2.2+).

If nonAtomic is true, the post-processing step will prevent MongoDB from locking the database; however, other clients will be able to read intermediate states of the output collection. Otherwise the map reduce operation must lock the database during post-processing.

MongoDB's aggregation framework is generally a bit more performant than map reduce. However, it is fairly new and it can't quite do all the same things just yet. If you can accomplish the same task via the aggregation framework I'd recommend using that instead.

For your reference, here's a list of operation types and what kinds of locks each operation requires:

http://docs.mongodb.org/manual/faq/concurrency/#which-operations-lock-the-database

于 2013-08-22T19:22:57.830 回答