database - AWS DynamoDB - 如何设计一个表/索引来有效检索大量具有特定值/状态的项目

标签 database amazon-web-services database-design amazon-dynamodb

我有一张表记录每个项目的工作状态(只有几个)。说 ["initial", "executing", "executed"] 并且此表中有大量具有不同作业状态的项目。

我的问题是我应该如何设计一个能够快速检索具有指定作业状态的所有作业的表/索引。

我考虑过创建一个以工作状态作为散列键的索引。这似乎可行,但我发现它在 dynamodb 中被视为糟糕的设计。

有没有更好的设计来解决这类问题?

谢谢。

最佳答案

恐怕,不,没有更好的解决方案来解决这类问题。

正如他们在 the docs 中所说的那样:

The partition key portion of a table's primary key determines the logical partitions in which a table's data is stored. This in turn affects the underlying physical partitions. Provisioned I/O capacity for the table is divided evenly among these physical partitions. Therefore a partition key design that doesn't distribute I/O requests evenly can create "hot" partitions that result in throttling and use your provisioned I/O capacity inefficiently.

...

If a single table has only a small number of partition key values, consider distributing your write operations across more distinct partition key values. In other words, structure the primary key elements to avoid one "hot" (heavily requested) partition key value that slows overall performance.

这意味着如果值只有几个不同的值——无论是表的分区键,还是索引的分区键——这些值将被放在同一个分区中,这将使它“热”并且您将无法将负载分配给它们。这就像一个“微扫描”:你不是在扫描整个表(好消息),只是一个分区。但是该分区仍然有大量数据,您正在对该分区进行全面扫描(坏消息)。

您可以使用 parallel scans 稍微改进一下(您可以扫描整个表或 GSI),但它仍然不是 Elixir 。

一般事件:如果您按几个唯一值分布大量数据,这就是瓶颈。

你能换个角度看这个问题吗?看起来您正在为作业的状态转换做一些逻辑。你能切换到DynamoDB streams / Triggers吗?每当您的记录更改时启用 DynamoDB 流,DynamoDB 将在流中发送该更改,以便相关方可以使用它。您可以制作一个 Lambda 函数,该函数将读取该流并在每次更改发生时立即对其使用react(好吧,不是立即,但滞后是最小的)。如果您可以将您的工作流重构为这个事件驱动模型,您将不需要任何查询或扫描。

关于database - AWS DynamoDB - 如何设计一个表/索引来有效检索大量具有特定值/状态的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57320473/

相关文章:

php - 标题中数据库中的行,设置为显示在所有页面中

amazon-web-services - 如何运行我的 CDK 应用程序?

sql-server - SQL Server 连接到 Node js

Java:尝试创建一个存储的数据库

java - aws "Cannot create enum from "+ 区域名称 + "value!"

mysql - MySQL 中的产品和订单表结构

database - 自动调整 levelDB 磁盘空间?

android - 未创建 SQLite 数据库

database - 如何在cassandra中定义动态列族

amazon-web-services - cfn-init 是否需要从 UserData 调用?