gpt4 book ai didi

amazon-web-services - 哪个哈希键最适合 DynamoDB 中的事件数据?

转载 作者:IT王子 更新时间:2023-10-29 06:01:39 26 4
gpt4 key购买 nike

我正在使用 Amazon DynamoDB 为事件流存储基于事件的数据。

我为每个月自动创建一个新表,并打算将事件数据存储在每个相关表中。通过这种方式,我可以在需要时通过删除旧表快速修剪旧月份,并更好地为更新的表提供负载。

然而,通过阅读亚马逊文档,我可以看出哈希键本身非常重要。

Provisioned throughput is dependent on the primary key selection, and the workload patterns on individual items. When storing data, Amazon DynamoDB divides a table's items into multiple partitions, and distributes the data primarily based on the hash key element. The provisioned throughput associated with a table is also divided evenly among the partitions, with no sharing of provisioned throughput across partitions.

我很难理解这个问题。

因此我的问题是,考虑到以上几点,这两者之间哪个哈希键更好:

1382465533_john.doe

或:

john.doe_1382465533

以上键是用户id和事件时间戳的组合。

如何查询这些表...

这些表将有一个范围键,因为对于这个用例它不是必需的。

此数据将用于为用户构建事件源。

当事件发生时,个人事件 ID 被推送(扇出)到用户关注者 redis 列表(每个用户一个列表);

因此,当用户请求他们的流时,我们会执行以下操作:

  1. Redis 获取 activityid 列表
  2. 遍历 activityid 并构建 BatchGetItem 查询以将它们从 DynamoDB 中提取出来。

考虑到所有这些,我需要了解的是如何最好地在事件表中定义我的哈希键。时间戳优先或用户标识优先。 DynamoDB 使用什么逻辑来自动分区哈希键?

提前感谢您的任何建议。

最佳答案

根据您的问题,我会说您如何编写哈希键并不重要,因为您必须使用该哈希键的确切值来查询您的表,而 DynamoDB 会将其视为字符串反正。另一件事是,如果您正在编写范围键,那么您可能希望按如下方式编写它

john.doe_1382465533

所以你可以像这样轻松查询你的表

hash key = whatever, range key >= john.doe_1382460000

也就是说,也许您可​​以通过像这样将 Redis 事件提要直接集成到 DynamoDB 中来摆脱它:

hash key: user id

range key: timestamp

the rest of the activity data

因此,无需将事件推送到 DynamoDB 并将事件 ID 推送到 Redis,您只需推送它并从同一个 DynamoDB 表中查询它。我不知道这是否与您的应用程序的其余部分兼容,但这是一个想法。

关于amazon-web-services - 哪个哈希键最适合 DynamoDB 中的事件数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19552922/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com