MongoDB:对数据库的读/写是否并发?
当百万个线程尝试同时读取
和写入
MongoDB
时会发生什么?锁定发生在数据库级、表级还是行级
?
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
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它发生在数据库级别,但是对于 Mongo 2.0,有一些并发方法,例如通过 _id 字段插入/更新。
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.
您可能会遇到并发问题,特别是当您使用单个 MongoDB 实例而不是分片集群时。当线程等待写入和其他操作完成并释放锁时,它们可能会开始互相阻塞。
MongoDB 中的锁定发生在实例的全局级别,但自 v2.0 以来的一些操作将产生锁定(通过 _id 更新、删除、长游标迭代)。集合级锁定可能很快就会添加。
如果需要有大量线程访问 MongoDB,可以考虑在前面放置一个队列来吸收并发争用的影响,然后从单个线程中顺序执行排队的操作。
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.