| 33 | } |
| 34 | |
| 35 | TEST(H2UnsentMessage, request_throughput) { |
| 36 | brpc::Controller cntl; |
| 37 | butil::IOBuf request_buf; |
| 38 | cntl.http_request().uri() = "0.0.0.0:8010/HttpService/Echo"; |
| 39 | brpc::policy::SerializeHttpRequest(&request_buf, &cntl, NULL); |
| 40 | |
| 41 | brpc::SocketId id; |
| 42 | brpc::SocketUniquePtr h2_client_sock; |
| 43 | brpc::SocketOptions h2_client_options; |
| 44 | h2_client_options.user = brpc::get_client_side_messenger(); |
| 45 | EXPECT_EQ(0, brpc::Socket::Create(h2_client_options, &id)); |
| 46 | EXPECT_EQ(0, brpc::Socket::Address(id, &h2_client_sock)); |
| 47 | |
| 48 | brpc::policy::H2Context* ctx = |
| 49 | new brpc::policy::H2Context(h2_client_sock.get(), NULL); |
| 50 | CHECK_EQ(ctx->Init(), 0); |
| 51 | h2_client_sock->initialize_parsing_context(&ctx); |
| 52 | ctx->_last_sent_stream_id = 0; |
| 53 | ctx->_remote_window_left = brpc::H2Settings::MAX_WINDOW_SIZE; |
| 54 | |
| 55 | int64_t ntotal = 500000; |
| 56 | |
| 57 | // calc H2UnsentRequest throughput |
| 58 | butil::IOBuf dummy_buf; |
| 59 | ProfilerStart("h2_unsent_req.prof"); |
| 60 | int64_t start_us = butil::cpuwide_time_us(); |
| 61 | for (int i = 0; i < ntotal; ++i) { |
| 62 | brpc::policy::H2UnsentRequest* req = brpc::policy::H2UnsentRequest::New(&cntl); |
| 63 | req->AppendAndDestroySelf(&dummy_buf, h2_client_sock.get()); |
| 64 | } |
| 65 | int64_t end_us = butil::cpuwide_time_us(); |
| 66 | ProfilerStop(); |
| 67 | int64_t elapsed = end_us - start_us; |
| 68 | LOG(INFO) << "H2UnsentRequest average qps=" |
| 69 | << (ntotal * 1000000L) / elapsed << "/s, data throughput=" |
| 70 | << dummy_buf.size() * 1000000L / elapsed << "/s"; |
| 71 | |
| 72 | // calc H2UnsentResponse throughput |
| 73 | dummy_buf.clear(); |
| 74 | start_us = butil::cpuwide_time_us(); |
| 75 | for (int i = 0; i < ntotal; ++i) { |
| 76 | // H2UnsentResponse::New would release cntl.http_response() and swap |
| 77 | // cntl.response_attachment() |
| 78 | cntl.http_response().set_content_type("text/plain"); |
| 79 | cntl.response_attachment().append("0123456789abcedef"); |
| 80 | brpc::policy::H2UnsentResponse* res = brpc::policy::H2UnsentResponse::New(&cntl, 0, false); |
| 81 | res->AppendAndDestroySelf(&dummy_buf, h2_client_sock.get()); |
| 82 | } |
| 83 | end_us = butil::cpuwide_time_us(); |
| 84 | elapsed = end_us - start_us; |
| 85 | LOG(INFO) << "H2UnsentResponse average qps=" |
| 86 | << (ntotal * 1000000L) / elapsed << "/s, data throughput=" |
| 87 | << dummy_buf.size() * 1000000L / elapsed << "/s"; |
| 88 | } |
nothing calls this directly
no test coverage detected