MongoDB :are reads/writes to database concurrent?

▼魔方 西西 提交于 2020-01-03 13:21:10

问题


What happens when million threads try to read from and write to MongoDB at the same time? does locking happens on a db-level, table-level or row-level?


回答1:


It happens at db-level, however with Mongo 2.0 there are a few methods for concurrency, such as inserting/updating by the _id field.




回答2:


You might run into concurrency problems, especially if you're working with a single MongoDB instance rather than a sharded cluster. The threads would likely start blocking eachother as they wait for writes and other operations to complete and locks to be released.

Locking in MongoDB happens at the global level of the instance, but some operations since v2.0 will yield their locks (update by _id, remove, long cursor iteration). Collection-level locking will probably be added sometime soon.

If you need to have a large number of threads accessing MongoDB, consider placing a queue in front to absorb the impact of the concurrency contention, then execute the queued operations sequentially from a single thread.



来源:https://stackoverflow.com/questions/7828875/mongodb-are-reads-writes-to-database-concurrent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!