Created
November 15, 2011 13:42
-
-
Save kumagi/1367096 to your computer and use it in GitHub Desktop.
pythonから使えるmemcachedクライアントの比較(シングルスレッド)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def bench(fn): | |
begin = time.time() | |
fn() | |
return time.time() - begin | |
n = 100000 | |
def setwork(cl): | |
for i in range(0, n): | |
cl.set(str(i), i) | |
def getwork(cl): | |
for i in range(0, n): | |
cl.get(str(i)) | |
def set_and_get(module): | |
cl = module.Client(['127.0.0.1:11211']) | |
content = (("set",setwork), ("get", getwork)) | |
for item in content: | |
time = bench(lambda :item[1](cl)) | |
print item[0] + ":" + str(n/time) + " qps." | |
import cmemcached | |
print "cmemcached:" | |
set_and_get(cmemcached) | |
print "pylibmc:" | |
import pylibmc | |
set_and_get(pylibmc) | |
import memcache | |
print "memcache:" | |
set_and_get(memcache) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PyPyで実行(cmemcachedはcythonの関係で使用不可) | |
pylibmc: | |
set:8430.30208222 qps. | |
get:9410.74875972 qps. | |
memcache: | |
set:9280.66762859 qps. | |
get:10494.6056407 qps. | |
# CPythonで実行 | |
cmemcached: | |
set:9730.57020326 qps. | |
get:11322.6547795 qps. | |
pylibmc: | |
set:10296.992951 qps. | |
get:10977.716197 qps. | |
memcache: | |
set:7193.36803759 qps. | |
get:7620.62517156 qps. | |
PyPyだとmemcacheが速く、CPythonだとpylibmcが速い。cmemcachedはlibmemcachedをラップしているとの事だけれど実はそんなに速くない。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment