如何在 App Engine 数据存储上保留有序列表,让每个实体都知道其在列表中的位置?
我根据人们获得的积分对他们进行排名。例如,我需要告诉每个参与者他们在游戏中的立场, 约翰 (1) - 170 分,玛丽 (2) - 160 分,莎拉 (3) - 110 分
所以约翰是第一个,玛丽是第二个,莎拉是第三个。现在,如果玛丽再赢 20 分,她将成为第一,约翰将成为第二。
我试图避免在 cron 上运行任务来列出并重新计算每个人的位置。
我的第一次尝试是维护一组单独的实体(PersonRank),这样我就不会遇到事务问题,这个排名将具有相同的键名称,所以我可以通过键 db.get() 。该实体将具有该人的计算排名,因此当一个人获得分数时,我必须检查该行上的下一个人的分数是否比我少,并与我交换位置,以便这是真的。 问题是,在这个例子中,莎拉可能赢得了 100 分,现在排名第一。在以前的算法中,我必须在许多实体之间“行走”,这意味着大量的 DataStore 获取和放置(将每个涉及的实体更新到新位置)。
我的下一个猜测可能是某种带有 ReferenceProperties 的链接列表,可能使用键名称来表示位置。
关于如何实施这一点有任何线索吗?
I have a ranking of people, based on points they earn. I need to tell each participant their position on the game for example,
John (1) - 170 points, Mary (2) - 160 points, Sarah (3) - 110 points
So John's the first one, Mary's the seconds and Sarah's the third. Now if Mary wins 20 more points, she'll be the first and john will be the second.
I'm trying to avoid having to run a task on cron to list and recalculate everybody's position.
My first try was to maintain a separate set of entities (PersonRank) so I wouldn't run into transaction problems, this rank would have the same key name, so I could db.get() by key. This entity would have the person's calculated rank, so when a Person receives points, I'd have to check if the next Person on the line has fewer points than me, and exchange places with me so that's true.
The problem is that Sarah, on the example, may have won 100 points, and is now number one. On the previous algorithm, I'd have to "walk" among a lot of entities, which means a lot of DataStore gets and puts (updating each involved Entity to the new position).
My next guess is maybe some kind of linked list with ReferenceProperties, maybe using the key names to denote the position.
Any clues about how to implement this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
比我复杂得多,但希望 Google 的一些人已经实现了这个解决方案 - http://googleappengine.blogspot.com/2009/01/google-code-jams-ranking-library.html
Much more complex than I though, but hopefully some guys at Google already implemented this solution - http://googleappengine.blogspot.com/2009/01/google-code-jams-ranking-library.html
正如您 3 年前自我回答的那样,Google 实现了这个解决方案,但他们专门针对 Python 实现了这一点。 java有非官方的解决方案,有人重写了Python解决方案并决定分享它:
http://toolongdidntread.com/ google-app-engine/using-googles-datastore-to-implement-a-ranked-scoreboard/
人们说它工作正常,但我还没有使用它。我可能会决定在接下来的几个月内使用它,这样我就可以写更多关于它的内容。请注意,Java 和 Python 解决方案每秒只能处理 3 个请求(!)。
更多阅读这里:
https://cloud.google.com/developers/ articles/fast-and-reliable-ranking-in-datastore/
基本上,它说 Google 升级了代码,以便它可以处理 300 个请求/秒,他们说如果你购买他们的高级支持,他们可以帮助你,但他们不会与凡人分享现成的解决方案。另外,所有代码和参考资料都是用 Python 编写的,但这很明显。
仍然没有比这里提到的更好的解决方案,至少我不知道有什么。
As you self-answered 3 years ago, Google implemented this solution, but they did that for Python exclusively. There is unofficial solution for java, someone re-writted Python solution and decided to share it:
http://toolongdidntread.com/google-app-engine/using-googles-datastore-to-implement-a-ranked-scoreboard/
People say it works fine, I did not use it yet though. I might decide to use it in next few months so I could write more about it then. Be aware that both Java and Python solutions can deal with 3 requests/sec only (!).
More reading here:
https://cloud.google.com/developers/articles/fast-and-reliable-ranking-in-datastore/
Basically, it says Google upgraded the code so it could deal with 300 requests/sec, and they said if you buy their premium-level support, they could help you with that, but they will not share the ready-to-go solution with the mere mortals. Also, all the code and references are in Python, but thats pretty obvious.
There is still no better solution than those mentioned here, at least I'm not aware of any.