X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Fstore.c;h=2043806828a9c241c513ff4952c34dbcf8e8e6d6;hb=348aaaad42163d6829112c9b18026c16b09e1914;hp=888bd1b07b490b6ae305377c2a8c8c1809c8ac9e;hpb=e560d8b120a5f2ed5057506f91bc8d9e818229a7;p=bluesky.git diff --git a/bluesky/store.c b/bluesky/store.c index 888bd1b..2043806 100644 --- a/bluesky/store.c +++ b/bluesky/store.c @@ -24,6 +24,8 @@ struct _BlueSkyStore { GMutex *lock; GCond *cond_idle; int pending; /* Count of operations not yet complete. */ + + struct bluesky_stats *stats_get, *stats_put; }; GHashTable *store_implementations; @@ -71,6 +73,10 @@ BlueSkyStore *bluesky_store_new(const gchar *type) store->lock = g_mutex_new(); store->cond_idle = g_cond_new(); store->pending = 0; + store->stats_get = bluesky_stats_new(g_strdup_printf("Store[%s]: GETS", + type)); + store->stats_put = bluesky_stats_new(g_strdup_printf("Store[%s]: PUTS", + type)); g_free(scheme); return store; } @@ -197,12 +203,15 @@ void bluesky_store_async_mark_complete(BlueSkyStoreAsync *async) g_return_if_fail(async->status != ASYNC_COMPLETE); bluesky_time_hires elapsed = bluesky_now_hires() - async->start_time; - - g_mutex_lock(async->store->lock); - async->store->pending--; - if (async->store->pending == 0) - g_cond_broadcast(async->store->cond_idle); - g_mutex_unlock(async->store->lock); + bluesky_time_hires latency = bluesky_now_hires() - async->exec_time; + + if (async->op != STORE_OP_BARRIER) { + g_mutex_lock(async->store->lock); + async->store->pending--; + if (async->store->pending == 0) + g_cond_broadcast(async->store->cond_idle); + g_mutex_unlock(async->store->lock); + } async->status = ASYNC_COMPLETE; g_cond_broadcast(async->completion_cond); @@ -216,9 +225,17 @@ void bluesky_store_async_mark_complete(BlueSkyStoreAsync *async) g_thread_pool_push(notifier_thread_pool, nl, NULL); } - g_log("bluesky/store", G_LOG_LEVEL_DEBUG, - "[%p] complete: elapsed = %"PRIi64" ns", - async, elapsed); + if (bluesky_verbose) { + g_log("bluesky/store", G_LOG_LEVEL_DEBUG, + "[%p] complete: elapsed = %"PRIi64" ns, latency = %"PRIi64" ns", + async, elapsed, latency); + } + + if (async->op == STORE_OP_GET) { + bluesky_stats_add(async->store->stats_get, 1); + } else if (async->op == STORE_OP_PUT) { + bluesky_stats_add(async->store->stats_put, 1); + } } void bluesky_store_async_submit(BlueSkyStoreAsync *async) @@ -227,13 +244,19 @@ void bluesky_store_async_submit(BlueSkyStoreAsync *async) async->start_time = bluesky_now_hires(); - g_log("bluesky/store", G_LOG_LEVEL_DEBUG, "[%p] submit: %s %s", - async, - async->op == STORE_OP_GET ? "GET" - : async->op == STORE_OP_PUT ? "PUT" - : async->op == STORE_OP_DELETE ? "DELETE" - : async->op == STORE_OP_BARRIER ? "BARRIER" : "???", - async->key); + // Backends should fill this in with a better estimate of the actual time + // processing was started, if there could be a delay from submission time. + async->exec_time = bluesky_now_hires(); + + if (bluesky_verbose) { + g_log("bluesky/store", G_LOG_LEVEL_DEBUG, "[%p] submit: %s %s", + async, + async->op == STORE_OP_GET ? "GET" + : async->op == STORE_OP_PUT ? "PUT" + : async->op == STORE_OP_DELETE ? "DELETE" + : async->op == STORE_OP_BARRIER ? "BARRIER" : "???", + async->key); + } /* Barriers are handled specially, and not handed down the storage * implementation layer. */ @@ -295,12 +318,17 @@ static void notifier_task(gpointer n, gpointer s) void bluesky_store_sync(BlueSkyStore *store) { g_mutex_lock(store->lock); - g_print("Waiting for pending store operations to complete...\n"); + if (bluesky_verbose) { + g_log("bluesky/store", G_LOG_LEVEL_DEBUG, + "Waiting for pending store operations to complete..."); + } while (store->pending > 0) { g_cond_wait(store->cond_idle, store->lock); } g_mutex_unlock(store->lock); - g_print("Operations are complete.\n"); + if (bluesky_verbose) { + g_log("bluesky/store", G_LOG_LEVEL_DEBUG, "Operations are complete."); + } } /* Convenience wrappers that perform a single operation synchronously. */ @@ -472,8 +500,8 @@ static BlueSkyStoreImplementation filestore_impl = { void bluesky_store_init() { store_implementations = g_hash_table_new(g_str_hash, g_str_equal); - notifier_thread_pool = g_thread_pool_new(notifier_task, NULL, -1, FALSE, - NULL); + notifier_thread_pool = g_thread_pool_new(notifier_task, NULL, + bluesky_max_threads, FALSE, NULL); bluesky_store_register(&memstore_impl, "mem"); bluesky_store_register(&filestore_impl, "file"); }