db_bench: add IteratorCreationWhileWriting mode and allow prefix_seek

Summary: as title

Test Plan: ran it

Reviewers: igor, haobo, yhchiang

Reviewed By: igor

CC: leveldb

Differential Revision: https://reviews.facebook.net/D17655
This commit is contained in:
Lei Jin 2014-04-10 10:15:59 -07:00
parent ca4fa2047e
commit 7a92537fc4

View File

@ -47,6 +47,8 @@ DEFINE_string(benchmarks,
"overwrite,"
"readrandom,"
"readrandom,"
"newiterator,"
"newiteratorwhilewriting,"
"readseq,"
"readreverse,"
"compact,"
@ -1172,6 +1174,9 @@ class Benchmark {
method = &Benchmark::ReadRandom;
} else if (name == Slice("newiterator")) {
method = &Benchmark::IteratorCreation;
} else if (name == Slice("newiteratorwhilewriting")) {
num_threads++; // Add extra thread for writing
method = &Benchmark::IteratorCreationWhileWriting;
} else if (name == Slice("seekrandom")) {
method = &Benchmark::SeekRandom;
} else if (name == Slice("readrandomsmall")) {
@ -1864,6 +1869,7 @@ class Benchmark {
void IteratorCreation(ThreadState* thread) {
Duration duration(FLAGS_duration, reads_);
ReadOptions options(FLAGS_verify_checksum, true);
options.prefix_seek = (FLAGS_prefix_size > 0);
while (!duration.Done(1)) {
Iterator* iter = db_->NewIterator(options);
delete iter;
@ -1871,6 +1877,14 @@ class Benchmark {
}
}
void IteratorCreationWhileWriting(ThreadState* thread) {
if (thread->tid > 0) {
IteratorCreation(thread);
} else {
BGWriter(thread);
}
}
void SeekRandom(ThreadState* thread) {
int64_t read = 0;
int64_t found = 0;
@ -1934,6 +1948,11 @@ class Benchmark {
if (thread->tid > 0) {
ReadRandom(thread);
} else {
BGWriter(thread);
}
}
void BGWriter(ThreadState* thread) {
// Special thread that keeps writing until other threads are done.
RandomGenerator gen;
double last = FLAGS_env->NowMicros();
@ -1984,7 +2003,6 @@ class Benchmark {
}
}
}
}
// Given a key K and value V, this puts (K+"0", V), (K+"1", V), (K+"2", V)
// in DB atomically i.e in a single batch. Also refer GetMany.