Improvements to reporting mechanism based on comments.

Turned the reporter into a composite, much cleaner arch.
pull/1649/head
David Garcia Quintas 10 years ago
parent 226beffea1
commit a6b559a76a
  1. 12
      test/cpp/qps/async_streaming_ping_pong_test.cc
  2. 12
      test/cpp/qps/async_unary_ping_pong_test.cc
  3. 16
      test/cpp/qps/qps_driver.cc
  4. 11
      test/cpp/qps/qps_test.cc
  5. 30
      test/cpp/qps/report.cc
  6. 20
      test/cpp/qps/report.h
  7. 12
      test/cpp/qps/sync_streaming_ping_pong_test.cc
  8. 12
      test/cpp/qps/sync_unary_ping_pong_test.cc
  9. 14
      test/cpp/util/benchmark_config.cc
  10. 8
      test/cpp/util/benchmark_config.h

@ -47,8 +47,7 @@ namespace testing {
static const int WARMUP = 5; static const int WARMUP = 5;
static const int BENCHMARK = 10; static const int BENCHMARK = 10;
static void RunAsyncStreamingPingPong( static void RunAsyncStreamingPingPong() {
const std::vector<std::unique_ptr<Reporter> >& reporters) {
gpr_log(GPR_INFO, "Running Async Streaming Ping Pong"); gpr_log(GPR_INFO, "Running Async Streaming Ping Pong");
ClientConfig client_config; ClientConfig client_config;
@ -68,10 +67,8 @@ static void RunAsyncStreamingPingPong(
const auto result = const auto result =
RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2);
for (const auto& reporter : reporters) { GetReporter()->ReportQPS(result);
reporter->ReportQPS(result); GetReporter()->ReportLatency(result);
reporter->ReportLatency(result);
}
} }
} // namespace testing } // namespace testing
@ -79,9 +76,8 @@ static void RunAsyncStreamingPingPong(
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc::testing::InitBenchmark(&argc, &argv, true); grpc::testing::InitBenchmark(&argc, &argv, true);
const auto& reporters = grpc::testing::InitBenchmarkReporters();
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
grpc::testing::RunAsyncStreamingPingPong(reporters); grpc::testing::RunAsyncStreamingPingPong();
return 0; return 0;
} }

@ -47,8 +47,7 @@ namespace testing {
static const int WARMUP = 5; static const int WARMUP = 5;
static const int BENCHMARK = 10; static const int BENCHMARK = 10;
static void RunAsyncUnaryPingPong( static void RunAsyncUnaryPingPong() {
const std::vector<std::unique_ptr<Reporter> >& reporters) {
gpr_log(GPR_INFO, "Running Async Unary Ping Pong"); gpr_log(GPR_INFO, "Running Async Unary Ping Pong");
ClientConfig client_config; ClientConfig client_config;
@ -68,19 +67,16 @@ static void RunAsyncUnaryPingPong(
const auto result = const auto result =
RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2);
for (const auto& reporter : reporters) { GetReporter()->ReportQPS(result);
reporter->ReportQPS(result); GetReporter()->ReportLatency(result);
reporter->ReportLatency(result);
}
} }
} // namespace testing } // namespace testing
} // namespace grpc } // namespace grpc
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc::testing::InitBenchmark(&argc, &argv, true); grpc::testing::InitBenchmark(&argc, &argv, true);
const auto& reporters = grpc::testing::InitBenchmarkReporters();
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
grpc::testing::RunAsyncUnaryPingPong(reporters); grpc::testing::RunAsyncUnaryPingPong();
return 0; return 0;
} }

