MongoDB读/写锁 [英] MongoDB Read/Write Locks

查看:584
本文介绍了MongoDB读/写锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算使用nodejs创建一个应用程序,用户可以对产品进行评分.据我了解,mongodb中的锁与mySql不同.

I'm planning to create an application using nodejs that users can rate the products. From what I heard locks are different in mongodb than mySql.

我担心如果说有10个用户同时对某产品进行投票,那么Mongodb将无法处理该产品,而其他用户看到的结果将是不正确的.

I'm worried that if let's say 10 users vote on a product at a same time, Mongodb can't handle it and the result other users see is not correct.

我看过类似的问题,但我仍然感到困惑! mongodb是一个不错的选择,还是我应该只使用Mysql?感谢您的帮助

I looked at similar questions but I'm still confused! Is mongodb a good choice or should I just use Mysql? I'd appreciate your help

推荐答案

MongoDB文档中的并发常见问题解答.特别是:

MongoDB使用读取器-写入器锁,该锁允许并发读取 访问数据库,但提供对单个写入的独占访问权限 操作.

MongoDB uses a readers-writer lock that allows concurrent reads access to a database but gives exclusive access to a single write operation.

当存在读取锁时,许多读取操作可能会使用此锁. 但是,当存在写锁时,单个写操作将保留 排他地锁定,并且任何其他读取或写入操作都不能共享 锁定.

When a read lock exists, many read operations may use this lock. However, when a write lock exists, a single write operation holds the lock exclusively, and no other read or write operations may share the lock.

锁是写者贪婪",这意味着写锁具有优先权 过度阅读.当读写都在等待锁时,MongoDB 将锁定授予写操作.

Locks are "writer greedy," which means write locks have preference over reads. When both a read and write are waiting for a lock, MongoDB grants the lock to the write.

关于您的陈述:

Mongodb无法处理它,并且其他用户看到的结果不正确.

Mongodb can't handle it and the result other users see is not correct.

MongoDB使用数据库范围内的锁定,该锁定可防止在数据库中某处执行写操作时进行读/写操作.通过此JIRA项的外观,它将被简化为集合级别的锁定未来(现在只是开发版本).同样,由于采用写者贪婪"方法,如果有多个写等待执行,则它们将在任何读之前完成,因此您的关心不应该成为问题.

MongoDB employs a database-wide lock that prevents reads/writes while a write operation is being performed somewhere in the database. By the looks of this JIRA item, this will be reduced to a collection-level lock in the future (right now it's just in a development version). Also, because of the "writer greedy" approach, if multiple writes are waiting to be performed, they will be done before any reads, so your concern shouldn't be an issue.

这篇关于MongoDB读/写锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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