chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.72k stars 1.19k forks source link

Reading and/or writing a small number of bytes slows down program #1426

Closed DUOLabs333 closed 4 months ago

DUOLabs333 commented 4 months ago

I'm sending messages over TCP. To delimit them, I send the size over 4 bytes, then I send the message. Reading the message body is fast, but unintuitively, reading the much smaller size bytes is slow --- if I switch the delimitation to read_until('\n'), getting rid of the size writing/reading all together, my program is much faster.

DUOLabs333 commented 4 months ago

I fixed this using set_option( asio::ip::tcp::no_delay( true) )