@ -74,8 +74,7 @@ using grpc::testing::ResourceUsage;
namespace grpc { namespace grpc {
namespace testing { namespace testing {
static void QpsDriver( static void QpsDriver() {
const std::vector<std::unique_ptr<Reporter> >& reporters) {
RpcType rpc_type; RpcType rpc_type;
GPR_ASSERT(RpcType_Parse(FLAGS_rpc_type, &rpc_type)); GPR_ASSERT(RpcType_Parse(FLAGS_rpc_type, &rpc_type));
@ -112,12 +111,10 @@ static void QpsDriver(
client_config, FLAGS_num_clients, server_config, FLAGS_num_servers, client_config, FLAGS_num_clients, server_config, FLAGS_num_servers,
FLAGS_warmup_seconds, FLAGS_benchmark_seconds, FLAGS_local_workers); FLAGS_warmup_seconds, FLAGS_benchmark_seconds, FLAGS_local_workers);
for (const auto& reporter : reporters) { GetReporter()->ReportQPS(result);
reporter->ReportQPS(result); GetReporter()->ReportQPSPerCore(result, server_config);
reporter->ReportQPSPerCore(result, server_config); GetReporter()->ReportLatency(result);
reporter->ReportLatency(result); GetReporter()->ReportTimes(result);
reporter->ReportTimes(result);
}
} }
} // namespace testing } // namespace testing
@ -125,10 +122,9 @@ static void QpsDriver(
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc::testing::InitBenchmark(&argc, &argv, true); grpc::testing::InitBenchmark(&argc, &argv, true);
const auto& reporters = grpc::testing::InitBenchmarkReporters();
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
grpc::testing::QpsDriver(reporters); grpc::testing::QpsDriver();
return 0; return 0;
} }

@ -47,7 +47,7 @@ namespace testing {
static const int WARMUP = 5; static const int WARMUP = 5;
static const int BENCHMARK = 10; static const int BENCHMARK = 10;
static void RunQPS(const std::vector<std::unique_ptr<Reporter> >& reporters) { static void RunQPS() {
gpr_log(GPR_INFO, "Running QPS test"); gpr_log(GPR_INFO, "Running QPS test");
ClientConfig client_config; ClientConfig client_config;
@ -67,10 +67,8 @@ static void RunQPS(const std::vector<std::unique_ptr<Reporter> >& reporters) {
const auto result = const auto result =
RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2);
for (const auto& reporter : reporters) { GetReporter()->ReportQPSPerCore(result, server_config);
reporter->ReportQPSPerCore(result, server_config); GetReporter()->ReportLatency(result);
reporter->ReportLatency(result);
}
} }
} // namespace testing } // namespace testing
@ -78,10 +76,9 @@ static void RunQPS(const std::vector<std::unique_ptr<Reporter> >& reporters) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc::testing::InitBenchmark(&argc, &argv, true); grpc::testing::InitBenchmark(&argc, &argv, true);
const auto& reporters = grpc::testing::InitBenchmarkReporters();
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
grpc::testing::RunQPS(reporters); grpc::testing::RunQPS();
return 0; return 0;
} }

