Commit 5d931833 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

#3783 txn begin commit benchmark refs[t:3783]

git-svn-id: file:///svn/toku/tokudb@33403 c7de825b-a66e-492c-adef-691d508d4ae1
parent 4d69a4f4
......@@ -24,13 +24,17 @@ TDB_DLINK_FILES = $(TOKUROOT)lib/$(TOKUDB)
TARGET_BDB = db-benchmark-test-bdb$(BINSUF)
SCANSCAN_BDB = scanscan-bdb$(BINSUF)
PTQUERY_BDB = ptquery-bdb$(BINSUF)
TXNCOMMIT_BDB = txncommit-bdb$(BINSUF)
TARGET_TDB = db-benchmark-test-tokudb$(BINSUF)
SCANSCAN_TDB = scanscan-tokudb$(BINSUF)
PTQUERY_TDB = ptquery-tokudb$(BINSUF)
SCANRACE_TDB = scanrace-tokudb$(BINSUF)
PTQUERY_TDB = ptquery-tokudb$(BINSUF)
TXNCOMMIT_TDB = txncommit-tokudb$(BINSUF)
MULTIBENCH_TDB = multi-bench-tokudb$(BINSUF)
TARGETS = $(TARGET_BDB) $(SCANSCAN_BDB) $(TARGET_TDB) $(SCANSCAN_TDB) $(SCANRACE_TDB) $(MULTIBENCH_TDB) $(PTQUERY_TDB) $(PTQUERY_BDB)
TARGETS_BDB = $(TARGET_BDB) $(SCANSCAN_BDB)
TARGETS_BDB = $(TARGET_BDB) $(SCANSCAN_BDB) $(PTQUERY_BDB) $(TXNCOMMIT_BDB)
TARGETS = $(TARGETS_BDB) $(TARGET_TDB) $(SCANSCAN_TDB) $(SCANRACE_TDB) $(MULTIBENCH_TDB) $(PTQUERY_TDB) $(TXNCOMMIT_TDB)
ifeq ($(OS_CHOICE),windows)
ifdef BDBDIR
......@@ -69,8 +73,8 @@ else
build: build.tdb build.bdb;
endif
build.bdb: $(TARGET_BDB) $(SCANSCAN_BDB) $(WINDOWS_BDB_LIB_NAME)
build.tdb: $(TARGET_TDB) $(SCANSCAN_TDB) $(MULTIBENCH_TDB) $(PTQUERY_TDB)
build.bdb: $(TARGET_BDB) $(SCANSCAN_BDB) $(WINDOWS_BDB_LIB_NAME) $(TXNCOMMIT_BDB)
build.tdb: $(TARGET_TDB) $(SCANSCAN_TDB) $(MULTIBENCH_TDB) $(PTQUERY_TDB) $(TXNCOMMIT_TDB)
check: check-default check-rowsize check-xfast check-x check-no-rollback check-4G child.benchmark.dir
......@@ -151,10 +155,10 @@ ifeq ($(OS_CHOICE),windows)
$(TARGET_TDB) $(SCANSCAN_TDB) $(SCANRACE_TDB): $(WIN_YDB) $(PTHREAD_LOCAL)
$(TARGET_TDB) $(SCANSCAN_TDB) $(SCANRACE_TDB): LINK_FILES+=$(WIN_YDB)
else
$(TARGET_TDB) $(SCANSCAN_TDB) $(SCANRACE_TDB) $(MULTIBENCH_TDB) $(PTQUERY_TDB): DLINK_FILES=$(TDB_DLINK_FILES)
$(TARGET_TDB) $(SCANSCAN_TDB) $(SCANRACE_TDB) $(MULTIBENCH_TDB) $(PTQUERY_TDB): RPATH_DIRS=$(dir $(TDB_DLINK_FILES))
$(TARGET_TDB) $(SCANSCAN_TDB) $(SCANRACE_TDB) $(MULTIBENCH_TDB) $(PTQUERY_TDB) $(TXNCOMMIT_TDB): DLINK_FILES=$(TDB_DLINK_FILES)
$(TARGET_TDB) $(SCANSCAN_TDB) $(SCANRACE_TDB) $(MULTIBENCH_TDB) $(PTQUERY_TDB) $(TXNCOMMIT_TDB): RPATH_DIRS=$(dir $(TDB_DLINK_FILES))
endif
$(TARGET_TDB) $(SCANSCAN_TDB) $(SCANRACE_TDB) $(MULTIBENCH_TDB) $(PTQUERY_TDB): LDLIBS+=-ltokuportability
$(TARGET_TDB) $(SCANSCAN_TDB) $(SCANRACE_TDB) $(MULTIBENCH_TDB) $(PTQUERY_TDB) $(TXNCOMMIT_TDB): LDLIBS+=-ltokuportability
$(TARGET_TDB): db-benchmark-test.c $(PTHREAD_LOCAL)
$(CC) $< $(BIN_FROM_C_FLAGS) $(LINK_MUST_BE_LAST)
$(SCANSCAN_TDB): scanscan.c $(PTHREAD_LOCAL)
......@@ -165,6 +169,8 @@ $(SCANRACE_TDB): scanrace.c $(PTHREAD_LOCAL)
$(CC) $< $(BIN_FROM_C_FLAGS) $(LINK_MUST_BE_LAST)
$(MULTIBENCH_TDB): multi-bench.c $(PTHREAD_LOCAL)
$(CC) $< $(BIN_FROM_C_FLAGS) $(LINK_MUST_BE_LAST)
$(TXNCOMMIT_TDB): txncommit.c $(PTHREAD_LOCAL)
$(CC) $< $(BIN_FROM_C_FLAGS) $(LINK_MUST_BE_LAST)
endif
$(TARGETS_BDB): CPPFLAGS+=-DDIRSUF=bdb -DTOKU_ALLOW_DEPRECATED
......@@ -174,7 +180,8 @@ $(TARGET_BDB): db-benchmark-test.c
$(CC) $< $(BIN_FROM_C_FLAGS) $(LINK_MUST_BE_LAST)
$(SCANSCAN_BDB): scanscan.c
$(CC) $< $(BIN_FROM_C_FLAGS) $(LINK_MUST_BE_LAST)
$(TXNCOMMIT_BDB): txncommit.c
$(CC) $< $(BIN_FROM_C_FLAGS) $(LINK_MUST_BE_LAST)
PARGS =
ptest%: $(TARGET_TDB)
......
// run txn begin commit on multiple threads and measure the throughput
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
#include <sys/time.h>
#include "db.h"
#include "toku_portability.h"
#include "toku_pthread.h"
static double now(void) {
struct timeval tv;
int r = gettimeofday(&tv, NULL); assert(r == 0);
return tv.tv_sec * 1000000.0 + tv.tv_usec;
}
static void test_txn(DB_ENV *env, uint32_t ntxns, long usleep_time) {
int r;
for (uint32_t i = 0; i < ntxns; i++) {
DB_TXN *txn = NULL;
r = env->txn_begin(env, NULL, &txn, DB_TXN_SNAPSHOT); assert(r == 0);
r = txn->commit(txn, 0); assert(r == 0);
if (usleep_time)
usleep(usleep_time);
else
sched_yield();
}
}
struct arg {
DB_ENV *env;
uint32_t ntxns;
long usleep_time;
};
static void *test_thread(void *arg) {
struct arg *myarg = (struct arg *) arg;
test_txn(myarg->env, myarg->ntxns, myarg->usleep_time);
return arg;
}
int main(int argc, char * const argv[]) {
uint32_t ntxns = 1000000;
uint32_t nthreads = 1;
long usleep_time = 0;
for (int i = 1; i < argc; i++) {
char * const arg = argv[i];
if (strcmp(arg, "--ntxns") == 0 && i+1 < argc) {
ntxns = atoll(argv[++i]);
continue;
}
if (strcmp(arg, "--nthreads") == 0 && i+1 < argc) {
nthreads = atoll(argv[++i]);
continue;
}
if (strcmp(arg, "--usleep") == 0 && i+1 < argc) {
usleep_time = atol(argv[++i]);
continue;
}
return 1;
}
#if defined(TOKUDB)
const char *ENVDIR = __FILE__ ".tokudb.dir";
#else
const char *ENVDIR = __FILE__ ".bdb.dir";
#endif
int r;
char cmd[256];
sprintf(cmd, "rm -rf %s", ENVDIR);
r = system(cmd); assert(r == 0);
r = toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO); assert(r == 0);
DB_ENV *env = NULL;
r = db_env_create(&env, 0); assert(r == 0);
r = env->set_cachesize(env, 4, 0, 1); assert(r == 0);
r = env->open(env, ENVDIR, DB_PRIVATE + DB_THREAD + DB_CREATE + DB_INIT_TXN + DB_INIT_LOG + DB_INIT_MPOOL + DB_RECOVER, 0); assert(r == 0);
double tstart = now();
assert(nthreads > 0);
struct arg myargs[nthreads-1];
toku_pthread_t mytids[nthreads];
for (uint32_t i = 0; i < nthreads-1; i++) {
myargs[i] = (struct arg) { env, ntxns, usleep_time};
r = toku_pthread_create(&mytids[i], NULL, test_thread, &myargs[i]); assert(r == 0);
}
test_txn(env, ntxns, usleep_time);
for (uint32_t i = 0; i < nthreads-1; i++) {
void *ret;
r = toku_pthread_join(mytids[i], &ret); assert(r == 0);
}
double tend = now();
double t = tend-tstart;
double n = ntxns * nthreads;
printf("%f %f %f\n", n, t, (n/t)*1000000.0);
r = env->close(env, 0); assert(r == 0);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment