From 045575ad0cf7a957ee6b8fe4e77b588b18a11935 Mon Sep 17 00:00:00 2001 From: sdong Date: Tue, 19 Aug 2014 12:50:13 -0700 Subject: [PATCH] Add CuckooHash table format to table_reader_bench 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 --- table/table_reader_bench.cc | 41 ++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/table/table_reader_bench.cc b/table/table_reader_bench.cc index effa90a0b..ed2c7c52d 100644 --- a/table/table_reader_bench.cc +++ b/table/table_reader_bench.cc @@ -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`"); @@ -242,7 +244,7 @@ int main(int argc, char** argv) { " [OPTIONS]..."); ParseCommandLineFlags(&argc, &argv, true); - rocksdb::TableFactory* tf = new rocksdb::BlockBasedTableFactory(); + std::shared_ptr tf; rocksdb::Options options; if (FLAGS_prefix_len < 16) { options.prefix_extractor.reset(rocksdb::NewFixedPrefixTransform( @@ -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; @@ -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 { - tf = new rocksdb::BlockBasedTableFactory(); + 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 { + 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(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; }