pull/837/head
Craig Tiller 10 years ago
parent 6af9ed0bf7
commit 10923c2fb5
  1. 19
      test/cpp/qps/client.cc
  2. 10
      test/cpp/qps/driver.cc
  3. 6
      test/cpp/qps/driver.h
  4. 5
      test/cpp/qps/histogram.h
  5. 10
      test/cpp/qps/qps_driver.cc
  6. 8
      test/cpp/qps/server.cc
  7. 3
      test/cpp/qps/server.h
  8. 29
      test/cpp/qps/worker.cc

@ -65,7 +65,8 @@ class SynchronousClient GRPC_FINAL : public Client {
public:
SynchronousClient(const ClientConfig& config) : timer_(new Timer) {
for (int i = 0; i < config.client_channels(); i++) {
channels_.push_back(ClientChannelInfo(config.server_targets(i % config.server_targets_size()), config));
channels_.push_back(ClientChannelInfo(
config.server_targets(i % config.server_targets_size()), config));
auto* stub = channels_.back().get_stub();
for (int j = 0; j < config.outstanding_rpcs_per_channel(); j++) {
threads_.emplace_back(new Thread(stub, config));
@ -104,11 +105,15 @@ class SynchronousClient GRPC_FINAL : public Client {
private:
class Thread {
public:
Thread(TestService::Stub* stub, const ClientConfig& config) : stub_(stub), config_(config), done_(false), new_(nullptr), impl_([this]() {
Thread(TestService::Stub* stub, const ClientConfig& config)
: stub_(stub),
config_(config),
done_(false),
new_(nullptr),
impl_([this]() {
SimpleRequest request;
SimpleResponse response;
request.set_response_type(
grpc::testing::PayloadType::COMPRESSABLE);
request.set_response_type(grpc::testing::PayloadType::COMPRESSABLE);
request.set_response_size(config_.payload_size());
for (;;) {
{
@ -122,8 +127,7 @@ class SynchronousClient GRPC_FINAL : public Client {
}
double start = Timer::Now();
grpc::ClientContext context;
grpc::Status s =
stub_->UnaryCall(&context, request, &response);
grpc::Status s = stub_->UnaryCall(&context, request, &response);
histogram_.Add((Timer::Now() - start) * 1e9);
}
}) {}
@ -162,7 +166,8 @@ class SynchronousClient GRPC_FINAL : public Client {
class ClientChannelInfo {
public:
explicit ClientChannelInfo(const grpc::string& target, const ClientConfig& config)
explicit ClientChannelInfo(const grpc::string& target,
const ClientConfig& config)
: channel_(CreateTestChannel(target, config.enable_ssl())),
stub_(TestService::NewStub(channel_)) {}
ChannelInterface* get_channel() { return channel_.get(); }

@ -83,7 +83,8 @@ void RunScenario(const ClientConfig& initial_client_config, size_t num_clients,
auto workers = get_hosts("QPS_WORKERS");
ClientConfig client_config = initial_client_config;
// TODO(ctiller): support running multiple configurations, and binpack client/server pairs
// TODO(ctiller): support running multiple configurations, and binpack
// client/server pairs
// to available workers
GPR_ASSERT(workers.size() >= num_clients + num_servers);
@ -98,7 +99,8 @@ void RunScenario(const ClientConfig& initial_client_config, size_t num_clients,
vector<ServerData> servers;
for (size_t i = 0; i < num_servers; i++) {
ServerData sd;
sd.stub = std::move(Worker::NewStub(CreateChannelDeprecated(workers[i], ChannelArguments())));
sd.stub = std::move(Worker::NewStub(
CreateChannelDeprecated(workers[i], ChannelArguments())));
ServerArgs args;
*args.mutable_setup() = server_config;
sd.stream = std::move(sd.stub->RunServer(alloc_context()));
@ -126,7 +128,8 @@ void RunScenario(const ClientConfig& initial_client_config, size_t num_clients,
vector<ClientData> clients;
for (size_t i = 0; i < num_clients; i++) {
ClientData cd;
cd.stub = std::move(Worker::NewStub(CreateChannelDeprecated(workers[i + num_servers], ChannelArguments())));
cd.stub = std::move(Worker::NewStub(
CreateChannelDeprecated(workers[i + num_servers], ChannelArguments())));
ClientArgs args;
*args.mutable_setup() = client_config;
cd.stream = std::move(cd.stub->RunTest(alloc_context()));
@ -191,6 +194,5 @@ void RunScenario(const ClientConfig& initial_client_config, size_t num_clients,
GPR_ASSERT(server.stream->Finish().IsOk());
}
}
}
}

@ -38,8 +38,10 @@
namespace grpc {
namespace testing {
void RunScenario(const grpc::testing::ClientConfig& client_config, size_t num_clients,
const grpc::testing::ServerConfig& server_config, size_t num_servers);
void RunScenario(const grpc::testing::ClientConfig& client_config,
size_t num_clients,
const grpc::testing::ServerConfig& server_config,
size_t num_servers);
}
}

@ -46,7 +46,9 @@ class Histogram {
void Merge(Histogram* h) { gpr_histogram_merge(impl_, h->impl_); }
void Add(double value) { gpr_histogram_add(impl_, value); }
double Percentile(double pctile) { return gpr_histogram_percentile(impl_, pctile); }
double Percentile(double pctile) {
return gpr_histogram_percentile(impl_, pctile);
}
double Count() { return gpr_histogram_count(impl_); }
void Swap(Histogram* other) { std::swap(impl_, other->impl_); }
@ -56,7 +58,6 @@ class Histogram {
gpr_histogram* impl_;
};
}
}

@ -47,7 +47,8 @@ DEFINE_int32(server_threads, 1, "Number of server threads");
DEFINE_string(server_type, "SYNCHRONOUS_SERVER", "Server type");
// Client config
DEFINE_int32(outstanding_rpcs_per_channel, 1, "Number of outstanding rpcs per channel");
DEFINE_int32(outstanding_rpcs_per_channel, 1,
"Number of outstanding rpcs per channel");
DEFINE_int32(client_channels, 1, "Number of client channels");
DEFINE_int32(payload_size, 1, "Payload size");
DEFINE_string(client_type, "SYNCHRONOUS_CLIENT", "Client type");
@ -76,7 +77,8 @@ int main(int argc, char **argv) {
ClientConfig client_config;
client_config.set_client_type(client_type);
client_config.set_enable_ssl(FLAGS_enable_ssl);
client_config.set_outstanding_rpcs_per_channel(FLAGS_outstanding_rpcs_per_channel);
client_config.set_outstanding_rpcs_per_channel(
FLAGS_outstanding_rpcs_per_channel);
client_config.set_client_channels(FLAGS_client_channels);
client_config.set_payload_size(FLAGS_payload_size);
@ -85,9 +87,9 @@ int main(int argc, char **argv) {
server_config.set_threads(FLAGS_server_threads);
server_config.set_enable_ssl(FLAGS_enable_ssl);
RunScenario(client_config, FLAGS_num_clients, server_config, FLAGS_num_servers);
RunScenario(client_config, FLAGS_num_clients, server_config,
FLAGS_num_servers);
grpc_shutdown();
return 0;
}

@ -85,7 +85,10 @@ class TestServiceImpl GRPC_FINAL : public TestService::Service {
class SynchronousServer GRPC_FINAL : public grpc::testing::Server {
public:
SynchronousServer(const ServerConfig& config, int port) : thread_pool_(config.threads()), impl_(MakeImpl(port)), timer_(new Timer) {}
SynchronousServer(const ServerConfig& config, int port)
: thread_pool_(config.threads()),
impl_(MakeImpl(port)),
timer_(new Timer) {}
ServerStats Mark() GRPC_OVERRIDE {
std::unique_ptr<Timer> timer(new Timer);
@ -120,7 +123,8 @@ class SynchronousServer GRPC_FINAL : public grpc::testing::Server {
std::unique_ptr<Timer> timer_;
};
std::unique_ptr<grpc::testing::Server> CreateSynchronousServer(const ServerConfig& config, int port) {
std::unique_ptr<grpc::testing::Server> CreateSynchronousServer(
const ServerConfig& config, int port) {
return std::unique_ptr<Server>(new SynchronousServer(config, port));
}

@ -46,7 +46,8 @@ class Server {
virtual ServerStats Mark() = 0;
};
std::unique_ptr<Server> CreateSynchronousServer(const ServerConfig& config, int port);
std::unique_ptr<Server> CreateSynchronousServer(const ServerConfig& config,
int port);
std::unique_ptr<Server> CreateAsyncServer(const ServerConfig& config, int port);
} // namespace testing

@ -77,16 +77,20 @@ namespace testing {
std::unique_ptr<Client> CreateClient(const ClientConfig& config) {
switch (config.client_type()) {
case ClientType::SYNCHRONOUS_CLIENT: return CreateSynchronousClient(config);
case ClientType::ASYNC_CLIENT: abort(); //return CreateAsyncClient(config);
case ClientType::SYNCHRONOUS_CLIENT:
return CreateSynchronousClient(config);
case ClientType::ASYNC_CLIENT:
abort(); // return CreateAsyncClient(config);
}
abort();
}
std::unique_ptr<Server> CreateServer(const ServerConfig& config) {
switch (config.server_type()) {
case ServerType::SYNCHRONOUS_SERVER: return CreateSynchronousServer(config, FLAGS_server_port);
case ServerType::ASYNC_SERVER: abort(); //return CreateAsyncServer(config, FLAGS_server_port);
case ServerType::SYNCHRONOUS_SERVER:
return CreateSynchronousServer(config, FLAGS_server_port);
case ServerType::ASYNC_SERVER:
abort(); // return CreateAsyncServer(config, FLAGS_server_port);
}
abort();
}
@ -95,7 +99,9 @@ class WorkerImpl final : public Worker::Service {
public:
WorkerImpl() : acquired_(false) {}
Status RunTest(ServerContext* ctx, ServerReaderWriter<ClientStatus, ClientArgs>* stream) GRPC_OVERRIDE {
Status RunTest(ServerContext* ctx,
ServerReaderWriter<ClientStatus, ClientArgs>* stream)
GRPC_OVERRIDE {
InstanceGuard g(this);
if (!g.Acquired()) {
return Status(RESOURCE_EXHAUSTED);
@ -127,7 +133,9 @@ class WorkerImpl final : public Worker::Service {
return Status::OK;
}
Status RunServer(ServerContext* ctx, ServerReaderWriter<ServerStatus, ServerArgs>* stream) GRPC_OVERRIDE {
Status RunServer(ServerContext* ctx,
ServerReaderWriter<ServerStatus, ServerArgs>* stream)
GRPC_OVERRIDE {
InstanceGuard g(this);
if (!g.Acquired()) {
return Status(RESOURCE_EXHAUSTED);
@ -163,8 +171,13 @@ class WorkerImpl final : public Worker::Service {
private:
class InstanceGuard {
public:
InstanceGuard(WorkerImpl* impl) : impl_(impl), acquired_(impl->TryAcquireInstance()) {}
~InstanceGuard() { if (acquired_) { impl_->ReleaseInstance(); } }
InstanceGuard(WorkerImpl* impl)
: impl_(impl), acquired_(impl->TryAcquireInstance()) {}
~InstanceGuard() {
if (acquired_) {
impl_->ReleaseInstance();
}
}
bool Acquired() const { return acquired_; }

Loading…
Cancel
Save