这是另一个 Google App Engine 数据存储问题。
假设我的应用程序跟踪一群老鼠以及它们吃了多少奶酪。每个Rat
实体都有一系列Meal
实体——每个实体跟踪老鼠何时进食以及吃了多少片奶酪(slices
属性)。每只Rat
还有一个total_slices
属性,每当记录新的膳食时该属性都会更新。
每当我需要知道总数时,是否应该放弃 total_slices
属性,转而简单地将每份 Meal
的 slices
加起来?数据存储文档称查询很便宜,而高频更新实体是有问题的(谷歌将“高频”定义为以持续的速率每秒更新一次实体以上)。因此,如果我有一些非常贪婪的老鼠,每秒进食不止一次,那么当我更新 Rat
的 total_slices
时,我就会冒着超时的风险。
对于如何最好地设计这个场景有什么建议吗?
This is another Google App Engine Datastore question.
Let’s say my app tracks a bunch of rats and how much cheese they’ve eaten. Each Rat
entity has a series of Meal
entities -- each tracks when the rat ate and how many slices of cheese (slices
property). Each Rat
also has a total_slices
property that is updated whenever a new meal is logged.
Should I abandon the total_slices
property in favor of simply adding up the slices
of each Meal
whenever I need to know the total? The Datastore documentation says that queries are cheap, while updating an entity at a high frequency is problematic (Google defines “high frequency” as updating an entity more than once a second at a sustained rate). So if I have some really voracious rats that feast more than once a second, I’m risking a timeout when I update the Rat
’s total_slices
.
Any suggestions how to best design this scenario?
发布评论
评论(1)
您的问题包含两个单独的问题:
1。您是否应该将
total_slices
反规范化为Rat
实体?要回答这个问题,您必须分析应用程序的数据访问模式。例如:
Rat
获取total_slices
共同任务?
按
total_slices
列出或排序Rats
?餐
加起来仍然是多年数据后的高效
已经积累了?
2.如果您的实体需要更新速度超过 1 秒,您会在 GAE 中做什么?
使用 分片计数器。
There are two separate issues wrapped up in your question:
1. Should you de-normalize
total_slices
to theRat
entity?To answer this you must analyze the data access patterns of your application. For example:
total_slices
for aRat
acommon task?
list or sort
Rats
bytotal_slices
?Meal
still beefficient after several years of data
have accumulated?
2. What do you do in GAE if you have an entity that needs to be updated more than 1/sec?
Use a Sharded Counter.