diff options
author | Yuxuan Li <yuxuanli@google.com> | 2016-10-06 11:01:50 -0700 |
---|---|---|
committer | Yuxuan Li <yuxuanli@google.com> | 2016-10-06 15:06:01 -0700 |
commit | 49aeb5938918070e574a1eb0cf6fce1ca94e2b3a (patch) | |
tree | 094071ad0ba1aaa0b1393d14d9e8336517a55e57 /test/cpp/qps/qps_json_driver.cc | |
parent | d31c78c6f05bc1e6e6ce307b43bd47993c8aead0 (diff) |
clang-formated and latency_vs_load.cc is deleted as its functionality
has been merged into qps_json_driver.
Diffstat (limited to 'test/cpp/qps/qps_json_driver.cc')
-rw-r--r-- | test/cpp/qps/qps_json_driver.cc | 83 |
1 files changed, 45 insertions, 38 deletions
diff --git a/test/cpp/qps/qps_json_driver.cc b/test/cpp/qps/qps_json_driver.cc index ac427e3a3d..0f21466d6b 100644 --- a/test/cpp/qps/qps_json_driver.cc +++ b/test/cpp/qps/qps_json_driver.cc @@ -46,11 +46,14 @@ DEFINE_string(scenarios_file, "", "JSON file containing an array of Scenario objects"); + DEFINE_string(scenarios_json, "", "JSON string containing an array of Scenario objects"); + DEFINE_bool(quit, false, "Quit the workers"); -DEFINE_bool(search, false, "Search for offered load setting that achieves targeted cpu load"); +DEFINE_bool(search, false, + "Search for offered load setting that achieves targeted cpu load"); DEFINE_double(initial_offered_load, 1000.0, "Set up for intial offered load"); @@ -90,17 +93,20 @@ static std::unique_ptr<ScenarioResult> RunAndReport(const Scenario& scenario, return result; } -static double GetCpuLoad(Scenario * scenario, double offered_load, bool* success) { - scenario->mutable_client_config()->mutable_load_params()->mutable_poisson()-> - set_offered_load(offered_load); +static double GetCpuLoad(Scenario* scenario, double offered_load, + bool* success) { + scenario->mutable_client_config() + ->mutable_load_params() + ->mutable_poisson() + ->set_offered_load(offered_load); auto result = RunAndReport(*scenario, success); return result->summary().server_cpu_usage(); } -static double BinarySearch(Scenario * scenario, double targeted_cpu_load, - double low, double high, bool* success) { +static double BinarySearch(Scenario* scenario, double targeted_cpu_load, + double low, double high, bool* success) { while (low <= high - FLAGS_precision) { - double mid = low + (high - low) /2; + double mid = low + (high - low) / 2; double current_cpu_load = GetCpuLoad(scenario, mid, success); gpr_log(GPR_INFO, "binary search: current_offered_load %.0f", mid); if (!*success) { @@ -108,12 +114,10 @@ static double BinarySearch(Scenario * scenario, double targeted_cpu_load, break; } if (targeted_cpu_load < current_cpu_load) { - high = mid -1; - } - else if (targeted_cpu_load > current_cpu_load) { + high = mid - 1; + } else if (targeted_cpu_load > current_cpu_load) { low = mid + 1; - } - else { + } else { high = mid - 1; } } @@ -121,27 +125,29 @@ static double BinarySearch(Scenario * scenario, double targeted_cpu_load, return low; } -static double SearchOfferedLoad(double initial_offered_load, double targeted_cpu_load, - Scenario * scenario, bool* success) { - std::cerr << "RUNNING SCENARIO: " << scenario->name() << "\n"; - double current_offered_load = initial_offered_load; - double current_cpu_load = GetCpuLoad(scenario, current_offered_load, success); - if (current_cpu_load > targeted_cpu_load) { - gpr_log(GPR_ERROR, "Initial offered load too high"); - return -1; - } +static double SearchOfferedLoad(double initial_offered_load, + double targeted_cpu_load, Scenario* scenario, + bool* success) { + std::cerr << "RUNNING SCENARIO: " << scenario->name() << "\n"; + double current_offered_load = initial_offered_load; + double current_cpu_load = GetCpuLoad(scenario, current_offered_load, success); + if (current_cpu_load > targeted_cpu_load) { + gpr_log(GPR_ERROR, "Initial offered load too high"); + return -1; + } - while (*success && (current_cpu_load < targeted_cpu_load)) { - current_offered_load *= 2; - current_cpu_load = GetCpuLoad(scenario, current_offered_load, success); - gpr_log(GPR_INFO, "do while: current_offered_load %f", current_offered_load); - } + while (*success && (current_cpu_load < targeted_cpu_load)) { + current_offered_load *= 2; + current_cpu_load = GetCpuLoad(scenario, current_offered_load, success); + gpr_log(GPR_INFO, "do while: current_offered_load %f", + current_offered_load); + } - double targeted_offered_load = BinarySearch(scenario, targeted_cpu_load, - current_offered_load / 2, - current_offered_load, success); + double targeted_offered_load = + BinarySearch(scenario, targeted_cpu_load, current_offered_load / 2, + current_offered_load, success); - return targeted_offered_load; + return targeted_offered_load; } static bool QpsDriver() { @@ -159,11 +165,11 @@ static bool QpsDriver() { if (scfile) { // Read the json data from disk - FILE *json_file = fopen(FLAGS_scenarios_file.c_str(), "r"); + FILE* json_file = fopen(FLAGS_scenarios_file.c_str(), "r"); GPR_ASSERT(json_file != NULL); fseek(json_file, 0, SEEK_END); long len = ftell(json_file); - char *data = new char[len]; + char* data = new char[len]; fseek(json_file, 0, SEEK_SET); GPR_ASSERT(len == (long)fread(data, 1, len, json_file)); fclose(json_file); @@ -185,12 +191,13 @@ static bool QpsDriver() { for (int i = 0; i < scenarios.scenarios_size(); i++) { if (!FLAGS_search) { - const Scenario &scenario = scenarios.scenarios(i); + const Scenario& scenario = scenarios.scenarios(i); RunAndReport(scenario, &success); - } - else { - Scenario *scenario = scenarios.mutable_scenarios(i); - double targeted_offered_load = SearchOfferedLoad(FLAGS_initial_offered_load, FLAGS_targeted_cpu_load, scenario, &success); + } else { + Scenario* scenario = scenarios.mutable_scenarios(i); + double targeted_offered_load = + SearchOfferedLoad(FLAGS_initial_offered_load, FLAGS_targeted_cpu_load, + scenario, &success); gpr_log(GPR_INFO, "targeted_offered_load %f", targeted_offered_load); } } @@ -200,7 +207,7 @@ static bool QpsDriver() { } // namespace testing } // namespace grpc -int main(int argc, char **argv) { +int main(int argc, char** argv) { grpc::testing::InitBenchmark(&argc, &argv, true); bool ok = grpc::testing::QpsDriver(); |