|
|
@ -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( |
|
|
|
std::unique_ptr<ScenarioResult> RunScenario( |
|
|
|
const ClientConfig& initial_client_config, size_t num_clients, |
|
|
|
const ClientConfig& initial_client_config, size_t num_clients, |
|
|
|
const ServerConfig& server_config, size_t num_servers, int warmup_seconds, |
|
|
|
const ServerConfig& server_config, size_t num_servers, int warmup_seconds, |
|
|
|
int benchmark_seconds, int spawn_local_worker_count) { |
|
|
|
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; |
|
|
|
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
|
|
|
|
// To be added to the result, containing the final configuration used for
|
|
|
|
// client and config (incluiding host, etc.)
|
|
|
|
// client and config (incluiding host, etc.)
|
|
|
@ -131,23 +149,22 @@ std::unique_ptr<ScenarioResult> RunScenario( |
|
|
|
workers.resize(num_clients + num_servers); |
|
|
|
workers.resize(num_clients + num_servers); |
|
|
|
|
|
|
|
|
|
|
|
// Start servers
|
|
|
|
// Start servers
|
|
|
|
struct ServerData { |
|
|
|
using runsc::ServerData; |
|
|
|
unique_ptr<Worker::Stub> stub; |
|
|
|
// servers is array rather than std::vector to avoid gcc-4.4 issues
|
|
|
|
unique_ptr<ClientReaderWriter<ServerArgs, ServerStatus>> stream; |
|
|
|
// where class contained in std::vector must have a copy constructor
|
|
|
|
}; |
|
|
|
auto* servers = new ServerData[num_servers]; |
|
|
|
vector<ServerData> servers; |
|
|
|
|
|
|
|
for (size_t i = 0; i < num_servers; i++) { |
|
|
|
for (size_t i = 0; i < num_servers; i++) { |
|
|
|
ServerData sd; |
|
|
|
servers[i].stub = std::move(Worker::NewStub( |
|
|
|
sd.stub = std::move(Worker::NewStub( |
|
|
|
|
|
|
|
CreateChannel(workers[i], InsecureCredentials(), ChannelArguments()))); |
|
|
|
CreateChannel(workers[i], InsecureCredentials(), ChannelArguments()))); |
|
|
|
ServerArgs args; |
|
|
|
ServerArgs args; |
|
|
|
result_server_config = server_config; |
|
|
|
result_server_config = server_config; |
|
|
|
result_server_config.set_host(workers[i]); |
|
|
|
result_server_config.set_host(workers[i]); |
|
|
|
*args.mutable_setup() = server_config; |
|
|
|
*args.mutable_setup() = server_config; |
|
|
|
sd.stream = std::move(sd.stub->RunServer(alloc_context())); |
|
|
|
servers[i].stream = |
|
|
|
GPR_ASSERT(sd.stream->Write(args)); |
|
|
|
std::move(servers[i].stub->RunServer(runsc::AllocContext(&contexts))); |
|
|
|
|
|
|
|
GPR_ASSERT(servers[i].stream->Write(args)); |
|
|
|
ServerStatus init_status; |
|
|
|
ServerStatus init_status; |
|
|
|
GPR_ASSERT(sd.stream->Read(&init_status)); |
|
|
|
GPR_ASSERT(servers[i].stream->Read(&init_status)); |
|
|
|
char* host; |
|
|
|
char* host; |
|
|
|
char* driver_port; |
|
|
|
char* driver_port; |
|
|
|
char* cli_target; |
|
|
|
char* cli_target; |
|
|
@ -157,30 +174,25 @@ std::unique_ptr<ScenarioResult> RunScenario( |
|
|
|
gpr_free(host); |
|
|
|
gpr_free(host); |
|
|
|
gpr_free(driver_port); |
|
|
|
gpr_free(driver_port); |
|
|
|
gpr_free(cli_target); |
|
|
|
gpr_free(cli_target); |
|
|
|
|
|
|
|
|
|
|
|
servers.push_back(std::move(sd)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Start clients
|
|
|
|
// Start clients
|
|
|
|
struct ClientData { |
|
|
|
using runsc::ClientData; |
|
|
|
unique_ptr<Worker::Stub> stub; |
|
|
|
// clients is array rather than std::vector to avoid gcc-4.4 issues
|
|
|
|
unique_ptr<ClientReaderWriter<ClientArgs, ClientStatus>> stream; |
|
|
|
// where class contained in std::vector must have a copy constructor
|
|
|
|
}; |
|
|
|
auto* clients = new ClientData[num_clients]; |
|
|
|
vector<ClientData> clients; |
|
|
|
|
|
|
|
for (size_t i = 0; i < num_clients; i++) { |
|
|
|
for (size_t i = 0; i < num_clients; i++) { |
|
|
|
ClientData cd; |
|
|
|
clients[i].stub = std::move(Worker::NewStub(CreateChannel( |
|
|
|
cd.stub = std::move(Worker::NewStub(CreateChannel( |
|
|
|
|
|
|
|
workers[i + num_servers], InsecureCredentials(), ChannelArguments()))); |
|
|
|
workers[i + num_servers], InsecureCredentials(), ChannelArguments()))); |
|
|
|
ClientArgs args; |
|
|
|
ClientArgs args; |
|
|
|
result_client_config = client_config; |
|
|
|
result_client_config = client_config; |
|
|
|
result_client_config.set_host(workers[i + num_servers]); |
|
|
|
result_client_config.set_host(workers[i + num_servers]); |
|
|
|
*args.mutable_setup() = client_config; |
|
|
|
*args.mutable_setup() = client_config; |
|
|
|
cd.stream = std::move(cd.stub->RunTest(alloc_context())); |
|
|
|
clients[i].stream = |
|
|
|
GPR_ASSERT(cd.stream->Write(args)); |
|
|
|
std::move(clients[i].stub->RunTest(runsc::AllocContext(&contexts))); |
|
|
|
|
|
|
|
GPR_ASSERT(clients[i].stream->Write(args)); |
|
|
|
ClientStatus init_status; |
|
|
|
ClientStatus init_status; |
|
|
|
GPR_ASSERT(cd.stream->Read(&init_status)); |
|
|
|
GPR_ASSERT(clients[i].stream->Read(&init_status)); |
|
|
|
|
|
|
|
|
|
|
|
clients.push_back(std::move(cd)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Let everything warmup
|
|
|
|
// Let everything warmup
|
|
|
@ -195,23 +207,25 @@ std::unique_ptr<ScenarioResult> RunScenario( |
|
|
|
server_mark.mutable_mark(); |
|
|
|
server_mark.mutable_mark(); |
|
|
|
ClientArgs client_mark; |
|
|
|
ClientArgs client_mark; |
|
|
|
client_mark.mutable_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)); |
|
|
|
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)); |
|
|
|
GPR_ASSERT(client->stream->Write(client_mark)); |
|
|
|
} |
|
|
|
} |
|
|
|
ServerStatus server_status; |
|
|
|
ServerStatus server_status; |
|
|
|
ClientStatus client_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)); |
|
|
|
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)); |
|
|
|
GPR_ASSERT(client->stream->Read(&client_status)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Wait some time
|
|
|
|
// Wait some time
|
|
|
|
gpr_log(GPR_INFO, "Running"); |
|
|
|
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( |
|
|
|
gpr_sleep_until(gpr_time_add( |
|
|
|
start, gpr_time_from_seconds(benchmark_seconds, GPR_TIMESPAN))); |
|
|
|
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->client_config = result_client_config; |
|
|
|
result->server_config = result_server_config; |
|
|
|
result->server_config = result_server_config; |
|
|
|
gpr_log(GPR_INFO, "Finishing"); |
|
|
|
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)); |
|
|
|
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)); |
|
|
|
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)); |
|
|
|
GPR_ASSERT(server->stream->Read(&server_status)); |
|
|
|
const auto& stats = server_status.stats(); |
|
|
|
const auto& stats = server_status.stats(); |
|
|
|
result->server_resources.push_back(ResourceUsage{ |
|
|
|
result->server_resources.emplace_back( |
|
|
|
stats.time_elapsed(), stats.time_user(), stats.time_system()}); |
|
|
|
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)); |
|
|
|
GPR_ASSERT(client->stream->Read(&client_status)); |
|
|
|
const auto& stats = client_status.stats(); |
|
|
|
const auto& stats = client_status.stats(); |
|
|
|
result->latencies.MergeProto(stats.latencies()); |
|
|
|
result->latencies.MergeProto(stats.latencies()); |
|
|
|
result->client_resources.push_back(ResourceUsage{ |
|
|
|
result->client_resources.emplace_back( |
|
|
|
stats.time_elapsed(), stats.time_user(), stats.time_system()}); |
|
|
|
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->WritesDone()); |
|
|
|
GPR_ASSERT(client->stream->Finish().ok()); |
|
|
|
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->WritesDone()); |
|
|
|
GPR_ASSERT(server->stream->Finish().ok()); |
|
|
|
GPR_ASSERT(server->stream->Finish().ok()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
delete[] clients; |
|
|
|
|
|
|
|
delete[] servers; |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
} // namespace testing
|
|
|
|
} // namespace testing
|
|
|
|