| 49 | _sleep_us = sleep_us; |
| 50 | } |
| 51 | virtual void Echo(google::protobuf::RpcController* cntl_base, |
| 52 | const example::EchoRequest* request, |
| 53 | example::EchoResponse* response, |
| 54 | google::protobuf::Closure* done) { |
| 55 | brpc::ClosureGuard done_guard(done); |
| 56 | brpc::Controller* cntl = |
| 57 | static_cast<brpc::Controller*>(cntl_base); |
| 58 | if (_sleep_us > 0) { |
| 59 | double delay = _sleep_us; |
| 60 | const double a = FLAGS_exception_ratio * 0.5; |
| 61 | if (a >= 0.0001) { |
| 62 | double x = butil::RandDouble(); |
| 63 | if (x < a) { |
| 64 | const double min_sleep_us = FLAGS_min_ratio * _sleep_us; |
| 65 | delay = min_sleep_us + (_sleep_us - min_sleep_us) * x / a; |
| 66 | } else if (x + a > 1) { |
| 67 | const double max_sleep_us = FLAGS_max_ratio * _sleep_us; |
| 68 | delay = _sleep_us + (max_sleep_us - _sleep_us) * (x + a - 1) / a; |
| 69 | } |
| 70 | } |
| 71 | if (FLAGS_spin) { |
| 72 | int64_t end_time = butil::cpuwide_time_us() + (int64_t)delay; |
| 73 | while (butil::cpuwide_time_us() < end_time) {} |
| 74 | } else { |
| 75 | bthread_usleep((int64_t)delay); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // Echo request and its attachment |
| 80 | response->set_message(request->message()); |
| 81 | if (FLAGS_echo_attachment) { |
| 82 | cntl->response_attachment().append(cntl->request_attachment()); |
| 83 | } |
| 84 | _nreq << 1; |
| 85 | } |
| 86 | |
| 87 | size_t num_requests() const { return _nreq.get_value(); } |
| 88 |
no test coverage detected