DAOCLOUD
推荐学习书目
Python Cookbook
Using Google App Engine
推荐下载
Latest Google App Engine SDK
其他兼容技术
AppScale
ayanamist

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

  •  
  •   ayanamist · Jan 28, 2011 · 3609 views
    This topic created in 5596 days ago, the information mentioned may be changed or developed.
    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语言真是太强大了,哇咔咔
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1482 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 16:47 · PVG 00:47 · LAX 09:47 · JFK 12:47
    ♥ Do have faith in what you're doing.