Commit 1dc6c023 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Add transactions to benchmark test

git-svn-id: file:///svn/tokudb@374 c7de825b-a66e-492c-adef-691d508d4ae1
parent 24c21821
...@@ -10,7 +10,7 @@ CFLAGS += -O2 ...@@ -10,7 +10,7 @@ CFLAGS += -O2
ifdef BDB ifdef BDB
CPPFLAGS = -I$(BDB)/include CPPFLAGS = -I$(BDB)/include
LDFLAGS = -L$(BDB)/lib -ldb -lpthread LDFLAGS = -L$(BDB)/lib -ldb -lpthread -Wl,-rpath,$(BDB)/lib
else else
CPPFLAGS = CPPFLAGS =
LDFLAGS = -ldb LDFLAGS = -ldb
...@@ -21,4 +21,4 @@ TARGET = db-benchmark-test ...@@ -21,4 +21,4 @@ TARGET = db-benchmark-test
$(TARGET): $(TARGET):
clean: clean:
rm -rf $(TARGET) $(BENCHDB) rm -rf $(TARGET) $(BENCHDB)
\ No newline at end of file
...@@ -10,16 +10,22 @@ ...@@ -10,16 +10,22 @@
#include <db.h> #include <db.h>
enum { SERIAL_SPACING = 1<<6 }; enum { SERIAL_SPACING = 1<<6 };
enum { ITEMS_TO_INSERT_PER_ITERATION = 1<<20 }; enum { ITEMS_TO_INSERT_PER_ITERATION = 1<<15 };
//enum { ITEMS_TO_INSERT_PER_ITERATION = 1<<14 }; //enum { ITEMS_TO_INSERT_PER_ITERATION = 1<<14 };
enum { BOUND_INCREASE_PER_ITERATION = SERIAL_SPACING*ITEMS_TO_INSERT_PER_ITERATION }; enum { BOUND_INCREASE_PER_ITERATION = SERIAL_SPACING*ITEMS_TO_INSERT_PER_ITERATION };
char *dbdir = "."; #define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0);
char *dbdir = "./bench/";
char *dbfilename = "bench.db"; char *dbfilename = "bench.db";
char *dbname; char *dbname;
DB_ENV *dbenv; DB_ENV *dbenv;
DB *db; DB *db;
DB_TXN *tid=0;
int do_transactions = 0;
void setup (void) { void setup (void) {
int r; int r;
...@@ -39,14 +45,43 @@ void setup (void) { ...@@ -39,14 +45,43 @@ void setup (void) {
printf("WARNING: set_cachesize %d\n", r); printf("WARNING: set_cachesize %d\n", r);
} }
r = dbenv->open(dbenv, dbdir, DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL, 0644); {
assert(r == 0); int flags = DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL | (do_transactions ? (DB_INIT_TXN | DB_INIT_LOG | DB_INIT_LOCK): 0);
r = dbenv->open(dbenv, dbdir, flags, 0644);
printf("Flags=%x\n", flags);
assert(r == 0);
}
r = db_create(&db, dbenv, 0); r = db_create(&db, dbenv, 0);
assert(r == 0); assert(r == 0);
r = db->open(db, NULL, dbfilename, NULL, DB_BTREE, DB_CREATE, 0644); if (do_transactions) {
r=dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0);
}
r = db->open(db, tid, dbfilename, NULL, DB_BTREE, DB_CREATE, 0644);
assert(r == 0); assert(r == 0);
if (do_transactions) {
r=tid->commit(tid, 0); assert(r==0);
}
if (do_transactions) {
DBT key,data;
r=dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0);
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.data="hello";
key.size=6;
data.data="there";
data.size=6;
r=db->put(db, tid, &key, &data, 0);
CKERR(r);
r=tid->commit(tid, 0); assert(r==0);
}
} }
void shutdown (void) { void shutdown (void) {
...@@ -76,15 +111,28 @@ void insert (long long v) { ...@@ -76,15 +111,28 @@ void insert (long long v) {
DBT kt, vt; DBT kt, vt;
long_long_to_array(kc, v); long_long_to_array(kc, v);
long_long_to_array(vc, v); long_long_to_array(vc, v);
int r = db->put(db, NULL, fill_dbt(&kt, kc, 8), fill_dbt(&vt, vc, 8), 0); int r = db->put(db, tid, fill_dbt(&kt, kc, 8), fill_dbt(&vt, vc, 8), 0);
assert(r == 0); CKERR(r);
} }
void serial_insert_from (long long from) { void serial_insert_from (long long from) {
long long i; long long i;
if (do_transactions) {
int r = dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0);
{
DBT k,v;
r=db->put(db, tid, fill_dbt(&k, "a", 1), fill_dbt(&v, "b", 1), 0);
CKERR(r);
}
}
for (i=0; i<ITEMS_TO_INSERT_PER_ITERATION; i++) { for (i=0; i<ITEMS_TO_INSERT_PER_ITERATION; i++) {
insert((from+i)*SERIAL_SPACING); insert((from+i)*SERIAL_SPACING);
} }
if (do_transactions) {
int r= tid->commit(tid, 0); assert(r==0);
tid=0;
}
} }
long long llrandom (void) { long long llrandom (void) {
...@@ -93,9 +141,16 @@ long long llrandom (void) { ...@@ -93,9 +141,16 @@ long long llrandom (void) {
void random_insert_below (long long below) { void random_insert_below (long long below) {
long long i; long long i;
if (do_transactions) {
int r = dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0);
}
for (i=0; i<ITEMS_TO_INSERT_PER_ITERATION; i++) { for (i=0; i<ITEMS_TO_INSERT_PER_ITERATION; i++) {
insert(llrandom()%below); insert(llrandom()%below);
} }
if (do_transactions) {
int r= tid->commit(tid, 0); assert(r==0);
tid=0;
}
} }
double tdiff (struct timeval *a, struct timeval *b) { double tdiff (struct timeval *a, struct timeval *b) {
...@@ -122,20 +177,38 @@ void biginsert (long long n_elements, struct timeval *starttime) { ...@@ -122,20 +177,38 @@ void biginsert (long long n_elements, struct timeval *starttime) {
int main (int argc, char *argv[]) { const long long default_n_items = 1LL<<22;
void print_usage (const char *argv0) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, " %s [-x] [ n_iterations ]\n", argv0);
fprintf(stderr, " where\n");
fprintf(stderr, " -x do transactions (one transaction per iteration) (default: no transactions at all)\n");
fprintf(stderr, " n_iterations how many iterations (default %lld iterations of %d items per iteration)\n", default_n_items/ITEMS_TO_INSERT_PER_ITERATION, ITEMS_TO_INSERT_PER_ITERATION);
}
int main (int argc, const char *argv[]) {
struct timeval t1,t2,t3; struct timeval t1,t2,t3;
long long total_n_items; long long total_n_items = default_n_items;
if (argc==2) { const char *argv0 = argv[0];
char *end; while (argc>1) {
errno=0; if (strcmp(argv[1], "-x")==0) do_transactions=1;
total_n_items = ITEMS_TO_INSERT_PER_ITERATION * (long long) strtol(argv[1], &end, 10); else {
assert(errno==0); /* if it looks like a number */
assert(*end==0); char *end;
assert(end!=argv[1]); errno=0;
} else { long n_iterations = strtol(argv[1], &end, 10);
total_n_items = 1LL<<22; // 1LL<<16 if (errno!=0 || *end!=0 || end==argv[1]) {
print_usage(argv0);
exit(1);
}
total_n_items = ITEMS_TO_INSERT_PER_ITERATION * (long long)n_iterations;
}
argc--;
argv++;
} }
printf("Serial and random insertions of %d per batch\n", ITEMS_TO_INSERT_PER_ITERATION); printf("Serial and random insertions of %d per batch%s\n", ITEMS_TO_INSERT_PER_ITERATION, do_transactions ? " (with transactions)" : "");
setup(); setup();
gettimeofday(&t1,0); gettimeofday(&t1,0);
biginsert(total_n_items, &t1); biginsert(total_n_items, &t1);
......
...@@ -50,7 +50,7 @@ int tokulogger_create_and_open_logger (const char *directory, TOKULOGGER *result ...@@ -50,7 +50,7 @@ int tokulogger_create_and_open_logger (const char *directory, TOKULOGGER *result
int tokulogger_log_bytes(TOKULOGGER logger, int nbytes, void *bytes) { int tokulogger_log_bytes(TOKULOGGER logger, int nbytes, void *bytes) {
int r; int r;
printf("%s:%d logging %d bytes\n", __FILE__, __LINE__, nbytes); //printf("%s:%d logging %d bytes\n", __FILE__, __LINE__, nbytes);
if (logger->fd==-1) { if (logger->fd==-1) {
int fnamelen = strlen(logger->directory)+50; int fnamelen = strlen(logger->directory)+50;
char fname[fnamelen]; char fname[fnamelen];
......
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