I am using Boost/ASIO to write a C++ server and accompanying client app which talk over TCP/IP. I was seeing delays between consecutive receives which were causing lower-than-expected throughput between the server and the client. The code on either side looked roughly like
class MyStream
{
...
void doStuff()
{
asio::async_read(socket, buffer, &bind(MyStream::readCallback, this, _1, _2)); // get some bytes
}
void readCallback(const error_code& err, size_t bytes_transferred)
{
processData(bytes_transferred); // maybe write some data back
asio::async_read(socket, buffer, &bind(MyStream::readCallback, this, _1, _2)); // get some additional bytes
}
...
};
The messaging between the server and client was very slow, something like 20-30 messages back-and-forth per second. I was testing on the local machine, using very small messages.
Using the ASIO compiler flag -DASIO_ENABLE_HANDLER_TRACKING
I observed delays between some of the receives which were consistently ~40ms.
...
@asio|1613871309.603585|>22|ec=asio.system:0,bytes_transferred=30
@asio|1613871309.603688|22^34|in 'ssl::stream<>::async_read_some' ([redacted]/asio/include/asio/ssl/detail/io.hpp:167)
@asio|1613871309.603688|22*34|socket@0x7fdebc013f80.async_receive
@asio|1613871309.603703|.34|non_blocking_recv,ec=asio.system:11,bytes_transferred=0
@asio|1613871309.603725|<22|
@asio|1613871309.643974|.34|non_blocking_recv,ec=asio.system:0,bytes_transferred=248
@asio|1613871309.644013|>34|ec=asio.system:0,bytes_transferred=248
...
What could be causing this 40ms delay?