From c7cfbc512b8eb08ead281df1865cb3b241a8070a Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Tue, 13 Jul 2010 22:25:39 -0700 Subject: [PATCH] Make the log benchmark configurable and make a parameter sweep script. --- logbench/logbench.c | 70 +++++++++++++++++++++++++++++++++++++------- logbench/runbench.sh | 22 ++++++++++++++ 2 files changed, 81 insertions(+), 11 deletions(-) create mode 100755 logbench/runbench.sh diff --git a/logbench/logbench.c b/logbench/logbench.c index d811dc9..722a2de 100644 --- a/logbench/logbench.c +++ b/logbench/logbench.c @@ -29,8 +29,10 @@ struct item { size_t len; }; -const int queue_capacity = 1024; -const int item_size = 1024; +int queue_capacity = 1024; +int item_size = 1024; +int opt_threads = 1; +int opt_batchsize = 1; GAsyncQueue *queue; int outstanding = 0; @@ -97,7 +99,7 @@ gpointer fslog_thread(gpointer d) void launch_fslog() { - dirfd = open("logdir", O_DIRECTORY); + dirfd = open(".", O_DIRECTORY); g_assert(dirfd >= 0); for (int i = 0; i < 1; i++) @@ -122,7 +124,7 @@ gpointer flatlog_thread(gpointer d) writebuf(fd, item->data, item->len); count++; - if (count % (1 << 8) == 0) + if (count % opt_batchsize == 0) fdatasync(fd); finish_item(item); @@ -150,7 +152,7 @@ gpointer bdb_thread(gpointer d) res = db_env_create(&env, 0); g_assert(res == 0); - res = env->open(env, "bdb", + res = env->open(env, ".", DB_CREATE | DB_RECOVER | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_THREAD, 0644); g_assert(res == 0); @@ -184,7 +186,7 @@ gpointer bdb_thread(gpointer d) g_assert(res == 0); count++; - if (count % (1 << 8) == 0) { + if (count % opt_batchsize == 0) { txn->commit(txn, 0); txn = NULL; } @@ -208,9 +210,55 @@ int main(int argc, char *argv[]) cond_empty = g_cond_new(); cond_full = g_cond_new(); - launch_fslog(); - // launch_flatlog(); - // launch_bdb(); + int opt; + int backend = 0; + while ((opt = getopt(argc, argv, "t:s:b:BFD")) != -1) { + switch (opt) { + case 't': + // Set number of log worker threads + opt_threads = atoi(optarg); + break; + case 's': + // Set item size (in bytes) + item_size = atoi(optarg); + break; + case 'b': + // Set batch size + opt_batchsize = atoi(optarg); + break; + case 'B': + // Select BDB backend + backend = 'b'; + break; + case 'F': + // Select flat file backend + backend = 'f'; + break; + case 'D': + // Select file system directory backend + backend = 'd'; + break; + default: /* '?' */ + fprintf(stderr, "Usage: %s [-t threads] {-B|-F|-D}\n", + argv[0]); + return EXIT_FAILURE; + } + } + + switch (backend) { + case 'b': + launch_bdb(); + break; + case 'f': + launch_flatlog(); + break; + case 'd': + launch_fslog(); + break; + default: + fprintf(stderr, "Backend not selected!\n"); + return EXIT_FAILURE; + } for (int i = 0; i < (1 << 12); i++) { struct item *item = g_new(struct item, 1); @@ -219,10 +267,10 @@ int main(int argc, char *argv[]) item->len = item_size; g_mutex_lock(lock); - while (outstanding >= queue_capacity) - g_cond_wait(cond_full, lock); g_async_queue_push(queue, item); outstanding++; + if (outstanding == opt_batchsize) + g_cond_wait(cond_empty, lock); g_mutex_unlock(lock); } diff --git a/logbench/runbench.sh b/logbench/runbench.sh new file mode 100755 index 0000000..5503f10 --- /dev/null +++ b/logbench/runbench.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +do_run() { + LOGDIR=$(mktemp -d ./logdir.XXXXXXXX) + sync; sleep 0.5 + echo Running: "$@" + (cd "$LOGDIR"; time ../logbench "$@") + rm -rf "$LOGDIR" +} + +for s in 256 1024 4096 16384 65536; do + #do_run -B -s $s + true +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 + done +done -- 2.20.1