我正在使用Boost ASIO库来实现需要高吞吐量的Windows UDP客户端。如何增加Boost ASIO,UDP客户端应用程序的吞吐量
我想使用异步接收调用,以便我最终可以实现接收超时,即。如果没有收到数据报,经过一段时间后,我的应用程序将退出。
我的问题是,我看到使用同步接收器 比异步接收高30%的数据吞吐量。在多台Dell R630,R710 Windows 2008服务器,甚至是我的 联想ThinkPad笔记本电脑上运行 应用程序时,我发现了这个问题。
以下两个代码段的主要性能差异是什么? 在每个异步接收之后调用ioService.run_one()
是否有更多开销? 我是Boost库的新用户,所以任何帮助将非常感谢!
同步接收:
socket_->receive_from(boost::asio::buffer(&vector_[0], datagramSize),
endPoint_);
与
异步接收(用封闭):
err = boost::asio::error::would_block;
socket_->async_receive_from(
boost::asio::mutable_buffers_1(&vector_[0], datagramSize),
endPoint_,
boost::bind(&HandleRead, _1, _2, &err, &bytesReceived));
do
{
ioService_.run_one()
}
while(err == boost::asio::error::would_block)
异步接收处理函数:
static void HandleRead
(
const boost::system::error_code& error,
std::size_t bytesRead,
boost::system::error_code* outError,
std::size_t* outBytesRead
)
{
*outError = error;
*outBytesRead = bytesRead;
}
在你async_receive_from情况下线程,处理器与缓慢标准'运营商new'分配。处理程序的快速[自定义分配](http://www.boost.org/doc/libs/1_58_0/doc/html/boost_asio/reference/asio_handler_allocate.html)可以提高性能。 –