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

Function access_thread

tools/parallel_http/parallel_http.cpp:68–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68void* access_thread(void* void_args) {
69 AccessThreadArgs* args = (AccessThreadArgs*)void_args;
70 brpc::ChannelOptions options;
71 options.protocol = brpc::PROTOCOL_HTTP;
72 options.connect_timeout_ms = FLAGS_timeout_ms / 2;
73 options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;
74 options.max_retry = FLAGS_max_retry;
75 const int concurrency_for_this_thread = FLAGS_concurrency / FLAGS_thread_num;
76
77 for (size_t i = args->offset; i < args->url_list->size(); i += FLAGS_thread_num) {
78 std::string const& url = (*args->url_list)[i];
79 brpc::Channel channel;
80 if (channel.Init(url.c_str(), &options) != 0) {
81 LOG(ERROR) << "Fail to create channel to url=" << url;
82 BAIDU_SCOPED_LOCK(args->output_queue_mutex);
83 args->output_queue.push_back(std::make_pair(url, butil::IOBuf()));
84 continue;
85 }
86 while (args->current_concurrency.fetch_add(1, butil::memory_order_relaxed)
87 > concurrency_for_this_thread) {
88 args->current_concurrency.fetch_sub(1, butil::memory_order_relaxed);
89 bthread_usleep(5000);
90 }
91 OnHttpCallEnd* done = new OnHttpCallEnd;
92 done->cntl.http_request().uri() = url;
93 done->args = args;
94 done->url = url;
95 channel.CallMethod(NULL, &done->cntl, NULL, NULL, done);
96 }
97 return NULL;
98}
99
100int main(int argc, char** argv) {
101 // Parse gflags. We recommend you to use gflags as well.

Callers

nothing calls this directly

Calls 9

bthread_usleepFunction · 0.85
fetch_addMethod · 0.80
fetch_subMethod · 0.80
IOBufClass · 0.50
sizeMethod · 0.45
InitMethod · 0.45
c_strMethod · 0.45
push_backMethod · 0.45
CallMethodMethod · 0.45

Tested by

no test coverage detected