문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top