From 22da8d9ba23ec62e35e942dc6bfe52d8bce0c4b5 Mon Sep 17 00:00:00 2001 From: Unbit Date: Sat, 18 May 2013 19:45:18 +0200 Subject: [PATCH] optimized pypy environ helper --- plugins/pypy/pypy_plugin.c | 29 +++-------------------------- plugins/pypy/pypy_setup.py | 21 +++++++++------------ 2 files changed, 12 insertions(+), 38 deletions(-) diff --git a/plugins/pypy/pypy_plugin.c b/plugins/pypy/pypy_plugin.c index f6aa2d0d..3d6b1b04 100644 --- a/plugins/pypy/pypy_plugin.c +++ b/plugins/pypy/pypy_plugin.c @@ -47,33 +47,10 @@ int uwsgi_pypy_helper_register_rpc(char *name, int argc, void *func) { return uwsgi_register_rpc(name, &pypy_plugin, argc, func); } -int uwsgi_pypy_helper_vars(int core) { +struct iovec *uwsgi_pypy_helper_environ(int core, uint16_t *len) { struct wsgi_request *wsgi_req = &uwsgi.workers[uwsgi.mywid].cores[core].req; - return wsgi_req->var_cnt; -} - -char *uwsgi_pypy_helper_key(int core, int pos) { - uwsgi_log("[key] core = %d pos = %d\n", core, pos); - struct wsgi_request *wsgi_req = &uwsgi.workers[uwsgi.mywid].cores[core].req; - return wsgi_req->hvec[pos].iov_base; -} - -int uwsgi_pypy_helper_keylen(int core, int pos) { - uwsgi_log("[keylen] core = %d pos = %d\n", core, pos); - struct wsgi_request *wsgi_req = &uwsgi.workers[uwsgi.mywid].cores[core].req; - return wsgi_req->hvec[pos].iov_len; -} - -char *uwsgi_pypy_helper_val(int core, int pos) { - uwsgi_log("[val] core = %d pos = %d\n", core, pos); - struct wsgi_request *wsgi_req = &uwsgi.workers[uwsgi.mywid].cores[core].req; - return wsgi_req->hvec[pos+1].iov_base; -} - -int uwsgi_pypy_helper_vallen(int core, int pos) { - uwsgi_log("[vallen] core = %d pos = %d\n", core, pos); - struct wsgi_request *wsgi_req = &uwsgi.workers[uwsgi.mywid].cores[core].req; - return wsgi_req->hvec[pos+1].iov_len; + *len = wsgi_req->var_cnt; + return wsgi_req->hvec; } void uwsgi_pypy_helper_status(int core, char *status, int status_len) { diff --git a/plugins/pypy/pypy_setup.py b/plugins/pypy/pypy_setup.py index c412ad9e..f4ed8f31 100644 --- a/plugins/pypy/pypy_setup.py +++ b/plugins/pypy/pypy_setup.py @@ -12,13 +12,12 @@ void free(void *); void (*uwsgi_pypy_hook_loader)(char *); void (*uwsgi_pypy_hook_request)(int); -char *uwsgi_pypy_helper_key(int, int); -int uwsgi_pypy_helper_keylen(int, int); +struct iovec { + char *iov_base; + uint64_t iov_len; +}; -char *uwsgi_pypy_helper_val(int, int); -int uwsgi_pypy_helper_vallen(int, int); - -int uwsgi_pypy_helper_vars(int); +struct iovec *uwsgi_pypy_helper_environ(int, uint16_t *); void uwsgi_pypy_helper_status(int, char *, int); void uwsgi_pypy_helper_header(int, char *, int, char *, int); @@ -67,12 +66,10 @@ def uwsgi_pypy_wsgi_handler(core): pass environ = {} - n = lib.uwsgi_pypy_helper_vars(core) - print "[n] core = %d vars = %d" % (core, n) - for i in range(0, n, 2): - key = ffi.string( lib.uwsgi_pypy_helper_key(core, i), lib.uwsgi_pypy_helper_keylen(core, i) ) - value = ffi.string( lib.uwsgi_pypy_helper_val(core, i), lib.uwsgi_pypy_helper_vallen(core, i) ) - environ[key] = value + nv = ffi.new("uint16_t *") + iov = lib.uwsgi_pypy_helper_environ(core, nv) + for i in range(0, nv[0], 2): + environ[ffi.string(iov[i].iov_base, iov[i].iov_len)] = ffi.string(iov[i+1].iov_base, iov[i+1].iov_len) environ['wsgi.version'] = (1, 0) scheme = 'http'