diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index b4f99726..b23ff8d7 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -2460,7 +2460,9 @@ PyObject *py_uwsgi_cache_get(PyObject * self, PyObject * args) { char buffer[0xffff]; PyObject *res; +#ifdef UWSGI_DEBUG struct timeval tv, tv2; +#endif if (!PyArg_ParseTuple(args, "s#|s:cache_get", &key, &keylen, &remote)) { return NULL; @@ -2473,14 +2475,18 @@ PyObject *py_uwsgi_cache_get(PyObject * self, PyObject * args) { } } else if (uwsgi.cache_max_items) { +#ifdef UWSGI_DEBUG gettimeofday(&tv, NULL); +#endif uwsgi_lock(uwsgi.cache_lock); value = uwsgi_cache_get(key, keylen, &valsize); res = PyString_FromStringAndSize(value, valsize); +#ifdef UWSGI_DEBUG gettimeofday(&tv2, NULL); if ((tv2.tv_sec* (1000*1000) + tv2.tv_usec) - (tv.tv_sec* (1000*1000) + tv.tv_usec) > 30000) { uwsgi_log("[slow] cache get done in %d microseconds (%llu bytes value)\n", (tv2.tv_sec* (1000*1000) + tv2.tv_usec) - (tv.tv_sec* (1000*1000) + tv.tv_usec), (unsigned long long) valsize); } +#endif uwsgi_unlock(uwsgi.cache_lock); return res; } diff --git a/protocol.c b/protocol.c index 492c5b38..d1c62536 100644 --- a/protocol.c +++ b/protocol.c @@ -82,7 +82,7 @@ int uwsgi_enqueue_message(char *host, int port, uint8_t modifier1, uint8_t modif if (!timeout) timeout = 1; - if (size > 0xFFFF) { + if (size > 0xffff) { uwsgi_log( "invalid object (marshalled) size\n"); return -1; } diff --git a/uwsgi.c b/uwsgi.c index 9724f2b8..55f599d8 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -1063,15 +1063,20 @@ int uwsgi_start(void *v_argv) { if (uwsgi.cache_max_items > 0) { - if (!uwsgi.cache_blocksize) uwsgi.cache_blocksize = 0xffff; + if (!uwsgi.cache_blocksize) uwsgi.cache_blocksize = UMAX16; - uwsgi.cache_hashtable = (uint64_t *) mmap(NULL, sizeof(uint64_t) * 0xffff, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + if (uwsgi.cache_blocksize % uwsgi.page_size != 0) { + uwsgi_log("invalid cache blocksize %llu: must be a multiple of memory page size (%d bytes)\n", (unsigned long long) uwsgi.cache_blocksize, uwsgi.page_size); + exit(1); + } + + uwsgi.cache_hashtable = (uint64_t *) mmap(NULL, sizeof(uint64_t) * UMAX16, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); if (!uwsgi.cache_hashtable) { uwsgi_error("mmap()"); exit(1); } - memset(uwsgi.cache_hashtable, 0, sizeof(uint64_t) * 0xffff); + memset(uwsgi.cache_hashtable, 0, sizeof(uint64_t) * UMAX16); uwsgi.cache_unused_stack = (uint64_t *) mmap(NULL, sizeof(uint64_t) * uwsgi.cache_max_items, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); if (!uwsgi.cache_unused_stack) { @@ -1105,6 +1110,8 @@ int uwsgi_start(void *v_argv) { uwsgi_lock_init(uwsgi.cache_lock); uwsgi.p[111] = &uwsgi_cache_plugin; + + uwsgi_log("*** Cache subsystem initialized: %dMB preallocated ***\n", ((sizeof(uint64_t) * UMAX16) + (sizeof(uint64_t) * uwsgi.cache_max_items) + (uwsgi.cache_blocksize * uwsgi.cache_max_items) + (sizeof(struct uwsgi_cache_item) * uwsgi.cache_max_items)) / (1024*1024)); } /* plugin initialization */ diff --git a/uwsgi.h b/uwsgi.h index 7aceaef1..cdcb3a1a 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -4,6 +4,8 @@ #define UWSGI_VERSION "0.9.7-dev" +#define UMAX16 65536 + #define uwsgi_error(x) uwsgi_log("%s: %s [%s line %d]\n", x, strerror(errno), __FILE__, __LINE__); #define uwsgi_debug(x, ...) uwsgi_log("[uWSGI DEBUG] " x, __VA_ARGS__); #define uwsgi_rawlog(x) if (write(2, x, strlen(x)) != strlen(x)) uwsgi_error("write()")