gae アプリ 開発メモ

Google App Engine アプリの開発メモ / 言語: python, javascript / ビギナー

memcacheの速度計測

ボチボチのデータの読み書き


memcacheに対して、1つのkeyに辞書をぶら下げたときの get/set の速度を計測。
辞書は 1000 件。
サイズは 3.7KBらしい。(Memcache Viewer がそう言ってるので)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from google.appengine.api import memcache

master_dict = {}

def initialize():
    # 読み書きサンプルの1000件の辞書オブジェクトを作成する
    global master_dict

    for n in range(1000):
        master_dict['key%05d' % n] = {
            'name': 'name%05d' % n,
            'age': n
        }

    memcache.set('master_dict', master_dict)

def test_get():
    d = memcache.get('master_dict')

def test_set():
    memcache.set('master_dict', master_dict)

initialize()

デプロイして計測した結果。

# 1 回目
test_get()  54,638.20934 usec/pass
test_set() 102,742.24043 usec/pass

# 2 回目
test_get()  58,820.97960 usec/pass
test_set() 102,911.06939 usec/pass

get()で 60ms 弱はなかなか遅い気もする。

ちなみにウチのローカル環境では、

test_get() 156.98291 usec/pass
test_set() 253.90111 usec/pass

なので、注意が必要みたい。


なお、10000 件の辞書オブジェクト(448.3 KB)の計測は、無料の環境では計測できなかった。
時間あたりのトラフィック(?)が多すぎるらしい。

memcache.incr()

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from google.appengine.api import memcache

def initialize():
    memcache.set('criticalsection', 0)

def test_incr():
    d = memcache.incr('criticalsection')

initialize()

結果は、

# 1回目
test_incr() 3,657.66151 usec/pass

# 2回目
test_incr() 3,739.51211 usec/pass

incr()でも 4ms 弱だそうだ。