You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用boto3操作本地DynamoDB时batch_write性能极慢问题求助

本地DynamoDB批量导入性能优化问题

我使用Python3和boto3库,将本地6个文本文件(总数据达数GB,单个文件约1000万行)加载至Docker部署的本地DynamoDB实例的表中,目前遇到严重性能问题:单个文件加载预估耗时19小时,经性能分析,耗时主要集中在boto3的batch_write_item调用上。

我的批量处理代码如下:

def add_batch(self, items, table):
    request = {
        table: []
    }
    if type(items) is not list:
        print(f'\nError while loading item\'s batch, expecting a <list> but got {type(items)}')
        return None
    for item in items:
        request[table].append(
            {
                'PutRequest': {
                    'Item': item
                }
            }
        )
    while request:
        response = self._client.batch_write_item(RequestItems=request) # by far the slowest call
        if response['UnprocessedItems']:
            request = response['UnprocessedItems']
            print('unprocessed items: ', request)
        else:
            request = None
    return 0

当前批量大小为25条,表吞吐量设为100(尝试过多个数值但效果甚微)。开启InMemory选项时性能更佳,但重启容器需重新加载数据耗时过久,因此改用命令docker run -p 8000:8000 amazon/dynamodb-local -jar DynamoDBLocal.jar启动容器。尝试并行处理时boto3持续抛出异常。

执行加载函数时的资源利用率

内容的提问来源于stack exchange,提问作者tex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 18:48:41