gpt4 book ai didi

python - 应用引擎 : Memcache design to ensure fast read and high write throughput

转载 作者:行者123 更新时间:2023-12-01 06:04:15 25 4
gpt4 key购买 nike

我目前正在将 App Engine 与 Python 结合使用。

我的应用程序看起来像一个大型多人游戏。我想缩短获取“房间”中发布的最新操作所需的时间。

我已经使用 Memcache API 来存储和检索写入吞吐量较低(每分钟 1 次)的操作。此外,我还考虑将其用于检索具有高写入吞吐量的操作(如果“房间”中有很多人,则每秒几次:例如< em>玩家发布的消息)

您建议我如何设计内存缓存存储来实现如此高的写入吞吐量? 单个键/值对(其中值 = 最新发布的操作列表)似乎不是正确的解决方案。

谢谢

最佳答案

如果没有您申请的更多详细信息,很难回答这个问题。一个简单的想法是使用更多的键/值对。

例如:

# 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)

此外,您可以使用compare和set来处理并发请求。 http://code.google.com/appengine/docs/python/memcache/overview.html#Using_Compare_and_Set_in_Python

GAE memcahce 有其自身的局限性,并且不保证数据持久性。增加内存缓存的使用可能会导致更多数据丢失。因此,您仍然需要使用datastore来保存持久性数据。

http://code.google.com/appengine/docs/python/memcache/overview.html#Quotas_and_Limits

关于python - 应用引擎 : Memcache design to ensure fast read and high write throughput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8901874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com