MongoDb 更新插入死锁
MongoDb upsert 操作是否可能陷入死锁? 我正在对 upsert 操作执行负载测试,如下所示:
db.update(
{ foo: {a: 'xxx', b: 'yyy'}, $lt: {"order.date": someDate}},
{order: order},
true, false);
使用官方 mongodb C# 驱动程序部署在 Azure 计算机上。单实例,还没有副本集或分片。
当我运行 5000 个相同的更新命令时,分成 200 个并发线程(2 台机器,每台 100 个线程),大多数情况下都会以死锁结束。即许多电话再也没有回来。我可以通过控制台从 db.currentOp() 看到,许多更新仍然存在,卡在locked:true 和lockType:'write' 中。
为什么会出现这种僵局呢?怎么可能呢?我该如何预防呢?是否有任何具体的指导方针来说明应避免哪些操作以避免 mongodb 上的死锁?
$atomic 与解决方案有关吗?我什至不知道如何在 c# 上设置 $atomic:true ,尽管它可能与这个死锁问题无关。
Is it possible to reach deadlocks on MongoDb upsert operations?
I'm performing a load-test on an upsert operation that looks like:
db.update(
{ foo: {a: 'xxx', b: 'yyy'}, $lt: {"order.date": someDate}},
{order: order},
true, false);
Deployed on Azure machine with the official mongodb C# driver. Single instance, no replica-sets or sharding yet.
When I run 5000 of this same update command, split among 200 concurrent threads (2 machines @ 100 threads each), most of the times it will end with deadlocks. I.e. many of the calls never come back. I can see from db.currentOp() via the console, many of the updates are still there, stuck in a locked:true, with lockType:'write'.
Why does this deadlock happen? How is it possible? And how do I prevent it? Is there any specific guidelines of what kind of operations should be avoided to avoid deadlocks on mongodb?
Is $atomic related to the solution? I don't even know how to set $atomic:true on c#, though it's probably irrelevant to this deadlock issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$atomic 应该有帮助
另外,你可能需要一个 $and 子句。检查你的通话解释,看看正在使用哪些索引,等等......
$atomic should help
also, you may want an $and clause. check your explain for your call to see what indexes are being used, etc...