Skip to content

Commit

Permalink
Merge pull request grpc#9184 from jtattermusch/qps_driver_cmdline
Browse files Browse the repository at this point in the history
Better qps_json_driver message when QPS_WORKERS env is missing
  • Loading branch information
jtattermusch committed Dec 22, 2016
2 parents c3c1240 + 9f89107 commit d7c923d
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions test/cpp/qps/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/support/env.h"
Expand Down Expand Up @@ -99,23 +100,36 @@ static std::unordered_map<string, std::deque<int>> get_hosts_and_cores(
return hosts;
}

static deque<string> get_workers(const string& name) {
char* env = gpr_getenv(name.c_str());
if (!env || strlen(env) == 0) return deque<string>();

static deque<string> get_workers(const string& env_name) {
char* env = gpr_getenv(env_name.c_str());
if (!env) {
env = gpr_strdup("");
}
deque<string> out;
char* p = env;
for (;;) {
char* comma = strchr(p, ',');
if (comma) {
out.emplace_back(p, comma);
p = comma + 1;
} else {
out.emplace_back(p);
gpr_free(env);
return out;
if (strlen(env) != 0) {
for (;;) {
char* comma = strchr(p, ',');
if (comma) {
out.emplace_back(p, comma);
p = comma + 1;
} else {
out.emplace_back(p);
break;
}
}
}
if (out.size() == 0) {
gpr_log(GPR_ERROR,
"Environment variable \"%s\" does not contain a list of QPS "
"workers to use. Set it to a comma-separated list of "
"hostname:port pairs, starting with hosts that should act as "
"servers. E.g. export "
"%s=\"serverhost1:1234,clienthost1:1234,clienthost2:1234\"",
env_name.c_str(), env_name.c_str());
}
gpr_free(env);
return out;
}

// helpers for postprocess_scenario_result
Expand Down Expand Up @@ -241,6 +255,7 @@ std::unique_ptr<ScenarioResult> RunScenario(
workers.push_back(addr);
}
}
GPR_ASSERT(workers.size() != 0);

// if num_clients is set to <=0, do dynamic sizing: all workers
// except for servers are clients
Expand Down Expand Up @@ -560,6 +575,9 @@ bool RunQuit() {
// Get client, server lists
bool result = true;
auto workers = get_workers("QPS_WORKERS");
if (workers.size() == 0) {
return false;
}
for (size_t i = 0; i < workers.size(); i++) {
auto stub = WorkerService::NewStub(
CreateChannel(workers[i], InsecureChannelCredentials()));
Expand Down

0 comments on commit d7c923d

Please sign in to comment.