From 79523587817866b3cc6620567602121ebc6da66e Mon Sep 17 00:00:00 2001 From: Gregory Burd Date: Wed, 12 Jun 2013 09:08:09 -0400 Subject: [PATCH] WIP: cache wasn't returning items found --- c_src/async_nif.h | 2 +- c_src/common.h | 1 + c_src/wterl.c | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/c_src/async_nif.h b/c_src/async_nif.h index 6fde4bb..e34748e 100644 --- a/c_src/async_nif.h +++ b/c_src/async_nif.h @@ -34,7 +34,7 @@ extern "C" { #define UNUSED(v) ((void)(v)) #endif -#define ASYNC_NIF_MAX_WORKERS 1024 +#define ASYNC_NIF_MAX_WORKERS 128 #define ASYNC_NIF_WORKER_QUEUE_SIZE 500 #define ASYNC_NIF_MAX_QUEUED_REQS ASYNC_NIF_WORKER_QUEUE_SIZE * ASYNC_NIF_MAX_WORKERS diff --git a/c_src/common.h b/c_src/common.h index b8324da..eba4ffc 100644 --- a/c_src/common.h +++ b/c_src/common.h @@ -24,6 +24,7 @@ extern "C" { #endif +#define DEBUG 1 #if !(__STDC_VERSION__ >= 199901L || defined(__GNUC__)) # undef DEBUG # define DEBUG 0 diff --git a/c_src/wterl.c b/c_src/wterl.c index 9bc16f1..eda611a 100644 --- a/c_src/wterl.c +++ b/c_src/wterl.c @@ -223,8 +223,10 @@ __ctx_cache_find(WterlConnHandle *conn_handle, const uint64_t sig) conn_handle->histogram[__log2(cpu_clock_ticks() - c->tstamp)]++; conn_handle->histogram_count++; conn_handle->cache_size -= 1; - } - c = n; + break; + } else { + c = n; + } } enif_mutex_unlock(conn_handle->cache_mutex); return c; @@ -422,7 +424,7 @@ __release_ctx(WterlConnHandle *conn_handle, uint32_t worker_id, struct wterl_ctx { int i, n; WT_CURSOR *cursor; - struct wterl_ctx *c; + struct wterl_ctx *c = NULL; n = sizeof((WT_CURSOR**)ctx->cursors) / sizeof(ctx->cursors[0]); for (i = 0; i < n; i++) { @@ -702,7 +704,7 @@ ASYNC_NIF_DECL( conn_handle->conn = conn; ERL_NIF_TERM result = enif_make_resource(env, conn_handle); - /* Init hash table which manages the cache of session/cursor(s) */ + /* Init list for cache of reuseable contexts */ STAILQ_INIT(&conn_handle->cache); conn_handle->cache_size = 0; @@ -749,6 +751,12 @@ ASYNC_NIF_DECL( }, { // work + /* First, remove this connection from our list of open connections so + we don't free it twice when asked to unload. */ + enif_mutex_lock(args->priv->conns_mutex); + SLIST_REMOVE(&args->priv->conns, args->conn_handle, wterl_conn, conns); + enif_mutex_unlock(args->priv->conns_mutex); + /* Free up the shared sessions and cursors. */ enif_mutex_lock(args->conn_handle->cache_mutex); __close_all_sessions(args->conn_handle);