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

查看:555
本文介绍了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:是每个连接还是整个/测试数据库在写入时锁定?

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天全站免登陆