MCPcopy Create free account
hub / github.com/apache/brpc / main

Function main

example/http_c++/benchmark_http.cpp:75–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75int main(int argc, char* argv[]) {
76 // Parse gflags. We recommend you to use gflags as well.
77 GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
78
79 // A Channel represents a communication line to a Server. Notice that
80 // Channel is thread-safe and can be shared by all threads in your program.
81 brpc::Channel channel;
82 brpc::ChannelOptions options;
83 options.protocol = FLAGS_protocol;
84 options.connection_type = FLAGS_connection_type;
85
86 // Initialize the channel, NULL means using default options.
87 // options, see `brpc/channel.h'.
88 if (channel.Init(FLAGS_url.c_str(), FLAGS_load_balancer.c_str(), &options) != 0) {
89 LOG(ERROR) << "Fail to initialize channel";
90 return -1;
91 }
92
93 std::vector<bthread_t> bids;
94 std::vector<pthread_t> pids;
95 if (!FLAGS_use_bthread) {
96 pids.resize(FLAGS_thread_num);
97 for (int i = 0; i < FLAGS_thread_num; ++i) {
98 if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
99 LOG(ERROR) << "Fail to create pthread";
100 return -1;
101 }
102 }
103 } else {
104 bids.resize(FLAGS_thread_num);
105 for (int i = 0; i < FLAGS_thread_num; ++i) {
106 if (bthread_start_background(
107 &bids[i], NULL, sender, &channel) != 0) {
108 LOG(ERROR) << "Fail to create bthread";
109 return -1;
110 }
111 }
112 }
113
114 if (FLAGS_dummy_port >= 0) {
115 brpc::StartDummyServerAt(FLAGS_dummy_port);
116 }
117
118 while (!brpc::IsAskedToQuit()) {
119 sleep(1);
120 LOG(INFO) << "Sending " << FLAGS_protocol << " requests at qps="
121 << g_latency_recorder.qps(1)
122 << " latency=" << g_latency_recorder.latency(1);
123 }
124
125 LOG(INFO) << "benchmark_http is going to quit";
126 for (int i = 0; i < FLAGS_thread_num; ++i) {
127 if (!FLAGS_use_bthread) {
128 pthread_join(pids[i], NULL);
129 } else {
130 bthread_join(bids[i], NULL);
131 }
132 }

Callers

nothing calls this directly

Calls 9

bthread_start_backgroundFunction · 0.85
StartDummyServerAtFunction · 0.85
IsAskedToQuitFunction · 0.85
bthread_joinFunction · 0.85
latencyMethod · 0.80
InitMethod · 0.45
c_strMethod · 0.45
resizeMethod · 0.45
qpsMethod · 0.45

Tested by

no test coverage detected