@ -39,6 +39,36 @@
namespace grpc { namespace grpc {
namespace testing { namespace testing {
void CompositeReporter::add(std::unique_ptr<Reporter> reporter) {
reporters_.emplace_back(std::move(reporter));
}
void CompositeReporter::ReportQPS(const ScenarioResult& result) const {
for (size_t i = 0; i < reporters_.size(); ++i) {
reporters_[i]->ReportQPS(result);
}
}
void CompositeReporter::ReportQPSPerCore(const ScenarioResult& result,
const ServerConfig& config) const {
for (size_t i = 0; i < reporters_.size(); ++i) {
reporters_[i]->ReportQPSPerCore(result, config);
}
}
void CompositeReporter::ReportLatency(const ScenarioResult& result) const {
for (size_t i = 0; i < reporters_.size(); ++i) {
reporters_[i]->ReportLatency(result);
}
}
void CompositeReporter::ReportTimes(const ScenarioResult& result) const {
for (size_t i = 0; i < reporters_.size(); ++i) {
reporters_[i]->ReportTimes(result);
}
}
void GprLogReporter::ReportQPS(const ScenarioResult& result) const { void GprLogReporter::ReportQPS(const ScenarioResult& result) const {
gpr_log(GPR_INFO, "QPS: %.1f", gpr_log(GPR_INFO, "QPS: %.1f",
result.latencies.Count() / result.latencies.Count() /

@ -51,6 +51,8 @@ class Reporter {
/** Construct a reporter with the given \a name. */ /** Construct a reporter with the given \a name. */
Reporter(const string& name) : name_(name) {} Reporter(const string& name) : name_(name) {}
virtual ~Reporter() {}
/** Returns this reporter's name. /** Returns this reporter's name.
* *
* Names are constants, set at construction time. */ * Names are constants, set at construction time. */
@ -73,6 +75,24 @@ class Reporter {
const string name_; const string name_;
}; };
/** A composite for all reporters to be considered. */
class CompositeReporter : public Reporter {
public:
CompositeReporter() : Reporter("CompositeReporter") {}
/** Adds a \a reporter to the composite. */
void add(std::unique_ptr<Reporter> reporter);
void ReportQPS(const ScenarioResult& result) const GRPC_OVERRIDE;
void ReportQPSPerCore(const ScenarioResult& result,
const ServerConfig& config) const GRPC_OVERRIDE;
void ReportLatency(const ScenarioResult& result) const GRPC_OVERRIDE;
void ReportTimes(const ScenarioResult& result) const GRPC_OVERRIDE;
private:
std::vector<std::unique_ptr<Reporter> > reporters_;
};
/** Reporter to gpr_log(GPR_INFO). */ /** Reporter to gpr_log(GPR_INFO). */
class GprLogReporter : public Reporter { class GprLogReporter : public Reporter {
public: public:

@ -47,8 +47,7 @@ namespace testing {
static const int WARMUP = 5; static const int WARMUP = 5;
static const int BENCHMARK = 10; static const int BENCHMARK = 10;
static void RunSynchronousStreamingPingPong( static void RunSynchronousStreamingPingPong() {
const std::vector<std::unique_ptr<Reporter> >& reporters) {
gpr_log(GPR_INFO, "Running Synchronous Streaming Ping Pong"); gpr_log(GPR_INFO, "Running Synchronous Streaming Ping Pong");
ClientConfig client_config; ClientConfig client_config;
@ -67,20 +66,17 @@ static void RunSynchronousStreamingPingPong(
const auto result = const auto result =
RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2);
for (const auto& reporter : reporters) { GetReporter()->ReportQPS(result);
reporter->ReportQPS(result); GetReporter()->ReportLatency(result);
reporter->ReportLatency(result);
}
} }
} // namespace testing } // namespace testing
} // namespace grpc } // namespace grpc
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc::testing::InitBenchmark(&argc, &argv, true); grpc::testing::InitBenchmark(&argc, &argv, true);
const auto& reporters = grpc::testing::InitBenchmarkReporters();
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
grpc::testing::RunSynchronousStreamingPingPong(reporters); grpc::testing::RunSynchronousStreamingPingPong();
return 0; return 0;
} }

@ -47,8 +47,7 @@ namespace testing {
static const int WARMUP = 5; static const int WARMUP = 5;
static const int BENCHMARK = 10; static const int BENCHMARK = 10;
static void RunSynchronousUnaryPingPong( static void RunSynchronousUnaryPingPong() {
const std::vector<std::unique_ptr<Reporter> >& reporters) {
gpr_log(GPR_INFO, "Running Synchronous Unary Ping Pong"); gpr_log(GPR_INFO, "Running Synchronous Unary Ping Pong");
ClientConfig client_config; ClientConfig client_config;
@ -67,10 +66,8 @@ static void RunSynchronousUnaryPingPong(
const auto result = const auto result =
RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2);
for (const auto& reporter : reporters) { GetReporter()->ReportQPS(result);
reporter->ReportQPS(result); GetReporter()->ReportLatency(result);
reporter->ReportLatency(result);
}
} }
} // namespace testing } // namespace testing
@ -78,10 +75,9 @@ static void RunSynchronousUnaryPingPong(
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc::testing::InitBenchmark(&argc, &argv, true); grpc::testing::InitBenchmark(&argc, &argv, true);
const auto& reporters = grpc::testing::InitBenchmarkReporters();
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
grpc::testing::RunSynchronousUnaryPingPong(reporters); grpc::testing::RunSynchronousUnaryPingPong();
return 0; return 0;
} }

@ -51,12 +51,18 @@ void InitBenchmark(int* argc, char*** argv, bool remove_flags) {
ParseCommandLineFlags(argc, argv, remove_flags); ParseCommandLineFlags(argc, argv, remove_flags);
} }
std::vector<std::unique_ptr<Reporter> > InitBenchmarkReporters() { static std::shared_ptr<Reporter> InitBenchmarkReporters() {
std::vector<std::unique_ptr<Reporter> > reporters; auto* composite_reporter = new CompositeReporter;
if (FLAGS_enable_log_reporter) { if (FLAGS_enable_log_reporter) {
reporters.emplace_back(new GprLogReporter("LogReporter")); composite_reporter->add(
std::unique_ptr<Reporter>(new GprLogReporter("LogReporter")));
} }
return reporters; return std::shared_ptr<Reporter>(composite_reporter);
}
const std::shared_ptr<Reporter>& GetReporter() {
static std::shared_ptr<Reporter> reporter(InitBenchmarkReporters());
return reporter;
} }
} // namespace testing } // namespace testing

@ -43,7 +43,13 @@ namespace grpc {
namespace testing { namespace testing {
void InitBenchmark(int* argc, char*** argv, bool remove_flags); void InitBenchmark(int* argc, char*** argv, bool remove_flags);
std::vector<std::unique_ptr<Reporter> > InitBenchmarkReporters();
/** Returns the benchmark Reporter instance.
*
* The returned instane will take care of generating reports for all the actual
* reporters configured via the "enable_*_reporter" command line flags (see
* benchmark_config.cc). */
const std::shared_ptr<Reporter>& GetReporter();
} // namespace testing } // namespace testing
} // namespace grpc } // namespace grpc

Loading…
Cancel
Save