initial merge of latency vs load to qps_json_driver.cc

pull/8313/head
Yuxuan Li 8 years ago
parent fe21ec90f6
commit 58977f1466
  1. 116
      test/cpp/qps/qps_json_driver.cc

@ -50,13 +50,100 @@ DEFINE_string(scenarios_json, "",
"JSON string containing an array of Scenario objects");
DEFINE_bool(quit, false, "Quit the workers");
DEFINE_bool(search, flase, "Search for offered load setting that achieves targeted cpu load");
DEFINE_double(initial_offered_load, 1000.0, "Set up for intial offered load");
DEFINE_double(targeted_cpu_load, 99.0, "targeted cpu load");
DEFINE_double(precision, 500, "final search result precision");
namespace grpc {
namespace testing {
static std::unique_ptr<ScenarioResult> RunAndReport(const Scenario& scenario,
bool* success) {
std::cerr << "RUNNING SCENARIO: " << scenario.name() << "\n";
auto result =
RunScenario(scenario.client_config(), scenario.num_clients(),
scenario.server_config(), scenario.num_servers(),
scenario.warmup_seconds(), scenario.benchmark_seconds(),
scenario.spawn_local_worker_count());
// Amend the result with scenario config. Eventually we should adjust
// RunScenario contract so we don't need to touch the result here.
result->mutable_scenario()->CopyFrom(scenario);
GetReporter()->ReportQPS(*result);
GetReporter()->ReportQPSPerCore(*result);
GetReporter()->ReportLatency(*result);
GetReporter()->ReportTimes(*result);
GetReporter()->ReportCpuUsage(*result);
for (int i = 0; *success && i < result->client_success_size(); i++) {
*success = result->client_success(i);
}
for (int i = 0; *success && i < result->server_success_size(); i++) {
*success = result->server_success(i);
}
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);
auto result = RunAndReport(*scenario, success);
return result->summary().server_cpu_usage();
}
static double BinarySearch(Scenario * scenario, double targeted_cpu_load,
double low_offered_load, double high_offered_load, bool* success) {
while (low <= high - FLAGS_precision) {
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) {
gpr_log(GPR_ERROR, "Client/Server Failure");
break;
}
if (targeted_cpu_load < current_cpu_load) {
high = mid -1;
}
else if (targeted_cpu_load > current_cpu_load) {
low = mid + 1;
}
else {
high = mid - 1;
}
}
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;
}
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);
return targeted_offered_load;
}
static bool QpsDriver() {
grpc::string json;
@ -97,29 +184,14 @@ static bool QpsDriver() {
GPR_ASSERT(scenarios.scenarios_size() > 0);
for (int i = 0; i < scenarios.scenarios_size(); i++) {
const Scenario &scenario = scenarios.scenarios(i);
std::cerr << "RUNNING SCENARIO: " << scenario.name() << "\n";
auto result =
RunScenario(scenario.client_config(), scenario.num_clients(),
scenario.server_config(), scenario.num_servers(),
scenario.warmup_seconds(), scenario.benchmark_seconds(),
scenario.spawn_local_worker_count());
// Amend the result with scenario config. Eventually we should adjust
// RunScenario contract so we don't need to touch the result here.
result->mutable_scenario()->CopyFrom(scenario);
GetReporter()->ReportQPS(*result);
GetReporter()->ReportQPSPerCore(*result);
GetReporter()->ReportLatency(*result);
GetReporter()->ReportTimes(*result);
GetReporter()->ReportCpuUsage(*result);
for (int i = 0; success && i < result->client_success_size(); i++) {
success = result->client_success(i);
if (!FLAGS_search) {
const Scenario &scenario = scenarios.scenarios(i);
RunAndReport(scenario, &success);
}
for (int i = 0; success && i < result->server_success_size(); i++) {
success = result->server_success(i);
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);
}
}
return success;

Loading…
Cancel
Save