mongodb c#驱动程序中使用InsertBatch方法的最佳批量商品数是多少? [英] What is the optimum bulk item count with InsertBatch method in mongodb c# driver?

查看:264
本文介绍了mongodb c#驱动程序中使用InsertBatch方法的最佳批量商品数是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说大批量生产并不能真正带来任何额外的性能

I heard that large batch sizes don't really give any additional performance

什么是最佳?

推荐答案

如果调用插入"一次插入一个文档,则每个文档都有网络往返.如果调用InsertBatch批量插入文档,则每个批次(而不是每个文档)都有一个网络往返行程. InsertBatch比Insert更有效率,因为它减少了网络往返的次数.

If you call Insert to insert documents one at a time there is a network round trip for each document. If you call InsertBatch to insert documents in batches there is a network round trip for each batch instead of for each document. InsertBatch is more efficient than Insert because it reduces the number of network round trips.

假设您必须插入1,000,000个文档,则可以分析不同批次大小的网络往返次数:

Suppose you had to insert 1,000,000 documents, you could analyze the number of network round trips for different batch sizes:

  • 批量大小1:往返1,000,000次
  • 批量10:往返100,000次
  • 批号100:往返10,000次
  • 批号1000,往返1000次
  • 等...

因此,您看到即使是小至10的批处理也已消除了90%的网络往返,而100的批处理已消除了99%的网络往返.

So you see that even a batch size as small as 10 has already eliminated 90% of the network round trips, and a batch size of 100 has eliminated 99% of the network round trips.

这是一个简化的分析,因为它忽略了以下事实:批大小增加,消息大小也会增加,但是它或多或少是准确的.

This is a somewhat simplified analysis because it ignores the fact that as the batch sizes increase so do the message sizes, but it's more or less accurate.

我认为没有一个最佳批次大小.我要说的是,较大的批次性能更好,但是每批次具有10-100个文档,则较大的批次将带来很小的性能改进.

I don't think that there is any one optimum batch size. I would say that larger batches are more performant, but once you have 10-100 documents per batch there will be very small performance improvements with larger batches.

这篇关于mongodb c#驱动程序中使用InsertBatch方法的最佳批量商品数是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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