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

Function main

example/dynamic_partition_echo_c++/client.cpp:123–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121
122
123int main(int argc, char* argv[]) {
124 // Parse gflags. We recommend you to use gflags as well.
125 GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
126
127 // A Channel represents a communication line to a Server. Notice that
128 // Channel is thread-safe and can be shared by all threads in your program.
129 brpc::DynamicPartitionChannel channel;
130
131 brpc::PartitionChannelOptions options;
132 options.protocol = FLAGS_protocol;
133 options.connection_type = FLAGS_connection_type;
134 options.succeed_without_server = true;
135 options.fail_limit = 1;
136 options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;
137 options.max_retry = FLAGS_max_retry;
138
139 if (channel.Init(new MyPartitionParser(),
140 FLAGS_server.c_str(), FLAGS_load_balancer.c_str(),
141 &options) != 0) {
142 LOG(ERROR) << "Fail to init channel";
143 return -1;
144 }
145 if (FLAGS_attachment_size > 0) {
146 g_attachment.resize(FLAGS_attachment_size, 'a');
147 }
148 if (FLAGS_request_size <= 0) {
149 LOG(ERROR) << "Bad request_size=" << FLAGS_request_size;
150 return -1;
151 }
152 g_request.resize(FLAGS_request_size, 'r');
153
154 std::vector<bthread_t> bids;
155 std::vector<pthread_t> pids;
156 if (!FLAGS_use_bthread) {
157 pids.resize(FLAGS_thread_num);
158 for (int i = 0; i < FLAGS_thread_num; ++i) {
159 if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
160 LOG(ERROR) << "Fail to create pthread";
161 return -1;
162 }
163 }
164 } else {
165 bids.resize(FLAGS_thread_num);
166 for (int i = 0; i < FLAGS_thread_num; ++i) {
167 if (bthread_start_background(
168 &bids[i], NULL, sender, &channel) != 0) {
169 LOG(ERROR) << "Fail to create bthread";
170 return -1;
171 }
172 }
173 }
174
175 int64_t last_counter = 0;
176 int64_t last_latency_sum = 0;
177 std::vector<size_t> last_nsuccess(FLAGS_thread_num);
178 while (!brpc::IsAskedToQuit()) {
179 sleep(1);
180 int64_t latency_sum = 0;

Callers

nothing calls this directly

Calls 9

bthread_start_backgroundFunction · 0.85
IsAskedToQuitFunction · 0.85
pthread_mutex_lockFunction · 0.85
pthread_mutex_unlockFunction · 0.85
bthread_joinFunction · 0.85
InitMethod · 0.45
c_strMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected