From 2b2c91ae1e2d8f26d554a7c90216bf88dcdc0bc2 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Wed, 14 Jul 2010 15:23:17 -0700 Subject: [PATCH] Update commit log benchmarks. --- logbench/logbench.c | 65 ++++++++++++++++++++++++++++++++++++-------- logbench/runbench.sh | 20 ++++++++++---- 2 files changed, 68 insertions(+), 17 deletions(-) diff --git a/logbench/logbench.c b/logbench/logbench.c index 722a2de..6cdd5ec 100644 --- a/logbench/logbench.c +++ b/logbench/logbench.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -33,12 +34,22 @@ int queue_capacity = 1024; int item_size = 1024; int opt_threads = 1; int opt_batchsize = 1; +int opt_writes = (1 << 12); +int opt_bdb_async = FALSE; GAsyncQueue *queue; int outstanding = 0; GMutex *lock; GCond *cond_empty, *cond_full; +int64_t get_ns() +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + + return ts.tv_sec * 1000000000LL + ts.tv_nsec; +} + struct item *get_item() { return (struct item *)g_async_queue_pop(queue); @@ -77,8 +88,6 @@ static int dirfd = -1; gpointer fslog_thread(gpointer d) { - g_print("Launching filesystem writer thread...\n"); - while (TRUE) { struct item *item = get_item(); @@ -109,8 +118,6 @@ void launch_fslog() /****************************** Single-File Log ******************************/ gpointer flatlog_thread(gpointer d) { - g_print("Launching flat log writer thread...\n"); - int fd = open("logfile", O_CREAT|O_WRONLY|O_TRUNC, 0666); g_assert(fd >= 0); @@ -141,8 +148,6 @@ void launch_flatlog() /************************* Transactional Berkeley DB *************************/ gpointer bdb_thread(gpointer d) { - g_print("Launching BDB log writer thread...\n"); - int res; DB_ENV *env; DB *db; @@ -157,6 +162,11 @@ gpointer bdb_thread(gpointer d) | DB_INIT_MPOOL | DB_INIT_TXN | DB_THREAD, 0644); g_assert(res == 0); + if (opt_bdb_async) { + res = env->set_flags(env, DB_TXN_WRITE_NOSYNC, 1); + g_assert(res == 0); + } + res = db_create(&db, env, 0); g_assert(res == 0); @@ -165,7 +175,7 @@ gpointer bdb_thread(gpointer d) g_assert(res == 0); while (TRUE) { - if (txn == NULL) { + if (txn == NULL && !opt_bdb_async) { res = env->txn_begin(env, NULL, &txn, 0); g_assert(res == 0); } @@ -182,13 +192,17 @@ gpointer bdb_thread(gpointer d) value.data = item->data; value.size = item->len; - res = db->put(db, NULL, &key, &value, 0); + res = db->put(db, opt_bdb_async ? NULL : txn, &key, &value, 0); g_assert(res == 0); count++; if (count % opt_batchsize == 0) { - txn->commit(txn, 0); - txn = NULL; + if (opt_bdb_async) { + env->txn_checkpoint(env, 0, 0, 0); + } else { + txn->commit(txn, 0); + txn = NULL; + } } finish_item(item); @@ -204,6 +218,8 @@ void launch_bdb() int main(int argc, char *argv[]) { + int64_t time_start, time_end; + g_thread_init(NULL); queue = g_async_queue_new(); lock = g_mutex_new(); @@ -212,8 +228,11 @@ int main(int argc, char *argv[]) int opt; int backend = 0; - while ((opt = getopt(argc, argv, "t:s:b:BFD")) != -1) { + while ((opt = getopt(argc, argv, "at:s:b:n:BFD")) != -1) { switch (opt) { + case 'a': + // Make BDB log writes more asynchronous + opt_bdb_async = TRUE; case 't': // Set number of log worker threads opt_threads = atoi(optarg); @@ -226,6 +245,10 @@ int main(int argc, char *argv[]) // Set batch size opt_batchsize = atoi(optarg); break; + case 'n': + // Set object count + opt_writes = atoi(optarg); + break; case 'B': // Select BDB backend backend = 'b'; @@ -260,7 +283,8 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - for (int i = 0; i < (1 << 12); i++) { + time_start = get_ns(); + for (int i = 0; i < opt_writes; i++) { struct item *item = g_new(struct item, 1); item->key = g_strdup_printf("item-%06d", i); item->data = g_malloc(item_size); @@ -278,6 +302,23 @@ int main(int argc, char *argv[]) while (outstanding > 0) g_cond_wait(cond_empty, lock); g_mutex_unlock(lock); + time_end = get_ns(); + + double elapsed = (time_end - time_start) / 1e9; + printf("Elapsed: %f s\nThroughput: %f txn/s, %f MiB/s\n", + elapsed, opt_writes / elapsed, + opt_writes / elapsed * item_size / (1 << 20)); + + if (backend == 'b' && opt_bdb_async) + backend = 'B'; + + FILE *f = fopen("../logbench.data", "a"); + g_assert(f != NULL); + fprintf(f, "%c\t%d\t%d\t%d\t%f\t%f\t%f\n", + backend, item_size, opt_writes, opt_batchsize, + elapsed, opt_writes / elapsed, + opt_writes / elapsed * item_size / (1 << 20)); + fclose(f); return 0; } diff --git a/logbench/runbench.sh b/logbench/runbench.sh index 5503f10..1d27012 100755 --- a/logbench/runbench.sh +++ b/logbench/runbench.sh @@ -4,7 +4,7 @@ do_run() { LOGDIR=$(mktemp -d ./logdir.XXXXXXXX) sync; sleep 0.5 echo Running: "$@" - (cd "$LOGDIR"; time ../logbench "$@") + (cd "$LOGDIR"; ../logbench "$@") rm -rf "$LOGDIR" } @@ -14,9 +14,19 @@ for s in 256 1024 4096 16384 65536; do done for b in 1 2 4 8 16 32; do - for s in 4096; do - do_run -B -s $s -b $b - do_run -F -s $s -b $b - do_run -D -s $s -b $b + for s in 1024 4096 32768; do + n=$(((1 << 26) / $s)) + if [ $n -gt 16384 ]; then + n=16384 + fi + if [ $n -lt 4096 ]; then + n=4096 + fi + + do_run -B -s $s -b $b -n $n + do_run -B -a -s $s -b $b -n $n + do_run -F -s $s -b $b -n $n + do_run -D -s $s -b $b -n $n + echo "========" done done -- 2.20.1