| 73 | } |
| 74 | |
| 75 | int 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 | } |
nothing calls this directly
no test coverage detected