Attempt to batch together database writes for performance.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Tue, 13 Jul 2010 00:26:21 +0000 (17:26 -0700)
committerMichael Vrable <mvrable@cs.ucsd.edu>
Tue, 13 Jul 2010 00:26:21 +0000 (17:26 -0700)
Doesn't seem to help all that much though...

bluesky/store-bdb.c

index 57422b9..cd33fac 100644 (file)
@@ -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;