我目前正在与Python一起使用App。
我的应用程序看起来像一个大型多人游戏。我想改善在“房间”内取得最新行动所需的时间。
我已经使用Memcache API来存储和检索写吞吐量低的操作(每分钟1次)。此外,我还在考虑检索具有高写吞吐量的操作(如果“房间”中有很多人,每秒钟有几个人):例如,由玩家发布的消息。
您如何建议我为这种高写吞吐量设计memcache存储?是一个单键/值对,其中value =最新发布的操作列表似乎不是正确的解决方案。
谢谢,
发布于 2012-01-17 21:57:10
如果没有你申请的更多细节,就很难回答这个问题。一个简单的想法是使用更多的键/值对。
例如:
# when write action log
# 1. decide the prefix based on the data
prefix = decide_prefix(action)
# 2. random pick up a bulk for this data
index = random.choice(range(100))
# 3. write action into a queue
action_list = memceche.get("%s_%s"%(prefix, index))
action_list.append(action)
memcache.set("%s_%s"%(prefix,index), action_list)
# when read action log
action_lists = memcache.get_multi(["%s_%s"%(prefix, k) for k in range(100)])
# merge all action list together.
all_action_list = merge_action_list(action_lists)此外,您可以使用比较和设置来处理并发请求。http://code.google.com/appengine/docs/python/memcache/overview.html#Using_Compare_and_Set_in_Python
GAE memcahce有其自身的局限性,不能保证数据的持久性。增加memcache的使用可能会导致更多的数据丢失。因此,您仍然需要使用数据存储来保存持久性数据。
http://code.google.com/appengine/docs/python/memcache/overview.html#Quotas_and_Limits
https://stackoverflow.com/questions/8901874
复制相似问题