Fix benchmarks under ROCKSDB_LITE

Summary: Fix db_bench and memtablerep_bench under ROCKSDB_LITE

Test Plan:
OPT=-DROCKSDB_LITE make db_bench -j64
OPT=-DROCKSDB_LITE make memtablerep_bench -j64
make db_bench -j64
make memtablerep_bench -j64

Reviewers: yhchiang, anthony, rven, igor, sdong

Reviewed By: sdong

Subscribers: dhruba

Differential Revision: https://reviews.facebook.net/D48717
main
Islam AbdelRahman 9 years ago
parent e587dbe03a
commit b81b2ec25d
  1. 33
      db/db_bench.cc
  2. 2
      db/memtablerep_bench.cc

@ -486,6 +486,7 @@ DEFINE_int32(deletepercent, 2, "Percentage of deletes out of reads/writes/"
DEFINE_uint64(delete_obsolete_files_period_micros, 0, DEFINE_uint64(delete_obsolete_files_period_micros, 0,
"Ignored. Left here for backward compatibility"); "Ignored. Left here for backward compatibility");
#ifndef ROCKSDB_LITE
DEFINE_bool(optimistic_transaction_db, false, DEFINE_bool(optimistic_transaction_db, false,
"Open a OptimisticTransactionDB instance. " "Open a OptimisticTransactionDB instance. "
"Required for randomtransaction benchmark."); "Required for randomtransaction benchmark.");
@ -509,6 +510,7 @@ DEFINE_int32(transaction_sleep, 0,
DEFINE_uint64(transaction_lock_timeout, 100, DEFINE_uint64(transaction_lock_timeout, 100,
"If using a transaction_db, specifies the lock wait timeout in" "If using a transaction_db, specifies the lock wait timeout in"
" milliseconds before failing a transaction waiting on a lock"); " milliseconds before failing a transaction waiting on a lock");
#endif // ROCKSDB_LITE
DEFINE_bool(compaction_measure_io_stats, false, DEFINE_bool(compaction_measure_io_stats, false,
"Measure times spents on I/Os while in compactions. "); "Measure times spents on I/Os while in compactions. ");
@ -645,7 +647,9 @@ DEFINE_int32(max_grandparent_overlap_factor, 10, "Control maximum bytes of "
"overlaps in grandparent (i.e., level+2) before we stop building a" "overlaps in grandparent (i.e., level+2) before we stop building a"
" single file in a level->level+1 compaction."); " single file in a level->level+1 compaction.");
#ifndef ROCKSDB_LITE
DEFINE_bool(readonly, false, "Run read only benchmarks."); DEFINE_bool(readonly, false, "Run read only benchmarks.");
#endif // ROCKSDB_LITE
DEFINE_bool(disable_auto_compactions, false, "Do not auto trigger compactions"); DEFINE_bool(disable_auto_compactions, false, "Do not auto trigger compactions");
@ -983,7 +987,9 @@ static void AppendWithSpace(std::string* str, Slice msg) {
struct DBWithColumnFamilies { struct DBWithColumnFamilies {
std::vector<ColumnFamilyHandle*> cfh; std::vector<ColumnFamilyHandle*> cfh;
DB* db; DB* db;
#ifndef ROCKSDB_LITE
OptimisticTransactionDB* opt_txn_db; OptimisticTransactionDB* opt_txn_db;
#endif // ROCKSDB_LITE
std::atomic<size_t> num_created; // Need to be updated after all the std::atomic<size_t> num_created; // Need to be updated after all the
// new entries in cfh are set. // new entries in cfh are set.
size_t num_hot; // Number of column families to be queried at each moment. size_t num_hot; // Number of column families to be queried at each moment.
@ -991,7 +997,12 @@ struct DBWithColumnFamilies {
// Column families will be created and used to be queried. // Column families will be created and used to be queried.
port::Mutex create_cf_mutex; // Only one thread can execute CreateNewCf() port::Mutex create_cf_mutex; // Only one thread can execute CreateNewCf()
DBWithColumnFamilies() : db(nullptr), opt_txn_db(nullptr) { DBWithColumnFamilies()
: db(nullptr)
#ifndef ROCKSDB_LITE
, opt_txn_db(nullptr)
#endif // ROCKSDB_LITE
{
cfh.clear(); cfh.clear();
num_created = 0; num_created = 0;
num_hot = 0; num_hot = 0;
@ -1000,7 +1011,9 @@ struct DBWithColumnFamilies {
DBWithColumnFamilies(const DBWithColumnFamilies& other) DBWithColumnFamilies(const DBWithColumnFamilies& other)
: cfh(other.cfh), : cfh(other.cfh),
db(other.db), db(other.db),
#ifndef ROCKSDB_LITE
opt_txn_db(other.opt_txn_db), opt_txn_db(other.opt_txn_db),
#endif // ROCKSDB_LITE
num_created(other.num_created.load()), num_created(other.num_created.load()),
num_hot(other.num_hot) {} num_hot(other.num_hot) {}
@ -1008,13 +1021,18 @@ struct DBWithColumnFamilies {
std::for_each(cfh.begin(), cfh.end(), std::for_each(cfh.begin(), cfh.end(),
[](ColumnFamilyHandle* cfhi) { delete cfhi; }); [](ColumnFamilyHandle* cfhi) { delete cfhi; });
cfh.clear(); cfh.clear();
#ifndef ROCKSDB_LITE
if (opt_txn_db) { if (opt_txn_db) {
delete opt_txn_db; delete opt_txn_db;
opt_txn_db = nullptr; opt_txn_db = nullptr;
} else { } else {
delete db; delete db;
db = nullptr;
} }
#else
delete db;
db = nullptr; db = nullptr;
#endif // ROCKSDB_LITE
} }
ColumnFamilyHandle* GetCfh(int64_t rand_num) { ColumnFamilyHandle* GetCfh(int64_t rand_num) {
@ -1940,9 +1958,11 @@ class Benchmark {
method = &Benchmark::Compress; method = &Benchmark::Compress;
} else if (name == "uncompress") { } else if (name == "uncompress") {
method = &Benchmark::Uncompress; method = &Benchmark::Uncompress;
#ifndef ROCKSDB_LITE
} else if (name == "randomtransaction") { } else if (name == "randomtransaction") {
method = &Benchmark::RandomTransaction; method = &Benchmark::RandomTransaction;
post_process_method = &Benchmark::RandomTransactionVerify; post_process_method = &Benchmark::RandomTransactionVerify;
#endif // ROCKSDB_LITE
} else if (name == "randomreplacekeys") { } else if (name == "randomreplacekeys") {
fresh_db = true; fresh_db = true;
method = &Benchmark::RandomReplaceKeys; method = &Benchmark::RandomReplaceKeys;
@ -2518,10 +2538,12 @@ class Benchmark {
NewGenericRateLimiter(FLAGS_rate_limiter_bytes_per_sec)); NewGenericRateLimiter(FLAGS_rate_limiter_bytes_per_sec));
} }
#ifndef ROCKSDB_LITE
if (FLAGS_readonly && FLAGS_transaction_db) { if (FLAGS_readonly && FLAGS_transaction_db) {
fprintf(stderr, "Cannot use readonly flag with transaction_db\n"); fprintf(stderr, "Cannot use readonly flag with transaction_db\n");
exit(1); exit(1);
} }
#endif // ROCKSDB_LITE
if (FLAGS_num_multi_db <= 1) { if (FLAGS_num_multi_db <= 1) {
OpenDb(options, FLAGS_db, &db_); OpenDb(options, FLAGS_db, &db_);
@ -2554,6 +2576,7 @@ class Benchmark {
column_families.push_back(ColumnFamilyDescriptor( column_families.push_back(ColumnFamilyDescriptor(
ColumnFamilyName(i), ColumnFamilyOptions(options))); ColumnFamilyName(i), ColumnFamilyOptions(options)));
} }
#ifndef ROCKSDB_LITE
if (FLAGS_readonly) { if (FLAGS_readonly) {
s = DB::OpenForReadOnly(options, db_name, column_families, s = DB::OpenForReadOnly(options, db_name, column_families,
&db->cfh, &db->db); &db->cfh, &db->db);
@ -2574,9 +2597,13 @@ class Benchmark {
} else { } else {
s = DB::Open(options, db_name, column_families, &db->cfh, &db->db); s = DB::Open(options, db_name, column_families, &db->cfh, &db->db);
} }
#else
s = DB::Open(options, db_name, column_families, &db->cfh, &db->db);
#endif // ROCKSDB_LITE
db->cfh.resize(FLAGS_num_column_families); db->cfh.resize(FLAGS_num_column_families);
db->num_created = num_hot; db->num_created = num_hot;
db->num_hot = num_hot; db->num_hot = num_hot;
#ifndef ROCKSDB_LITE
} else if (FLAGS_readonly) { } else if (FLAGS_readonly) {
s = DB::OpenForReadOnly(options, db_name, &db->db); s = DB::OpenForReadOnly(options, db_name, &db->db);
} else if (FLAGS_optimistic_transaction_db) { } else if (FLAGS_optimistic_transaction_db) {
@ -2591,7 +2618,7 @@ class Benchmark {
if (s.ok()) { if (s.ok()) {
db->db = ptr; db->db = ptr;
} }
#endif // ROCKSDB_LITE
} else { } else {
s = DB::Open(options, db_name, &db->db); s = DB::Open(options, db_name, &db->db);
} }
@ -3636,6 +3663,7 @@ class Benchmark {
} }
} }
#ifndef ROCKSDB_LITE
// This benchmark stress tests Transactions. For a given --duration (or // This benchmark stress tests Transactions. For a given --duration (or
// total number of --writes, a Transaction will perform a read-modify-write // total number of --writes, a Transaction will perform a read-modify-write
// to increment the value of a key in each of N(--transaction-sets) sets of // to increment the value of a key in each of N(--transaction-sets) sets of
@ -3868,6 +3896,7 @@ class Benchmark {
fprintf(stdout, "RandomTransactionVerify Success!\n"); fprintf(stdout, "RandomTransactionVerify Success!\n");
} }
#endif // ROCKSDB_LITE
// Writes and deletes random keys without overwriting keys. // Writes and deletes random keys without overwriting keys.
// //

@ -592,6 +592,7 @@ int main(int argc, char** argv) {
std::unique_ptr<rocksdb::MemTableRepFactory> factory; std::unique_ptr<rocksdb::MemTableRepFactory> factory;
if (FLAGS_memtablerep == "skiplist") { if (FLAGS_memtablerep == "skiplist") {
factory.reset(new rocksdb::SkipListFactory); factory.reset(new rocksdb::SkipListFactory);
#ifndef ROCKSDB_LITE
} else if (FLAGS_memtablerep == "vector") { } else if (FLAGS_memtablerep == "vector") {
factory.reset(new rocksdb::VectorRepFactory); factory.reset(new rocksdb::VectorRepFactory);
} else if (FLAGS_memtablerep == "hashskiplist") { } else if (FLAGS_memtablerep == "hashskiplist") {
@ -613,6 +614,7 @@ int main(int argc, char** argv) {
static_cast<uint32_t>(FLAGS_hash_function_count))); static_cast<uint32_t>(FLAGS_hash_function_count)));
options.prefix_extractor.reset( options.prefix_extractor.reset(
rocksdb::NewFixedPrefixTransform(FLAGS_prefix_length)); rocksdb::NewFixedPrefixTransform(FLAGS_prefix_length));
#endif // ROCKSDB_LITE
} else { } else {
fprintf(stdout, "Unknown memtablerep: %s\n", FLAGS_memtablerep.c_str()); fprintf(stdout, "Unknown memtablerep: %s\n", FLAGS_memtablerep.c_str());
exit(1); exit(1);

Loading…
Cancel
Save