Commit 563df5ec authored by zhujiashun's avatar zhujiashun

Directly allocate unsent message instead of preparing them first

parent 5947fed8
......@@ -36,45 +36,37 @@ TEST(H2UnsentMessage, request_throughput) {
ctx->_last_client_stream_id = 0;
ctx->_remote_window_left = brpc::H2Settings::MAX_WINDOW_SIZE;
int64_t ntotal = 1000000;
int64_t ntotal = 5000000;
// calc H2UnsentRequest throughput
std::vector<brpc::policy::H2UnsentRequest*> req_msgs;
req_msgs.resize(ntotal);
for (int i = 0; i < ntotal; ++i) {
req_msgs[i] = brpc::policy::H2UnsentRequest::New(&cntl);
}
butil::IOBuf dummy_buf;
ProfilerStart("h2_unsent_req.prof");
int64_t start_us = butil::gettimeofday_us();
for (int i = 0; i < ntotal; ++i) {
req_msgs[i]->AppendAndDestroySelf(&dummy_buf, h2_client_sock.get());
brpc::policy::H2UnsentRequest* req = brpc::policy::H2UnsentRequest::New(&cntl);
req->AppendAndDestroySelf(&dummy_buf, h2_client_sock.get());
}
int64_t end_us = butil::gettimeofday_us();
ProfilerStop();
int64_t elapsed = end_us - start_us;
LOG(INFO) << "H2UnsentRequest average qps="
<< (ntotal * 1000000L) / elapsed << "/s, data throughput="
<< dummy_buf.size() * 1000000L / elapsed;
req_msgs.clear();
<< dummy_buf.size() * 1000000L / elapsed << "/s";
// calc H2UnsentResponse throughput
std::vector<brpc::policy::H2UnsentResponse*> res_msgs;
res_msgs.resize(ntotal);
for (int i = 0; i < ntotal; ++i) {
cntl.http_response().set_content_type("text/plain");
cntl.response_attachment().append("0123456789abcedef");
res_msgs[i] = brpc::policy::H2UnsentResponse::New(&cntl, 0, false);
}
dummy_buf.clear();
start_us = butil::gettimeofday_us();
for (int i = 0; i < ntotal; ++i) {
res_msgs[i]->AppendAndDestroySelf(&dummy_buf, h2_client_sock.get());
// H2UnsentResponse::New would release cntl.http_response() and swap
// cntl.response_attachment()
cntl.http_response().set_content_type("text/plain");
cntl.response_attachment().append("0123456789abcedef");
brpc::policy::H2UnsentResponse* res = brpc::policy::H2UnsentResponse::New(&cntl, 0, false);
res->AppendAndDestroySelf(&dummy_buf, h2_client_sock.get());
}
end_us = butil::gettimeofday_us();
elapsed = end_us - start_us;
LOG(INFO) << "H2UnsentResponse average qps="
<< (ntotal * 1000000L) / elapsed << "/s, data throughput="
<< dummy_buf.size() * 1000000L / elapsed;
res_msgs.clear();
<< dummy_buf.size() * 1000000L / elapsed << "/s";
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment