我使用boost :: asio处理我的异步tcp请求,但是我发现每次调用boost :: asio :: async_write都需要数百微秒。我认为这只是将数据放入TCP发送缓冲区。为什么这么久?谢谢大家!
==== 227 do_write_impl
==== 274 do_write_impl
==== 238 do_write_impl
==== 60 do_write_impl
==== 220 do_write_impl
==== 229 do_write_impl
==== 368 do_write_impl
==== 189 do_write_impl
==== 221 do_write_impl
==== 234 do_write_impl
auto b = boost::asio::buffer(msg_send->get_header(), length);
auto f = [self, this] (const bsys::error_code& e, std::size_t bytes_trans) { handle_write_impl(e, bytes_trans); };
struct timeval tv1 {0, 0};
struct timeval tv2 {0, 0};
gettimeofday(&tv1, nullptr); const auto beg = tv1.tv_sec * 1000000 + tv1.tv_usec;
boost::asio::async_write(socket_,
b,
f
);
gettimeofday(&tv2, nullptr); const auto end = tv2.tv_sec * 1000000 + tv2.tv_usec;
std::cout << " ==== " << (end - beg) << " do_write_impl " << std::endl;