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
This commit is contained in:
sdong 2014-08-19 12:50:13 -07:00
parent 6929b08616
commit 045575ad0c

View File

@ -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 " 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 " "the query will be against DB. Otherwise, will be directly against "
"a table reader."); "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", DEFINE_string(time_unit, "microsecond",
"The time unit used for measuring performance. User can specify " "The time unit used for measuring performance. User can specify "
"`microsecond` (default) or `nanosecond`"); "`microsecond` (default) or `nanosecond`");
@ -242,7 +244,7 @@ int main(int argc, char** argv) {
" [OPTIONS]..."); " [OPTIONS]...");
ParseCommandLineFlags(&argc, &argv, true); ParseCommandLineFlags(&argc, &argv, true);
rocksdb::TableFactory* tf = new rocksdb::BlockBasedTableFactory(); std::shared_ptr<rocksdb::TableFactory> tf;
rocksdb::Options options; rocksdb::Options options;
if (FLAGS_prefix_len < 16) { if (FLAGS_prefix_len < 16) {
options.prefix_extractor.reset(rocksdb::NewFixedPrefixTransform( options.prefix_extractor.reset(rocksdb::NewFixedPrefixTransform(
@ -253,7 +255,12 @@ int main(int argc, char** argv) {
options.create_if_missing = true; options.create_if_missing = true;
options.compression = rocksdb::CompressionType::kNoCompression; 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; options.allow_mmap_reads = true;
env_options.use_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.bloom_bits_per_key = (FLAGS_prefix_len == 16) ? 0 : 8;
plain_table_options.hash_table_ratio = 0.75; 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( options.prefix_extractor.reset(rocksdb::NewFixedPrefixTransform(
FLAGS_prefix_len)); FLAGS_prefix_len));
} else if (FLAGS_table_factory == "block_based") {
tf.reset(new rocksdb::BlockBasedTableFactory());
} else { } 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<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; return 0;
} }