blob: d7642f0e1ee7037efdaf366a1f0e5af029548f69 [file] [log] [blame]
Craig Tiller0bda0b32016-03-03 12:51:53 -08001/*
2 *
3 * Copyright 2015-2016, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34#include <memory>
35#include <set>
36
Craig Tiller3ab2fe02016-04-11 20:11:18 -070037#include <grpc++/support/config_protobuf.h>
Craig Tiller0bda0b32016-03-03 12:51:53 -080038
39#include <gflags/gflags.h>
40#include <grpc/support/log.h>
41
42#include "test/cpp/qps/driver.h"
Craig Tiller3ab2fe02016-04-11 20:11:18 -070043#include "test/cpp/qps/parse_json.h"
Craig Tiller0bda0b32016-03-03 12:51:53 -080044#include "test/cpp/qps/report.h"
45#include "test/cpp/util/benchmark_config.h"
46
47DEFINE_string(scenarios_file, "",
48 "JSON file containing an array of Scenario objects");
49DEFINE_string(scenarios_json, "",
50 "JSON string containing an array of Scenario objects");
vjpai29089c72016-04-20 12:38:16 -070051DEFINE_bool(quit, false, "Quit the workers");
Craig Tiller0bda0b32016-03-03 12:51:53 -080052
53namespace grpc {
54namespace testing {
55
56static void QpsDriver() {
57 grpc::string json;
58
vjpai29089c72016-04-20 12:38:16 -070059 bool scfile = (FLAGS_scenarios_file != "");
60 bool scjson = (FLAGS_scenarios_json != "");
61 if ((!scfile && !scjson && !FLAGS_quit) ||
Vijay Pai89094282016-04-20 14:21:30 -070062 (scfile && (scjson || FLAGS_quit)) || (scjson && FLAGS_quit)) {
63 gpr_log(GPR_ERROR,
64 "Exactly one of --scenarios_file, --scenarios_json, "
65 "or --quit must be set");
vjpai29089c72016-04-20 12:38:16 -070066 abort();
67 }
68
69 if (scfile) {
Craig Tiller0bda0b32016-03-03 12:51:53 -080070 // Read the json data from disk
71 FILE *json_file = fopen(FLAGS_scenarios_file.c_str(), "r");
72 GPR_ASSERT(json_file != NULL);
73 fseek(json_file, 0, SEEK_END);
74 long len = ftell(json_file);
75 char *data = new char[len];
76 fseek(json_file, 0, SEEK_SET);
77 GPR_ASSERT(len == (long)fread(data, 1, len, json_file));
78 fclose(json_file);
79 json = grpc::string(data, data + len);
80 delete[] data;
vjpai29089c72016-04-20 12:38:16 -070081 } else if (scjson) {
Craig Tiller0bda0b32016-03-03 12:51:53 -080082 json = FLAGS_scenarios_json.c_str();
vjpai29089c72016-04-20 12:38:16 -070083 } else if (FLAGS_quit) {
84 RunQuit();
85 return;
Craig Tiller0bda0b32016-03-03 12:51:53 -080086 }
87
88 // Parse into an array of scenarios
89 Scenarios scenarios;
Craig Tiller8f98e0b2016-04-11 23:39:12 -070090 ParseJson(json.c_str(), "grpc.testing.Scenarios", &scenarios);
Craig Tiller0bda0b32016-03-03 12:51:53 -080091
Vijay Paidfdfe262016-04-21 11:38:31 -070092 // Make sure that there is at least some valid scenario here
93 GPR_ASSERT(scenarios.scenarios_size() > 0);
94
Craig Tiller0bda0b32016-03-03 12:51:53 -080095 for (int i = 0; i < scenarios.scenarios_size(); i++) {
96 const Scenario &scenario = scenarios.scenarios(i);
97 std::cerr << "RUNNING SCENARIO: " << scenario.name() << "\n";
Jan Tattermusch969ffaf2016-04-14 12:59:42 -070098 auto result =
Craig Tiller0bda0b32016-03-03 12:51:53 -080099 RunScenario(scenario.client_config(), scenario.num_clients(),
100 scenario.server_config(), scenario.num_servers(),
101 scenario.warmup_seconds(), scenario.benchmark_seconds(),
102 scenario.spawn_local_worker_count());
103
Jan Tattermusch969ffaf2016-04-14 12:59:42 -0700104 // Amend the result with scenario config. Eventually we should adjust
105 // RunScenario contract so we don't need to touch the result here.
106 result->mutable_scenario()->CopyFrom(scenario);
107
Craig Tiller0bda0b32016-03-03 12:51:53 -0800108 GetReporter()->ReportQPS(*result);
109 GetReporter()->ReportQPSPerCore(*result);
110 GetReporter()->ReportLatency(*result);
111 GetReporter()->ReportTimes(*result);
112 }
113}
114
115} // namespace testing
116} // namespace grpc
117
118int main(int argc, char **argv) {
119 grpc::testing::InitBenchmark(&argc, &argv, true);
120
121 grpc::testing::QpsDriver();
122
123 return 0;
124}