4

I've developed a TCP network application using boost::asio with an asynchronous approach. The application sends around 1GB of data in the following way:

  • Send a 5 bytes command (using async_write())
  • Send a 1024 bytes data (using another async_write())
  • Repeat until all the 1GB data is sent

When I use a synchronous approach the performances are the expected (around 9 seconds to TX 1GB of data using a 1Gb ethernet) but when I use asynchronous calls the performance decrease and 20 seconds are needed to TX the same amount of data.

I have tried to deactivate the Nagle's algorithm but it doesn't solve the problem.

do you know if using several async_write() calls with small amounts of data can have a negative impact on performances?

Thanks!

lezo
  • 175
  • 1
  • 1
  • 10
  • Try using larger (32-64k) data packet sizes. – Wilbert Oct 22 '13 at 14:11
  • @Wilbert, so you agree with me that using async operations with small amounts of data decrease the performance. Sadly, I can't decrease the packet size (it's imposed on me by the receiver design) – lezo Oct 22 '13 at 14:32
  • @lezo Packet size? Do you use TCP or UDP? – Slava Oct 22 '13 at 14:34
  • @lezo It's just a guess, but yes. – Wilbert Oct 22 '13 at 14:39
  • @Slava I use TCP. Pakets have 5 bytes (a header containing useful information) and 1024 bytes. – lezo Oct 22 '13 at 14:45
  • 3
    @lezo when you use TCP there is stream, no packets. So you can send more data at once unrelated how receiver is designed. – Slava Oct 22 '13 at 14:52
  • @Slava so how do you suggest me I should proceed? Do you mean I should put everything in a big stream and then send it asynchronously? – lezo Oct 22 '13 at 15:07
  • 2
    @lezo you did not understand me. TCP is already a stream by itself. So sending one packet at a time does not mean that receiver gets it by one packet every time. And receiver definitely should not rely on that. Probably send whole 1GB file in one shot is not a good idea, but try to send more than 1 "packet" at a time. Wilbert suggested 32-64k so send 32 - 64 packets in one call. Measure. Try more. Until it will not affect speed anymore and would be still reasonable. – Slava Oct 22 '13 at 15:12
  • This is very curious because the way you push bytes into the TCP stack should not materially impact performance (in fact, synchronous sends should take a little less CPU). Post your code, profile it (or pause the debugger multiple times to see where it stops most). – usr Oct 22 '13 at 16:11

0 Answers0