amazon-web-services - 扫描 10GB 的大型 Amazon DynamoDB 数据
问题描述
以下代码适用于我,但 1 个 API 请求需要 19 分钟才能返回结果。一个优化的结果将不胜感激。我不想去细分,因为那样我将不得不进行线程管理。
dynamodb = boto3.resource('dynamodb', region_name='us-west-2', endpoint_url="http://localhost:8000")
table = dynamodb.Table('Movies')
fe = Key('year').between(1950, 1959)
pe = "#yr, title, info.rating"
# Expression Attribute Names for Projection Expression only.
ean = { "#yr": "year", }
esk = None
response = table.scan(
FilterExpression=fe,
ProjectionExpression=pe,
ExpressionAttributeNames=ean
)
for i in response['Items']:
print(json.dumps(i, cls=DecimalEncoder))
// As long as LastEvaluatedKey is in response it means there are still items from the query related to the data
while 'LastEvaluatedKey' in response:
response = table.scan(
ProjectionExpression=pe,
FilterExpression=fe,
ExpressionAttributeNames= ean,
ExclusiveStartKey=response['LastEvaluatedKey']
)
for i in response['Items']:
print(json.dumps(i, cls=DecimalEncoder))
解决方案
因为它是在所有分区中搜索,所以scan
操作可能非常慢。如果您正在使用关系数据库,您将无法像使用关系数据库那样“调整”此查询。
为了最好地帮助您,我需要更多地了解您的访问模式(按年获取电影?)以及您的表当前的外观(您的分区键/排序键,其他属性等)。
推荐阅读
- angular - Cypress Docker 容器无法安装 NPM 依赖项
- r - dplyr 中的嵌套 group_by 操作:第二次调用是否包含第一次调用?
- c - 导致 EXC_BAD_ACCESS 的指针分配
- macos - brew安装时分配依赖项python版本
- android - 如何创建大型离线数据存储库 Android 应用程序?
- c# - Godot C#“来自信号的错误调用方法”
- ruby-on-rails - 如何在 Ruby CSV 中导入数据之前检查标头是否存在?
- html - 如何将图像的背景颜色设置为黑色?
- c# - 如何仅在 Google 表格中为特定单元格更新前景色
- api - Rails 6:版本控制 API 时没有方法错误