什么是运动数据流中的分片

What is shards in kinesis data stream

什么是运动数据流和分区键中的分片。我阅读了 aws 文档,但我不明白。谁能简单解释一下?

来自Amazon Kinesis Data Streams Terminology and Concepts - Amazon Kinesis Data Streams

A shard is a uniquely identified sequence of data records in a stream. A stream is composed of one or more shards, each of which provides a fixed unit of capacity. Each shard can support up to 5 transactions per second for reads, up to a maximum total data read rate of 2 MB per second and up to 1,000 records per second for writes, up to a maximum total data write rate of 1 MB per second (including partition keys). The data capacity of your stream is a function of the number of shards that you specify for the stream. The total capacity of the stream is the sum of the capacities of its shards.

因此,分片有两个用途:

  • 一定数量的capacity/throughput
  • 消息的有序列表

如果您的应用程序必须按顺序处理所有 条消息,那么您只能使用一个分片。把它想象成银行里的一条线——如果只有一条线,那么每个人都会按顺序得到服务。

但是,如果消息只需要为消息的某个子集排序,则可以将它们发送到单独的分片。例如,银行中的多条线路,每条线路都按顺序提供服务。或者,想想发送 GPS 坐标的公共汽车。每条总线仅将消息发送到一个分片。一个分片可能包含来自多个总线的消息,但每个总线只发送到一个 个分片。这样,当处理来自该分片的消息时,来自特定总线的所有消息都会按顺序处理。

这是通过使用标识源的分区键来控制的。分区键被散列并分配给一个分片。因此,具有相同分区键的所有消息都将转到同一个分片。

在 back-end,每个分片有一个 通常一个工作人员 按顺序处理来自该分片的消息。

如果您的系统不关心保留消息顺序,则使用随机分区键。这意味着消息将被发送到任何分片。