Question

I'm doing a Boost asio networking program for Mac OS X based on the HTTP Server 3 example. It uses async_read_some to read data from the TCP socket asynchronously.

The problem is that my handler returns with a very small amount of data. I give it a 64k buffer but it usually returns with about 1448 bytes which is the size of one full Ethernet packet. This in turn causes high CPU usage when there is a large data transfer and I can't imagine all those kernel to user space jumps are efficient.

Is this normal to get data in such small chunks?

Is there a way to tell the TCP stack or the asio framework to try and buffer more data in the kernel before returning?

Was it helpful?

Solution

It's really easy: once things become busy, you will start getting larger amounts of data at once. That's all there's to it. Yes, it's very much normal to get data in such small chunks when the system is not loaded. This is in fact the desired behavior: you are taking advantage of low system load to get exceptionally good latency. Things will gracefully degrade from that point, as necessary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top