Boost logo

Boost Users :

Subject: Re: [Boost-users] boost asio synchronous vs asynchronous operations performance
From: Igor R (boost.lists_at_[hidden])
Date: 2014-03-21 17:39:49


> void start()
> {
> while (socket_.is_open()) {
> boost::asio::async_write(socket_, boost::asio::buffer(message_),
> boost::bind(&tcp_connection::handle_write,
> shared_from_this(),
> boost::asio::placeholders::error,
> boost::asio::placeholders::bytes_transferred));
> }
> }
>
> private:
> tcp_connection(boost::asio::io_service& io_service)
> : socket_(io_service),
> message_(25, 'A')
> {
> }
>
> void handle_write(const boost::system::error_code& error,
> size_t bytes_transferred)
> {
> if (error) {
> if (socket_.is_open()) {
> std::cout<<"Error while sending data
> asynchronously"<<std::endl;
> socket_.close();
> }
> }
> }

I guess in the above handle_wite() you intended to call start() again.

<...>

> When the client is running against synchronous server it is able to receive
> around 700K msgs/sec but when it is running against asynchronous server the
> performance is dropped to around 100K-120K msgs/sec.

Since you use a very small message, the overhead related to the
completion handlers may be significant. In general, it's worth using
performance profiler to see what's going on, but anyway you could use
a trivial "static" handler allocator and see if it helps:
http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/example/cpp03/allocation/server.cpp

Of course, ensure you compile with optimizations.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net