分片中的 InsertBatch [英] InsertBatch in Sharding

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

问题描述

如果有一个大的 InsertBatch,在幕后实际发生了什么一个是写入分片集群?MongoDb 是否真的支持批量插入或 InserBatch 实际上一次插入一个服务器级别?那么这如何与分片一起工作?做这个意味着 mongos 将查看批次中的每个项目以找出每个项目的分片键是什么,然后将其路由到右侧服务器?如果它存在并且似乎不存在,这将破坏批量插入高效.用于分片的 InsertBatch 的机制是什么解决方案?我使用的是 2.0 版,如果有什么不同,我愿意升级

What is actually happening behind the scene with a big InsertBatch if one is writing to a sharded cluster? Does MongoDb actually support bulk insert or the InserBatch is actually inserting one at a time at the server level? How does this work with sharding then? Does this mean that a mongos will look at every item in the batch to figure out what is the shard key of each item and then will route it to the right server? This will break bulk insert if it exist and does not seem to be efficient. What is the mechanics of InsertBatch for a sharding solution? I am using version 2.0 and willing to upgrade if that makes any difference

推荐答案

批量插入是 MongoDB 的一项实际功能,由于往返次数较少,因此性能(在某种程度上)比单独的每个文档插入更高.

Bulk inserts are an actual MongoDB feature and are (somewhat) more performant than seperate per-document inserts due to less roundtrips.

在分片环境中,如果 mongos 收到批量插入,它将确定批量的哪一部分必须发送到哪个分片.2.0 和 2.1 之间没有区别,它是将数据批量插入分片数据库的最有效方式.

In a sharded environment if mongos receives a bulk insert it will figure out which part of the bulk has to be sent to which shard. There are no differences between 2.0 and 2.1 and it is the most efficient way to bulk insert data into a sharded database.

如果您对 mongos 的工作原理感到好奇,请在此处查看它的源代码:

If you're curious to how exactly mongos works have a look at it's source code here :

https://github.com/mongodb/mongo/tree/master/src/mongo/s

这篇关于分片中的 InsertBatch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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