MongoDB:对数据库的读/写是否并发?

发布于 2024-12-10 14:43:23 字数 105 浏览 0 评论 0原文

当百万个线程尝试同时读取写入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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

≈。彩虹 2024-12-17 14:43:23

它发生在数据库级别,但是对于 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.

我纯我任性 2024-12-17 14:43:23

您可能会遇到并发问题,特别是当您使用单个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文