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