简体   繁体   中英

couchdbkit 10x slower than requests?

I was playing with couchdb and the recommended "couchdbkit" python package. I felt it was a bit slow and decided to do some measurements. If i didn't do something wrong, then using the popular "requests" package is more than 10 times faster than going through couchdbkit. Why?

Here is the timing script i used:

from time import time as now
from pprint import pprint

class Timer:
    def __init__(self):
        self.current = now()

    def __call__(self, msg):
        snap = now()
        duration = snap - self.current
        self.current = snap
        pprint("%.3f duration -- %s" %(duration, msg))

def requests(num):
    t = Timer()

    import requests
    for i in range(num):
        r = requests.get("http://127.0.0.1:8001/releases/_design/access/_view/yieldlinks")
        assert r.status_code == 200
        r.json # make sure the json is there
    t("requests: %d" % (num,))

def couchdbkit(num):
    import couchdbkit

    t = Timer()
    server = couchdbkit.Server("http://127.0.0.1:8001")
    releases = server.get_db("releases")
    for x in range(num):
        for x in releases.view("access/yieldlinks"):
            pass
    t("couchdbkit: %d" %(num,))

num = 500
requests(num)
couchdbkit(num)

For running the example you probably need to modify the view URL. I verified that the two invocations cause the exact same GET requests on the server. So this really seems to relate to the inner working of couchdbkit?!

So i finally found the issue, it's actually the same as this one:

CouchDB / MochiWeb : negative effect of persistent connections

In short, adding:

[httpd]
socket_options = [{nodelay, true}]

resolves the perf difference - in fact couchdbkit/restkit is now a little faster.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM