|
|
|
@ -77,16 +77,34 @@ static deque<string> get_hosts(const string& name) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Namespace for classes and functions used only in RunScenario
|
|
|
|
|
// Using this rather than local definitions to workaround gcc-4.4 limitations
|
|
|
|
|
// regarding using templates without linkage
|
|
|
|
|
namespace runsc { |
|
|
|
|
|
|
|
|
|
// ClientContext allocator
|
|
|
|
|
static ClientContext* AllocContext(list<ClientContext>* contexts) { |
|
|
|
|
contexts->emplace_back(); |
|
|
|
|
return &contexts->back(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct ServerData { |
|
|
|
|
unique_ptr<Worker::Stub> stub; |
|
|
|
|
unique_ptr<ClientReaderWriter<ServerArgs, ServerStatus>> stream; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct ClientData { |
|
|
|
|
unique_ptr<Worker::Stub> stub; |
|
|
|
|
unique_ptr<ClientReaderWriter<ClientArgs, ClientStatus>> stream; |
|
|
|
|
}; |
|
|
|
|
} // namespace runsc
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<ScenarioResult> RunScenario( |
|
|
|
|
const ClientConfig& initial_client_config, size_t num_clients, |
|
|
|
|
const ServerConfig& server_config, size_t num_servers, int warmup_seconds, |
|
|
|
|
int benchmark_seconds, int spawn_local_worker_count) { |
|
|
|
|
// ClientContext allocator (all are destroyed at scope exit)
|
|
|
|
|
// ClientContext allocations (all are destroyed at scope exit)
|
|
|
|
|
list<ClientContext> contexts; |
|
|
|
|
auto alloc_context = [&contexts]() { |
|
|
|
|
contexts.emplace_back(); |
|
|
|
|
return &contexts.back(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// To be added to the result, containing the final configuration used for
|
|
|
|
|
// client and config (incluiding host, etc.)
|
|
|
|
@ -131,23 +149,22 @@ std::unique_ptr<ScenarioResult> RunScenario( |
|
|
|
|
workers.resize(num_clients + num_servers); |
|
|
|
|
|
|
|
|
|
// Start servers
|
|
|
|
|
struct ServerData { |
|
|
|
|
unique_ptr<Worker::Stub> stub; |
|
|
|
|
unique_ptr<ClientReaderWriter<ServerArgs, ServerStatus>> stream; |
|
|
|
|
}; |
|
|
|
|
vector<ServerData> servers; |
|
|
|
|
using runsc::ServerData; |
|
|
|
|
// servers is array rather than std::vector to avoid gcc-4.4 issues
|
|
|
|
|
// where class contained in std::vector must have a copy constructor
|
|
|
|
|
auto* servers = new ServerData[num_servers]; |
|
|
|
|
for (size_t i = 0; i < num_servers; i++) { |
|
|
|
|
ServerData sd; |
|
|
|
|
sd.stub = std::move(Worker::NewStub( |
|
|
|
|
servers[i].stub = std::move(Worker::NewStub( |
|
|
|
|
CreateChannel(workers[i], InsecureCredentials(), ChannelArguments()))); |
|
|
|
|
ServerArgs args; |
|
|
|
|
result_server_config = server_config; |
|
|
|
|
result_server_config.set_host(workers[i]); |
|
|
|
|
*args.mutable_setup() = server_config; |
|
|
|
|
sd.stream = std::move(sd.stub->RunServer(alloc_context())); |
|
|
|
|
GPR_ASSERT(sd.stream->Write(args)); |
|
|
|
|
servers[i].stream = |
|
|
|
|
std::move(servers[i].stub->RunServer(runsc::AllocContext(&contexts))); |
|
|
|
|
GPR_ASSERT(servers[i].stream->Write(args)); |
|
|
|
|
ServerStatus init_status; |
|
|
|
|
GPR_ASSERT(sd.stream->Read(&init_status)); |
|
|
|
|
GPR_ASSERT(servers[i].stream->Read(&init_status)); |
|
|
|
|
char* host; |
|
|
|
|
char* driver_port; |
|
|
|
|
char* cli_target; |
|
|
|
@ -157,30 +174,25 @@ std::unique_ptr<ScenarioResult> RunScenario( |
|
|
|
|
gpr_free(host); |
|
|
|
|
gpr_free(driver_port); |
|
|
|
|
gpr_free(cli_target); |
|
|
|
|
|
|
|
|
|
servers.push_back(std::move(sd)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Start clients
|
|
|
|
|
struct ClientData { |
|
|
|
|
unique_ptr<Worker::Stub> stub; |
|
|
|
|
unique_ptr<ClientReaderWriter<ClientArgs, ClientStatus>> stream; |
|
|
|
|
}; |
|
|
|
|
vector<ClientData> clients; |
|
|
|
|
using runsc::ClientData; |
|
|
|
|
// clients is array rather than std::vector to avoid gcc-4.4 issues
|
|
|
|
|
// where class contained in std::vector must have a copy constructor
|
|
|
|
|
auto* clients = new ClientData[num_clients]; |
|
|
|
|
for (size_t i = 0; i < num_clients; i++) { |
|
|
|
|
ClientData cd; |
|
|
|
|
cd.stub = std::move(Worker::NewStub(CreateChannel( |
|
|
|
|
clients[i].stub = std::move(Worker::NewStub(CreateChannel( |
|
|
|
|
workers[i + num_servers], InsecureCredentials(), ChannelArguments()))); |
|
|
|
|
ClientArgs args; |
|
|
|
|
result_client_config = client_config; |
|
|
|
|
result_client_config.set_host(workers[i + num_servers]); |
|
|
|
|
*args.mutable_setup() = client_config; |
|
|
|
|
cd.stream = std::move(cd.stub->RunTest(alloc_context())); |
|
|
|
|
GPR_ASSERT(cd.stream->Write(args)); |
|
|
|
|
clients[i].stream = |
|
|
|
|
std::move(clients[i].stub->RunTest(runsc::AllocContext(&contexts))); |
|
|
|
|
GPR_ASSERT(clients[i].stream->Write(args)); |
|
|
|
|
ClientStatus init_status; |
|
|
|
|
GPR_ASSERT(cd.stream->Read(&init_status)); |
|
|
|
|
|
|
|
|
|
clients.push_back(std::move(cd)); |
|
|
|
|
GPR_ASSERT(clients[i].stream->Read(&init_status)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Let everything warmup
|
|
|
|
@ -195,23 +207,25 @@ std::unique_ptr<ScenarioResult> RunScenario( |
|
|
|
|
server_mark.mutable_mark(); |
|
|
|
|
ClientArgs client_mark; |
|
|
|
|
client_mark.mutable_mark(); |
|
|
|
|
for (auto server = servers.begin(); server != servers.end(); server++) { |
|
|
|
|
for (auto server = &servers[0]; server != &servers[num_servers]; server++) { |
|
|
|
|
GPR_ASSERT(server->stream->Write(server_mark)); |
|
|
|
|
} |
|
|
|
|
for (auto client = clients.begin(); client != clients.end(); client++) { |
|
|
|
|
for (auto client = &clients[0]; client != &clients[num_clients]; client++) { |
|
|
|
|
GPR_ASSERT(client->stream->Write(client_mark)); |
|
|
|
|
} |
|
|
|
|
ServerStatus server_status; |
|
|
|
|
ClientStatus client_status; |
|
|
|
|
for (auto server = servers.begin(); server != servers.end(); server++) { |
|
|
|
|
for (auto server = &servers[0]; server != &servers[num_servers]; server++) { |
|
|
|
|
GPR_ASSERT(server->stream->Read(&server_status)); |
|
|
|
|
} |
|
|
|
|
for (auto client = clients.begin(); client != clients.end(); client++) { |
|
|
|
|
for (auto client = &clients[0]; client != &clients[num_clients]; client++) { |
|
|
|
|
GPR_ASSERT(client->stream->Read(&client_status)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Wait some time
|
|
|
|
|
gpr_log(GPR_INFO, "Running"); |
|
|
|
|
// Use gpr_sleep_until rather than this_thread::sleep_until to support
|
|
|
|
|
// compilers that don't work with this_thread
|
|
|
|
|
gpr_sleep_until(gpr_time_add( |
|
|
|
|
start, gpr_time_from_seconds(benchmark_seconds, GPR_TIMESPAN))); |
|
|
|
|
|
|
|
|
@ -220,34 +234,36 @@ std::unique_ptr<ScenarioResult> RunScenario( |
|
|
|
|
result->client_config = result_client_config; |
|
|
|
|
result->server_config = result_server_config; |
|
|
|
|
gpr_log(GPR_INFO, "Finishing"); |
|
|
|
|
for (auto server = servers.begin(); server != servers.end(); server++) { |
|
|
|
|
for (auto server = &servers[0]; server != &servers[num_servers]; server++) { |
|
|
|
|
GPR_ASSERT(server->stream->Write(server_mark)); |
|
|
|
|
} |
|
|
|
|
for (auto client = clients.begin(); client != clients.end(); client++) { |
|
|
|
|
for (auto client = &clients[0]; client != &clients[num_clients]; client++) { |
|
|
|
|
GPR_ASSERT(client->stream->Write(client_mark)); |
|
|
|
|
} |
|
|
|
|
for (auto server = servers.begin(); server != servers.end(); server++) { |
|
|
|
|
for (auto server = &servers[0]; server != &servers[num_servers]; server++) { |
|
|
|
|
GPR_ASSERT(server->stream->Read(&server_status)); |
|
|
|
|
const auto& stats = server_status.stats(); |
|
|
|
|
result->server_resources.push_back(ResourceUsage{ |
|
|
|
|
stats.time_elapsed(), stats.time_user(), stats.time_system()}); |
|
|
|
|
result->server_resources.emplace_back( |
|
|
|
|
stats.time_elapsed(), stats.time_user(), stats.time_system()); |
|
|
|
|
} |
|
|
|
|
for (auto client = clients.begin(); client != clients.end(); client++) { |
|
|
|
|
for (auto client = &clients[0]; client != &clients[num_clients]; client++) { |
|
|
|
|
GPR_ASSERT(client->stream->Read(&client_status)); |
|
|
|
|
const auto& stats = client_status.stats(); |
|
|
|
|
result->latencies.MergeProto(stats.latencies()); |
|
|
|
|
result->client_resources.push_back(ResourceUsage{ |
|
|
|
|
stats.time_elapsed(), stats.time_user(), stats.time_system()}); |
|
|
|
|
result->client_resources.emplace_back( |
|
|
|
|
stats.time_elapsed(), stats.time_user(), stats.time_system()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (auto client = clients.begin(); client != clients.end(); client++) { |
|
|
|
|
for (auto client = &clients[0]; client != &clients[num_clients]; client++) { |
|
|
|
|
GPR_ASSERT(client->stream->WritesDone()); |
|
|
|
|
GPR_ASSERT(client->stream->Finish().ok()); |
|
|
|
|
} |
|
|
|
|
for (auto server = servers.begin(); server != servers.end(); server++) { |
|
|
|
|
for (auto server = &servers[0]; server != &servers[num_servers]; server++) { |
|
|
|
|
GPR_ASSERT(server->stream->WritesDone()); |
|
|
|
|
GPR_ASSERT(server->stream->Finish().ok()); |
|
|
|
|
} |
|
|
|
|
delete[] clients; |
|
|
|
|
delete[] servers; |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
} // namespace testing
|
|
|
|
|