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.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题