Skip to content

Commit

Permalink
Add CuckooHash table format to table_reader_bench
Browse files Browse the repository at this point in the history
Summary: Make table_reader_bench cover all the three table formats.

Test Plan: Run it using three options

Reviewers: radheshyamb, ljin

Reviewed By: ljin

Subscribers: leveldb

Differential Revision: https://reviews.facebook.net/D22137
  • Loading branch information
siying committed Aug 19, 2014
1 parent 6929b08 commit 045575a
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions table/table_reader_bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ DEFINE_bool(iterator, false, "For test iterator");
DEFINE_bool(through_db, false, "If enable, a DB instance will be created and "
"the query will be against DB. Otherwise, will be directly against "
"a table reader.");
DEFINE_bool(plain_table, false, "Use PlainTable");
DEFINE_string(table_factory, "block_based",
"Table factory to use: `block_based` (default), `plain_table` or "
"`cuckoo_hash`.");
DEFINE_string(time_unit, "microsecond",
"The time unit used for measuring performance. User can specify "
"`microsecond` (default) or `nanosecond`");
Expand All @@ -242,7 +244,7 @@ int main(int argc, char** argv) {
" [OPTIONS]...");
ParseCommandLineFlags(&argc, &argv, true);

rocksdb::TableFactory* tf = new rocksdb::BlockBasedTableFactory();
std::shared_ptr<rocksdb::TableFactory> tf;
rocksdb::Options options;
if (FLAGS_prefix_len < 16) {
options.prefix_extractor.reset(rocksdb::NewFixedPrefixTransform(
Expand All @@ -253,7 +255,12 @@ int main(int argc, char** argv) {
options.create_if_missing = true;
options.compression = rocksdb::CompressionType::kNoCompression;

if (FLAGS_plain_table) {
if (FLAGS_table_factory == "cuckoo_hash") {
options.allow_mmap_reads = true;
env_options.use_mmap_reads = true;

tf.reset(rocksdb::NewCuckooTableFactory(0.75));
} else if (FLAGS_table_factory == "plain_table") {
options.allow_mmap_reads = true;
env_options.use_mmap_reads = true;

Expand All @@ -262,22 +269,28 @@ int main(int argc, char** argv) {
plain_table_options.bloom_bits_per_key = (FLAGS_prefix_len == 16) ? 0 : 8;
plain_table_options.hash_table_ratio = 0.75;

tf = new rocksdb::PlainTableFactory(plain_table_options);
tf.reset(new rocksdb::PlainTableFactory(plain_table_options));
options.prefix_extractor.reset(rocksdb::NewFixedPrefixTransform(
FLAGS_prefix_len));
} else if (FLAGS_table_factory == "block_based") {
tf.reset(new rocksdb::BlockBasedTableFactory());
} else {
fprintf(stderr, "Invalid table type %s\n", FLAGS_table_factory.c_str());
}

if (tf) {
// if user provides invalid options, just fall back to microsecond.
bool measured_by_nanosecond = FLAGS_time_unit == "nanosecond";

options.table_factory = tf;
rocksdb::TableReaderBenchmark(options, env_options, ro, FLAGS_num_keys1,
FLAGS_num_keys2, FLAGS_iter, FLAGS_prefix_len,
FLAGS_query_empty, FLAGS_iterator,
FLAGS_through_db, measured_by_nanosecond);
} else {
tf = new rocksdb::BlockBasedTableFactory();
return 1;
}
// if user provides invalid options, just fall back to microsecond.
bool measured_by_nanosecond = FLAGS_time_unit == "nanosecond";

options.table_factory =
std::shared_ptr<rocksdb::TableFactory>(tf);
rocksdb::TableReaderBenchmark(options, env_options, ro, FLAGS_num_keys1,
FLAGS_num_keys2, FLAGS_iter, FLAGS_prefix_len,
FLAGS_query_empty, FLAGS_iterator,
FLAGS_through_db, measured_by_nanosecond);
delete tf;
return 0;
}

Expand Down

0 comments on commit 045575a

Please sign in to comment.