Skip to content

Commit

Permalink
Update scan-perf: read_line return a bool value #2
Browse files Browse the repository at this point in the history
  • Loading branch information
vrofze committed Oct 16, 2018
1 parent 475a71f commit 214b1a7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
22 changes: 13 additions & 9 deletions scan-perf/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ int main(int argc, char* argv[])
// rocksdb options
settings.opt.create_if_missing = true;
rocksdb::BlockBasedTableOptions bbto;
bbto.block_cache = rocksdb::NewLRUCache(32ULL << 10, 8, false);
bbto.block_cache = rocksdb::NewLRUCache(32ULL << 30, 8, false);
bbto.block_size = 16 << 10;
settings.opt.compression = CompressionType::kSnappyCompression;
settings.opt.table_factory.reset(rocksdb::NewBlockBasedTableFactory(bbto));

if (argc >= 3) {
Expand All @@ -62,21 +64,23 @@ int main(int argc, char* argv[])

if (!strcmp(argv[1], "load")) {
db->load();
db->compact();
//db->compact();
} else if (!strcmp(argv[1], "compact")) {
db->compact();
} else if (!strcmp(argv[1], "run")) {
db->load_keys();
//db->load_keys();
printf("%s\n", "benchmark begin!");

benchmark::RegisterBenchmark("warn-up", scan, db)->Unit(benchmark::kMillisecond);
benchmark::RegisterBenchmark("scan", scan, db)->Unit(benchmark::kMillisecond);
benchmark::RegisterBenchmark("scan", scan, db)->Unit(benchmark::kMillisecond)->Iterations(100);
benchmark::RegisterBenchmark("scan_rev", scan_rev, db)->Unit(benchmark::kMillisecond);
benchmark::RegisterBenchmark("seek", seek, db)->Unit(benchmark::kMillisecond);
benchmark::RegisterBenchmark("seek_next", seek_next, db)->Unit(benchmark::kMillisecond)
->Arg(10)->Arg(20);
benchmark::RegisterBenchmark("seek_prev", seek_prev, db)->Unit(benchmark::kMillisecond)
->Arg(10)->Arg(20);
//benchmark::RegisterBenchmark("seek", seek, db)->Unit(benchmark::kMillisecond);
//benchmark::RegisterBenchmark("seek_next", seek_next, db)->Unit(benchmark::kMillisecond)->Arg(1);
//benchmark::RegisterBenchmark("seek_prev", seek_prev, db)->Unit(benchmark::kMillisecond)->Arg(1);
//benchmark::RegisterBenchmark("seek_next", seek_next, db)->Unit(benchmark::kMillisecond)->Arg(10);
//benchmark::RegisterBenchmark("seek_prev", seek_prev, db)->Unit(benchmark::kMillisecond)->Arg(10);
//benchmark::RegisterBenchmark("seek_next", seek_next, db)->Unit(benchmark::kMillisecond)->Arg(100);
//benchmark::RegisterBenchmark("seek_prev", seek_prev, db)->Unit(benchmark::kMillisecond)->Arg(100);
benchmark::RunSpecifiedBenchmarks();
} else if (!strcmp(argv[1], "verify")) {
db->verify();
Expand Down
19 changes: 14 additions & 5 deletions scan-perf/rocksdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ RocksDB::~RocksDB()
delete db;
}

void RocksDB::read_line(char* key, char* value)
bool RocksDB::read_line(char* key, char* value)
{
assert(data_file != nullptr);

Expand All @@ -84,8 +84,10 @@ void RocksDB::read_line(char* key, char* value)
}
free(buf);
} else {
fprintf(stderr, "ERROR: file EOF, lines < limit(%ld).\n", settings.limit);
fprintf(stderr, "Reach file EOF.\n");
return false;
}
return true;
}

bool RocksDB::load()
Expand All @@ -103,7 +105,7 @@ bool RocksDB::load()
rocksdb::Status s;
while (nums < settings.limit) {
read_line(key, value);
s = db->Put(write_options, key, value);
s = db->Put(write_options, key, "");
// printf("key: %s value: %s\n", key, value);
if (!s.ok()) {
fprintf(stderr, "ERROR: error insert: %s && %s\n", key, value);
Expand Down Expand Up @@ -154,12 +156,13 @@ void RocksDB::load_keys()
size_t nums = 0;
auto key = (char *)malloc(20480 * sizeof(char));

while (nums < settings.limit) {
read_line(key, nullptr);
while (read_line(key, nullptr)) {
keys.emplace_back(std::string(key));
nums++;
}

printf("Read %lu keys.\n", nums);

free(key);
//if (data_file != nullptr) {
fclose(data_file);
Expand All @@ -169,6 +172,12 @@ void RocksDB::load_keys()

auto seed = std::chrono::system_clock::now().time_since_epoch().count();
std::shuffle(keys.begin(), keys.end(), std::default_random_engine(seed));
if (settings.limit <= nums) {
keys.resize(settings.limit);
printf("Reserve %lu keys.\n", settings.limit);
} else {
printf("Settings.limit(%lu) < nums(%lu)\n", settings.limit, nums);
}

printf("%s\n", "Load keys done");
}
Expand Down
2 changes: 1 addition & 1 deletion scan-perf/rocksdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RocksDB {
std::vector<std::string> keys;
std::vector<std::pair<std::string, std::string>> keys_values;

void read_line(char* key, char* value);
bool read_line(char* key, char* value);
};


Expand Down

0 comments on commit 214b1a7

Please sign in to comment.