in reply to Help me understand/fix buffering issue for tcp?
Actually, I suspect the issue comes from lack of buffering.
Because the output isn't buffered, two packets are sent out. The readline receives one, it doesn't have a newline, so it must wait for another. Lots of system calls. Lots more work.
Or maybe the OS starts performing its own buffering when you send lots of short strings, and the delay is the OS making sure you're not about to send another.
You can keep your code structure by turning off the buffering on the socket and explicitly flushing the socket when you output a newline.
PS — You might benefit from examining the traffic with tcpdump.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Help me understand/fix buffering issue for tcp?
by suaveant (Parson) on Nov 21, 2011 at 14:01 UTC | |
Re^2: Help me understand/fix buffering issue for tcp?
by suaveant (Parson) on Nov 21, 2011 at 21:07 UTC |