douningzhi1991 2018-05-14 21:52
浏览 222
已采纳

PutItem进入DynamoDB的速度很慢

I have an EC2 instance which opens up a json file, reads each line and does a putItem operation into two tables.

Without the putItem operation, Golang parses a 67k line file in about 3 seconds.

With the putItem operation, it is processing 10k items every 5 minutes. The put operation into dynamodb is not being throttled. The WCUs and RCUs have been set accordingly. So Is there a reason that the putItem operation is holding up the code?

I assume that Golang is waiting for each put operation to succeed?

Still quite unsure, if anyone has done a mass insert into dynamodb using golang, then it would be helpful if you shedded some light on how you circumvented this.

  • 写回答

1条回答 默认 最新

  • doucan957495 2018-05-15 07:40
    关注

    The slowness comes from the fact that each insert has to do a full HTTP round trip to dynamo.

    10k items in 5 mins is about 30ms per item, which is expected of an HTTP trip.

    You can use a batch update, docs here

    In the docs, you have BatchWriteItemInput, which takes a map[string][]*WriteRequest.

    type BatchWriteItemInput struct {
        // ... trimmed
    
        RequestItems map[string][]*WriteRequest
    
        ...
    }
    

    The WriteRequest model is a little odd, because its used for both Delete and Put operations, just ignore the DeleteRequest *DeleteRequest field.

    It's important to note that there are some limits on the batch operation:

    • You can't change the same item more than once in a batch request
    • You must have more than 2 and fewer than 25 items in a batch
    • Each item cannot be bigger than 400KB and the total batch cannot be bigger than 16MB.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog