Google Cloud Datastore - 索引简短枚举列表的可扩展性
Google Cloud Datastore - Scalability of indexing a short list of enums
在 Datastore 中索引只能有 4-5 个可能值的 属性 是否存在问题?这会导致平板电脑热点吗?
我正在考虑 属性,其中包含一个字符串值枚举,例如 "done"、"working"、"complete"。索引这样的 属性 的原因是您可以创建一个复合索引,让您查询所有 "done" 的实体。
是的,这将是一个问题 if/when 使用您提到的这些复合索引的查询率很高,列在 Indexes:
- Do not index properties with monotonically increasing values (such as a
NOW()
timestamp). Maintaining such an index could lead to
hotspots that impact Cloud Datastore latency for applications with
high read and write rates. For further guidance on dealing with
monotonic properties, see High read/write rates for a narrow key
range below.
您还会遇到平板电脑热点问题 if/when 您对具有相同 属性 值的实体的数据存储写入率很高(例如,每秒有 100 个实体变为 done
) - 同一问题的另一个方面。就是High read/write rates to a narrow key range:
中提到的这种情况
- You will also see this problem if you create new entities at a high rate with a monotonically increasing indexed property like a
timestamp, because these properties are the keys for rows in the index
tables in Bigtable.
TLDR:只要实体键是分散的,它就可以扩展。
DR:
让我们首先考虑正在写入的索引条目。
我们有类似的东西:
SomeKind\E1 -> FullEntityKey1
SomeKind\E2 -> FullEntityKey2
SomeKind\E2 -> FullEntityKey3
SomeKind\E3 -> FullEntityKey4
我们注意到每个单独的索引条目都指向某个实体。
就负载分片而言,分片的值如下所示:
SomeKind\E1\FullEntityKey1
SomeKind\E2\FullEntityKey2
SomeKind\E2\FullEntityKey3
SomeKind\E3\FullEntityKey4
现在假设我们为实体键使用随机分配的 ID(范围 [0,2] 很简单)——我们假设写入在随机实体 ID 之间均匀分布。
SomeKind\E1[=12=]\RestOfKey1
SomeKind\E2[=12=]\RestOfKey2
SomeKind\E2\RestOfKey3
SomeKind\E3\RestOfKey4
然后我们可以注意到,有明确的分割点供负载分片——也就是说,每个 [0,2] 可能的随机 ID 都是一个分片,只要系统可以无限扩展写入在 SomeKind 写入的实体中均匀分布(使随机 ID 更长以进行更多拆分 points/scaling)
因此,索引枚举值 scaling/hotspotting 与被索引的实体键高度相关,实体键通常以可分片的方式构建,这意味着关联的索引条目也是。
这并不是说不可能创造 hotspots 可能发生的情况(例如,如果实体键具有单调递增的值(如时间戳)),或者通过针对一小部分密钥可实现非常高的写入率——但默认情况下,典型的流量模式和实体密钥不应发生这种情况。
在 Datastore 中索引只能有 4-5 个可能值的 属性 是否存在问题?这会导致平板电脑热点吗?
我正在考虑 属性,其中包含一个字符串值枚举,例如 "done"、"working"、"complete"。索引这样的 属性 的原因是您可以创建一个复合索引,让您查询所有 "done" 的实体。
是的,这将是一个问题 if/when 使用您提到的这些复合索引的查询率很高,列在 Indexes:
- Do not index properties with monotonically increasing values (such as a
NOW()
timestamp). Maintaining such an index could lead to hotspots that impact Cloud Datastore latency for applications with high read and write rates. For further guidance on dealing with monotonic properties, see High read/write rates for a narrow key range below.
您还会遇到平板电脑热点问题 if/when 您对具有相同 属性 值的实体的数据存储写入率很高(例如,每秒有 100 个实体变为 done
) - 同一问题的另一个方面。就是High read/write rates to a narrow key range:
- You will also see this problem if you create new entities at a high rate with a monotonically increasing indexed property like a timestamp, because these properties are the keys for rows in the index tables in Bigtable.
TLDR:只要实体键是分散的,它就可以扩展。
DR:
让我们首先考虑正在写入的索引条目。
我们有类似的东西:
SomeKind\E1 -> FullEntityKey1
SomeKind\E2 -> FullEntityKey2
SomeKind\E2 -> FullEntityKey3
SomeKind\E3 -> FullEntityKey4
我们注意到每个单独的索引条目都指向某个实体。
就负载分片而言,分片的值如下所示:
SomeKind\E1\FullEntityKey1
SomeKind\E2\FullEntityKey2
SomeKind\E2\FullEntityKey3
SomeKind\E3\FullEntityKey4
现在假设我们为实体键使用随机分配的 ID(范围 [0,2] 很简单)——我们假设写入在随机实体 ID 之间均匀分布。
SomeKind\E1[=12=]\RestOfKey1
SomeKind\E2[=12=]\RestOfKey2
SomeKind\E2\RestOfKey3
SomeKind\E3\RestOfKey4
然后我们可以注意到,有明确的分割点供负载分片——也就是说,每个 [0,2] 可能的随机 ID 都是一个分片,只要系统可以无限扩展写入在 SomeKind 写入的实体中均匀分布(使随机 ID 更长以进行更多拆分 points/scaling)
因此,索引枚举值 scaling/hotspotting 与被索引的实体键高度相关,实体键通常以可分片的方式构建,这意味着关联的索引条目也是。
这并不是说不可能创造 hotspots 可能发生的情况(例如,如果实体键具有单调递增的值(如时间戳)),或者通过针对一小部分密钥可实现非常高的写入率——但默认情况下,典型的流量模式和实体密钥不应发生这种情况。