MongoDB 将写入锁定到什么级别?(或:“每个连接"是什么意思? [英] To what level does MongoDB lock on writes? (or: what does it mean by "per connection"

查看:20
本文介绍了MongoDB 将写入锁定到什么级别?(或:“每个连接"是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 mongodb 文档中,它说:

In the mongodb documentation, it says:

从 2.2 版开始,MongoDB 在每个数据库的基础上为大多数读写操作实现锁.一些全局操作,通常是涉及多个数据库的短期操作,仍然需要全局实例"范围的锁.在 2.2 之前,每个 mongod 实例只有一个全局"锁.

Beginning with version 2.2, MongoDB implements locks on a per-database basis for most read and write operations. Some global operations, typically short lived operations involving multiple databases, still require a global "instance" wide lock. Before 2.2, there is only one "global" lock per mongod instance.

这是否意味着在我有 3 个连接到 mongodb://localhost/test 从网络上运行的不同应用程序的情况下 - 一次只能写入一个?还是只是每个连接?

Does this mean that in the situation that I Have, say, 3 connections to mongodb://localhost/test from different apps running on the network - only one could be writing at a time? Or is it just per connection?

IOW:是每个连接,还是在写入时整个/test 数据库被锁定?

IOW: Is it per connection, or is the whole /test database locked while it writes?

推荐答案

不是每个连接,而是每个 mongod.换句话说,该锁将存在于到该服务器上 test 数据库的所有连接中.

It is not per connection, it is per mongod. In other words the lock will exist across all connections to the test database on that server.

它也是一个读/写锁,所以如果正在发生写,那么读必须等待,否则 MongoDB 怎么知道它是一致读?

It is also a read/write lock so if a write is occuring then a read must wait, otherwise how can MongoDB know it is a consistent read?

但是,我应该提到 MongoDB 锁与您获得的 SQL/普通事务锁非常不同,通常在平均更新之间,锁会保持大约一微秒.

However I should mention that MongoDB locks are very different to SQL/normal transactional locks you get and normally a lock will be held for about a microsecond between average updates.

这篇关于MongoDB 将写入锁定到什么级别?(或:“每个连接"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