From 0c2a6b20994edb21ef45a9757260ecf35cd8ca18 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Mon, 12 Jul 2010 17:26:21 -0700 Subject: [PATCH] Attempt to batch together database writes for performance. Doesn't seem to help all that much though... --- bluesky/store-bdb.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/bluesky/store-bdb.c b/bluesky/store-bdb.c index 57422b9..cd33fac 100644 --- a/bluesky/store-bdb.c +++ b/bluesky/store-bdb.c @@ -27,11 +27,23 @@ typedef struct { static gpointer bdbstore_thread(gpointer data) { BDBStore *store = (BDBStore *)data; + DB_TXN *txn = NULL; + + // Number of operations in the current transaction + int transaction_size = 0; while (TRUE) { int res; BlueSkyStoreAsync *async; + if (txn == NULL) { + res = store->env->txn_begin(store->env, NULL, &txn, 0); + if (res != 0) { + fprintf(stderr, "Unable to begin transaction!\n"); + return NULL; + } + } + async = (BlueSkyStoreAsync *)g_async_queue_pop(store->operations); async->status = ASYNC_RUNNING; async->exec_time = bluesky_now_hires(); @@ -48,7 +60,7 @@ static gpointer bdbstore_thread(gpointer data) if (async->op == STORE_OP_GET) { value.flags = DB_DBT_MALLOC; - res = store->db->get(store->db, NULL, &key, &value, 0); + res = store->db->get(store->db, txn, &key, &value, 0); async->result = res; async->data = NULL; @@ -64,7 +76,7 @@ static gpointer bdbstore_thread(gpointer data) value.data = async->data->data; value.size = async->data->len; - res = store->db->put(store->db, NULL, &key, &value, 0); + res = store->db->put(store->db, txn, &key, &value, 0); if (res != 0) { fprintf(stderr, "BDB write failure: %s\n", db_strerror(res)); @@ -75,6 +87,13 @@ static gpointer bdbstore_thread(gpointer data) bluesky_store_async_mark_complete(async); bluesky_store_async_unref(async); + transaction_size++; + + if (transaction_size >= 64) { + txn->commit(txn, 0); + txn = NULL; + transaction_size = 0; + } } return NULL; -- 2.20.1