V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
DAOCLOUD
推荐学习书目
Python Cookbook
Using Google App Engine
推荐下载
Latest Google App Engine SDK
其他兼容技术
AppScale
ayanamist
V2EX  ›  Google App Engine

Python的语言特性,轻松绕过5次每秒的Write Contention

  •  
  •   ayanamist · 2011-01-28 18:20:39 +08:00 · 3115 次点击
    这是一个创建于 4848 天前的主题,其中的信息可能已经有所发展或是发生改变。
    http://code.google.com/intl/it/appengine/articles/scaling/contention.html
    http://code.google.com/intl/it/appengine/articles/handling_datastore_errors.html
    GAE有每个Entity Group每秒只能写入5次的硬限制,多于五次就会开始抛出ApplicationError 5的错误。
    #TwiTalkerPlus的短ID列表读写很频繁,几乎是1:1,之前想不到什么很好的办法,刚才看Python的文档,发现类可以create on-the-fly,于是想到个hack。

    cls = type('IdList%d' % shard, (IdList,), {})
    short_id_list = cls(key_name=jid, short_id_list_str=data)

    动态的生成一个Entity,然后再写入。这样就可以动态创造很多Entity Group了,每个遇到Write Contention的可能性都要小很多~

    只是要注意的是Pickle之前也要hack一下,否则会报Can't pickle <class 'xxx'>: it's not found as xxx

    setattr(sys.modules[__name__], data.__class__.__name__, type(data))

    Python语言真是太强大了,哇咔咔
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4911 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:07 · PVG 18:07 · LAX 03:07 · JFK 06:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.