aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/cpp')
-rw-r--r--test/cpp/qps/async_streaming_ping_pong_test.cc10
-rw-r--r--test/cpp/qps/async_unary_ping_pong_test.cc11
-rw-r--r--test/cpp/qps/qps_driver.cc27
-rw-r--r--test/cpp/qps/qps_test.cc9
-rw-r--r--test/cpp/qps/report.cc50
-rw-r--r--test/cpp/qps/report.h77
-rw-r--r--test/cpp/qps/sync_streaming_ping_pong_test.cc10
-rw-r--r--test/cpp/qps/sync_unary_ping_pong_test.cc9
-rw-r--r--test/cpp/util/benchmark_config.cc69
-rw-r--r--test/cpp/util/benchmark_config.h57
10 files changed, 287 insertions, 42 deletions
diff --git a/test/cpp/qps/async_streaming_ping_pong_test.cc b/test/cpp/qps/async_streaming_ping_pong_test.cc
index d4871c0ba1..411df4d32a 100644
--- a/test/cpp/qps/async_streaming_ping_pong_test.cc
+++ b/test/cpp/qps/async_streaming_ping_pong_test.cc
@@ -31,12 +31,15 @@
*
*/
+#include <set>
+
#include <grpc/support/log.h>
#include <signal.h>
#include "test/cpp/qps/driver.h"
#include "test/cpp/qps/report.h"
+#include "test/cpp/util/benchmark_config.h"
namespace grpc {
namespace testing {
@@ -64,16 +67,17 @@ static void RunAsyncStreamingPingPong() {
const auto result =
RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2);
- ReportQPS(*result);
- ReportLatency(*result);
+ GetReporter()->ReportQPS(*result);
+ GetReporter()->ReportLatency(*result);
}
} // namespace testing
} // namespace grpc
int main(int argc, char** argv) {
+ grpc::testing::InitBenchmark(&argc, &argv, true);
+
signal(SIGPIPE, SIG_IGN);
grpc::testing::RunAsyncStreamingPingPong();
-
return 0;
}
diff --git a/test/cpp/qps/async_unary_ping_pong_test.cc b/test/cpp/qps/async_unary_ping_pong_test.cc
index 35f188c986..eda31b5744 100644
--- a/test/cpp/qps/async_unary_ping_pong_test.cc
+++ b/test/cpp/qps/async_unary_ping_pong_test.cc
@@ -31,12 +31,15 @@
*
*/
+#include <set>
+
#include <grpc/support/log.h>
#include <signal.h>
#include "test/cpp/qps/driver.h"
#include "test/cpp/qps/report.h"
+#include "test/cpp/util/benchmark_config.h"
namespace grpc {
namespace testing {
@@ -64,16 +67,16 @@ static void RunAsyncUnaryPingPong() {
const auto result =
RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2);
- ReportQPS(*result);
- ReportLatency(*result);
+ GetReporter()->ReportQPS(*result);
+ GetReporter()->ReportLatency(*result);
}
-
} // namespace testing
} // namespace grpc
int main(int argc, char** argv) {
+ grpc::testing::InitBenchmark(&argc, &argv, true);
signal(SIGPIPE, SIG_IGN);
- grpc::testing::RunAsyncUnaryPingPong();
+ grpc::testing::RunAsyncUnaryPingPong();
return 0;
}
diff --git a/test/cpp/qps/qps_driver.cc b/test/cpp/qps/qps_driver.cc
index 008830de4e..281e2e8119 100644
--- a/test/cpp/qps/qps_driver.cc
+++ b/test/cpp/qps/qps_driver.cc
@@ -31,12 +31,15 @@
*
*/
+#include <memory>
+#include <set>
+
#include <gflags/gflags.h>
#include <grpc/support/log.h>
#include "test/cpp/qps/driver.h"
#include "test/cpp/qps/report.h"
-#include "test/cpp/util/test_config.h"
+#include "test/cpp/util/benchmark_config.h"
DEFINE_int32(num_clients, 1, "Number of client binaries");
DEFINE_int32(num_servers, 1, "Number of server binaries");
@@ -68,9 +71,10 @@ using grpc::testing::ServerType;
using grpc::testing::RpcType;
using grpc::testing::ResourceUsage;
-int main(int argc, char** argv) {
- grpc::testing::InitTest(&argc, &argv, true);
+namespace grpc {
+namespace testing {
+static void QpsDriver() {
RpcType rpc_type;
GPR_ASSERT(RpcType_Parse(FLAGS_rpc_type, &rpc_type));
@@ -107,9 +111,20 @@ int main(int argc, char** argv) {
client_config, FLAGS_num_clients, server_config, FLAGS_num_servers,
FLAGS_warmup_seconds, FLAGS_benchmark_seconds, FLAGS_local_workers);
- ReportQPSPerCore(*result, server_config);
- ReportLatency(*result);
- ReportTimes(*result);
+ GetReporter()->ReportQPS(*result);
+ GetReporter()->ReportQPSPerCore(*result, server_config);
+ GetReporter()->ReportLatency(*result);
+ GetReporter()->ReportTimes(*result);
+}
+
+} // namespace testing
+} // namespace grpc
+
+int main(int argc, char** argv) {
+ grpc::testing::InitBenchmark(&argc, &argv, true);
+
+ signal(SIGPIPE, SIG_IGN);
+ grpc::testing::QpsDriver();
return 0;
}
diff --git a/test/cpp/qps/qps_test.cc b/test/cpp/qps/qps_test.cc
index 9a81d0fc90..63a37ae07e 100644
--- a/test/cpp/qps/qps_test.cc
+++ b/test/cpp/qps/qps_test.cc
@@ -31,12 +31,15 @@
*
*/
+#include <set>
+
#include <grpc/support/log.h>
#include <signal.h>
#include "test/cpp/qps/driver.h"
#include "test/cpp/qps/report.h"
+#include "test/cpp/util/benchmark_config.h"
namespace grpc {
namespace testing {
@@ -64,14 +67,16 @@ static void RunQPS() {
const auto result =
RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2);
- ReportQPSPerCore(*result, server_config);
- ReportLatency(*result);
+ GetReporter()->ReportQPSPerCore(*result, server_config);
+ GetReporter()->ReportLatency(*result);
}
} // namespace testing
} // namespace grpc
int main(int argc, char** argv) {
+ grpc::testing::InitBenchmark(&argc, &argv, true);
+
signal(SIGPIPE, SIG_IGN);
grpc::testing::RunQPS();
diff --git a/test/cpp/qps/report.cc b/test/cpp/qps/report.cc
index 3115ff3bfb..e116175e3b 100644
--- a/test/cpp/qps/report.cc
+++ b/test/cpp/qps/report.cc
@@ -39,27 +39,55 @@
namespace grpc {
namespace testing {
-// QPS: XXX
-void ReportQPS(const ScenarioResult& result) {
+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 {
gpr_log(GPR_INFO, "QPS: %.1f",
result.latencies.Count() /
average(result.client_resources,
[](ResourceUsage u) { return u.wall_time; }));
}
-// QPS: XXX (YYY/server core)
-void ReportQPSPerCore(const ScenarioResult& result,
- const ServerConfig& server_config) {
- auto qps = result.latencies.Count() /
- average(result.client_resources,
- [](ResourceUsage u) { return u.wall_time; });
+void GprLogReporter::ReportQPSPerCore(const ScenarioResult& result,
+ const ServerConfig& server_config) const {
+ auto qps =
+ result.latencies.Count() /
+ average(result.client_resources,
+ [](ResourceUsage u) { return u.wall_time; });
gpr_log(GPR_INFO, "QPS: %.1f (%.1f/server core)", qps,
qps / server_config.threads());
}
-// Latency (50/90/95/99/99.9%-ile): AA/BB/CC/DD/EE us
-void ReportLatency(const ScenarioResult& result) {
+void GprLogReporter::ReportLatency(const ScenarioResult& result) const {
gpr_log(GPR_INFO,
"Latencies (50/90/95/99/99.9%%-ile): %.1f/%.1f/%.1f/%.1f/%.1f us",
result.latencies.Percentile(50) / 1000,
@@ -69,7 +97,7 @@ void ReportLatency(const ScenarioResult& result) {
result.latencies.Percentile(99.9) / 1000);
}
-void ReportTimes(const ScenarioResult& result) {
+void GprLogReporter::ReportTimes(const ScenarioResult& result) const {
gpr_log(GPR_INFO, "Server system time: %.2f%%",
100.0 * sum(result.server_resources,
[](ResourceUsage u) { return u.system_time; }) /
diff --git a/test/cpp/qps/report.h b/test/cpp/qps/report.h
index 343e426ca4..630275ecda 100644
--- a/test/cpp/qps/report.h
+++ b/test/cpp/qps/report.h
@@ -34,22 +34,77 @@
#ifndef TEST_QPS_REPORT_H
#define TEST_QPS_REPORT_H
+#include <memory>
+#include <set>
+#include <vector>
+#include <grpc++/config.h>
+
#include "test/cpp/qps/driver.h"
+#include "test/cpp/qps/qpstest.grpc.pb.h"
namespace grpc {
namespace testing {
-// QPS: XXX
-void ReportQPS(const ScenarioResult& result);
-// QPS: XXX (YYY/server core)
-void ReportQPSPerCore(const ScenarioResult& result, const ServerConfig& config);
-// Latency (50/90/95/99/99.9%-ile): AA/BB/CC/DD/EE us
-void ReportLatency(const ScenarioResult& result);
-// Server system time: XX%
-// Server user time: XX%
-// Client system time: XX%
-// Client user time: XX%
-void ReportTimes(const ScenarioResult& result);
+/** Interface for all reporters. */
+class Reporter {
+ public:
+ /** Construct a reporter with the given \a name. */
+ Reporter(const string& name) : name_(name) {}
+
+ virtual ~Reporter() {}
+
+ /** Returns this reporter's name.
+ *
+ * Names are constants, set at construction time. */
+ string name() const { return name_; }
+
+ /** Reports QPS for the given \a result. */
+ virtual void ReportQPS(const ScenarioResult& result) const = 0;
+
+ /** Reports QPS per core as (YYY/server core). */
+ virtual void ReportQPSPerCore(const ScenarioResult& result,
+ const ServerConfig& config) const = 0;
+
+ /** Reports latencies for the 50, 90, 95, 99 and 99.9 percentiles, in ms. */
+ virtual void ReportLatency(const ScenarioResult& result) const = 0;
+
+ /** Reports system and user time for client and server systems. */
+ virtual void ReportTimes(const ScenarioResult& result) const = 0;
+
+ private:
+ 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). */
+class GprLogReporter : public Reporter {
+ public:
+ GprLogReporter(const string& name) : Reporter(name) {}
+
+ private:
+ 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;
+};
} // namespace testing
} // namespace grpc
diff --git a/test/cpp/qps/sync_streaming_ping_pong_test.cc b/test/cpp/qps/sync_streaming_ping_pong_test.cc
index 218306846b..d53905a779 100644
--- a/test/cpp/qps/sync_streaming_ping_pong_test.cc
+++ b/test/cpp/qps/sync_streaming_ping_pong_test.cc
@@ -31,12 +31,15 @@
*
*/
+#include <set>
+
#include <grpc/support/log.h>
#include <signal.h>
#include "test/cpp/qps/driver.h"
#include "test/cpp/qps/report.h"
+#include "test/cpp/util/benchmark_config.h"
namespace grpc {
namespace testing {
@@ -63,14 +66,15 @@ static void RunSynchronousStreamingPingPong() {
const auto result =
RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2);
- ReportQPS(*result);
- ReportLatency(*result);
+ GetReporter()->ReportQPS(*result);
+ GetReporter()->ReportLatency(*result);
}
-
} // namespace testing
} // namespace grpc
int main(int argc, char** argv) {
+ grpc::testing::InitBenchmark(&argc, &argv, true);
+
signal(SIGPIPE, SIG_IGN);
grpc::testing::RunSynchronousStreamingPingPong();
diff --git a/test/cpp/qps/sync_unary_ping_pong_test.cc b/test/cpp/qps/sync_unary_ping_pong_test.cc
index 137ef79f2f..d276d13a43 100644
--- a/test/cpp/qps/sync_unary_ping_pong_test.cc
+++ b/test/cpp/qps/sync_unary_ping_pong_test.cc
@@ -31,12 +31,15 @@
*
*/
+#include <set>
+
#include <grpc/support/log.h>
#include <signal.h>
#include "test/cpp/qps/driver.h"
#include "test/cpp/qps/report.h"
+#include "test/cpp/util/benchmark_config.h"
namespace grpc {
namespace testing {
@@ -63,14 +66,16 @@ static void RunSynchronousUnaryPingPong() {
const auto result =
RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2);
- ReportQPS(*result);
- ReportLatency(*result);
+ GetReporter()->ReportQPS(*result);
+ GetReporter()->ReportLatency(*result);
}
} // namespace testing
} // namespace grpc
int main(int argc, char** argv) {
+ grpc::testing::InitBenchmark(&argc, &argv, true);
+
signal(SIGPIPE, SIG_IGN);
grpc::testing::RunSynchronousUnaryPingPong();
diff --git a/test/cpp/util/benchmark_config.cc b/test/cpp/util/benchmark_config.cc
new file mode 100644
index 0000000000..5b3c1daf5d
--- /dev/null
+++ b/test/cpp/util/benchmark_config.cc
@@ -0,0 +1,69 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <gflags/gflags.h>
+#include "test/cpp/util/benchmark_config.h"
+
+DEFINE_bool(enable_log_reporter, true,
+ "Enable reporting of benchmark results through GprLog");
+
+// In some distros, gflags is in the namespace google, and in some others,
+// in gflags. This hack is enabling us to find both.
+namespace google {}
+namespace gflags {}
+using namespace google;
+using namespace gflags;
+
+namespace grpc {
+namespace testing {
+
+void InitBenchmark(int* argc, char*** argv, bool remove_flags) {
+ ParseCommandLineFlags(argc, argv, remove_flags);
+}
+
+static std::shared_ptr<Reporter> InitBenchmarkReporters() {
+ auto* composite_reporter = new CompositeReporter;
+ if (FLAGS_enable_log_reporter) {
+ composite_reporter->add(
+ std::unique_ptr<Reporter>(new GprLogReporter("LogReporter")));
+ }
+ return std::shared_ptr<Reporter>(composite_reporter);
+}
+
+std::shared_ptr<Reporter> GetReporter() {
+ static std::shared_ptr<Reporter> reporter(InitBenchmarkReporters());
+ return reporter;
+}
+
+} // namespace testing
+} // namespace grpc
diff --git a/test/cpp/util/benchmark_config.h b/test/cpp/util/benchmark_config.h
new file mode 100644
index 0000000000..6b308a15ff
--- /dev/null
+++ b/test/cpp/util/benchmark_config.h
@@ -0,0 +1,57 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPC_TEST_CPP_UTIL_BENCHMARK_CONFIG_H
+#define GRPC_TEST_CPP_UTIL_BENCHMARK_CONFIG_H
+
+#include <memory>
+#include <vector>
+
+#include "test/cpp/qps/report.h"
+
+namespace grpc {
+namespace testing {
+
+void InitBenchmark(int* argc, char*** argv, bool remove_flags);
+
+/** Returns the benchmark Reporter instance.
+ *
+ * The returned instance will take care of generating reports for all the actual
+ * reporters configured via the "enable_*_reporter" command line flags (see
+ * benchmark_config.cc). */
+std::shared_ptr<Reporter> GetReporter();
+
+} // namespace testing
+} // namespace grpc
+
+#endif // GRPC_TEST_CPP_UTIL_BENCHMARK_CONFIG_H