| 66 | } |
| 67 | |
| 68 | void* 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 | |
| 100 | int main(int argc, char** argv) { |
| 101 | // Parse gflags. We recommend you to use gflags as well. |
nothing calls this directly
no test coverage detected