Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
GehaFearless committed Feb 28, 2023
1 parent 18dccd5 commit 6d43e4a
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions src/test/bench_test/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,31 +158,27 @@ void benchmark::multi_set_random(thread_arg *thread)
{
// do write operation num times
uint64_t bytes = 0;
int count = 0;

for (int i = 0; i < config::instance().num / 100; i++) {
for (int i = 0; i < FLAGS_benchmark_num / 100; i++) {
// generate hash key
std::string hash_key, sort_key, value;
hash_key = generate_string(config::instance().hashkey_size);
hash_key = generate_string(FLAGS_hashkey_size);
std::map<std::string, std::string> kvs;

// generate sort key and value
for (int j = 0; j < 100; j++) {
sort_key = generate_string(config::instance().sortkey_size);
value = generate_string(config::instance().value_size);
sort_key = generate_string(FLAGS_sortkey_size);
value = generate_string(FLAGS_value_size);
kvs.emplace(sort_key, value);
}

// write to pegasus
int try_count = 0;
while (true) {
try_count++;
int ret = _client->multi_set(hash_key, kvs, config::instance().pegasus_timeout_ms);
int ret = _client->multi_set(hash_key, kvs, FLAGS_pegasus_timeout_ms);
if (ret == ::pegasus::PERR_OK) {
bytes += (config::instance().value_size + config::instance().hashkey_size +
config::instance().sortkey_size) *
100;
count += 100;
bytes += (FLAGS_value_size + FLAGS_hashkey_size + FLAGS_sortkey_size) * 100;
break;
} else if (ret != ::pegasus::PERR_TIMEOUT || try_count > 3) {
fmt::print(stderr, "Set returned an error: {}\n", _client->get_error_string(ret));
Expand Down Expand Up @@ -243,31 +239,34 @@ void benchmark::multi_get_random(thread_arg *thread)
{
uint64_t bytes = 0;
uint64_t found = 0;
for (int i = 0; i < config::instance().num / 100; i++) {
int max_fetch_count = 100;
int max_fetch_size = 1000000;

for (int i = 0; i < FLAGS_benchmark_num / 100; i++)
{

// generate hash key
std::string hash_key, sort_key, value;
hash_key = generate_string(config::instance().hashkey_size);
std::string hashkey, sort_key, value;
hashkey = generate_string(FLAGS_hashkey_size);
std::map<std::string, std::string> kvs;
std::set<std::string> sortkeys;

// generate sort key
// generate value for random to keep in peace with write
for (int j = 0; j < 100; j++) {
sortkeys.insert(generate_string(config::instance().sortkey_size));
value = generate_string(config::instance().value_size);
sortkeys.insert(generate_string(FLAGS_sortkey_size));
value = generate_string(FLAGS_value_size);
}

// read from pegasus
int try_count = 0;
while (true) {
try_count++;
int ret = _client->multi_get(hash_key, sortkeys, kvs);
int ret = _client->multi_get(
hashkey, sortkeys, kvs, max_fetch_count, max_fetch_size, FLAGS_pegasus_timeout_ms);
if (ret == ::pegasus::PERR_OK) {
found += 100;
bytes += (config::instance().value_size + config::instance().hashkey_size +
config::instance().sortkey_size) *
100;
bytes += (FLAGS_hashkey_size + FLAGS_sortkey_size + FLAGS_value_size) * 100;
break;
} else if (ret == ::pegasus::PERR_NOT_FOUND) {
break;
Expand All @@ -284,7 +283,7 @@ void benchmark::multi_get_random(thread_arg *thread)
}

// count total read bytes and hit rate
std::string msg = fmt::format("({} of {} found)", found, config::instance().num);
std::string msg = fmt::format("({} of {} found)", found, FLAGS_benchmark_num);
thread->stats.add_bytes(bytes);
thread->stats.add_message(msg);
}
Expand Down

0 comments on commit 6d43e4a

Please sign in to comment.