| 78 | } |
| 79 | |
| 80 | int main(int argc, char* argv[]) { |
| 81 | // Parse gflags. We recommend you to use gflags as well. |
| 82 | GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); |
| 83 | |
| 84 | // A Channel represents a communication line to a Server. Notice that |
| 85 | // Channel is thread-safe and can be shared by all threads in your program. |
| 86 | brpc::Channel channel; |
| 87 | |
| 88 | // Initialize the channel, NULL means using default options. |
| 89 | brpc::ChannelOptions options; |
| 90 | options.protocol = brpc::PROTOCOL_THRIFT; |
| 91 | options.connection_type = FLAGS_connection_type; |
| 92 | options.connect_timeout_ms = std::min(FLAGS_timeout_ms / 2, 100); |
| 93 | options.timeout_ms = FLAGS_timeout_ms; |
| 94 | options.max_retry = FLAGS_max_retry; |
| 95 | if (channel.Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), &options) != 0) { |
| 96 | LOG(ERROR) << "Fail to initialize channel"; |
| 97 | return -1; |
| 98 | } |
| 99 | |
| 100 | if (FLAGS_request_size <= 0) { |
| 101 | LOG(ERROR) << "Bad request_size=" << FLAGS_request_size; |
| 102 | return -1; |
| 103 | } |
| 104 | g_request.resize(FLAGS_request_size, 'r'); |
| 105 | |
| 106 | if (FLAGS_dummy_port >= 0) { |
| 107 | brpc::StartDummyServerAt(FLAGS_dummy_port); |
| 108 | } |
| 109 | |
| 110 | std::vector<bthread_t> bids; |
| 111 | std::vector<pthread_t> pids; |
| 112 | if (!FLAGS_use_bthread) { |
| 113 | pids.resize(FLAGS_thread_num); |
| 114 | for (int i = 0; i < FLAGS_thread_num; ++i) { |
| 115 | if (pthread_create(&pids[i], NULL, sender, &channel) != 0) { |
| 116 | LOG(ERROR) << "Fail to create pthread"; |
| 117 | return -1; |
| 118 | } |
| 119 | } |
| 120 | } else { |
| 121 | bids.resize(FLAGS_thread_num); |
| 122 | for (int i = 0; i < FLAGS_thread_num; ++i) { |
| 123 | if (bthread_start_background( |
| 124 | &bids[i], NULL, sender, &channel) != 0) { |
| 125 | LOG(ERROR) << "Fail to create bthread"; |
| 126 | return -1; |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | while (!brpc::IsAskedToQuit()) { |
| 132 | sleep(1); |
| 133 | LOG(INFO) << "Sending EchoRequest at qps=" << g_latency_recorder.qps(1) |
| 134 | << " latency=" << g_latency_recorder.latency(1); |
| 135 | } |
| 136 | |
| 137 | LOG(INFO) << "EchoClient is going to quit"; |
nothing calls this directly
no test coverage detected