Feature Request: Set Receive Buffer size for Netcam
In debugging a recent problem with an IP9100A
) I needed to find out the TCP receive and transmit buffer sizes that were allocated by default.
So I updated the StatisticsDataPatch
to output this information (patch is not yet posted on that page but I have it stored and will post it soon).
The results were interesting. On my PC the first thread (a streaming webcam at 5fps) is allocated (automatically I think) 868,000-1,600,000 bytes of receive buffer. This is much more than should be needed, and subsequent threads only received 87,000 bytes (all figures approximate).
I created a small patch to set the TCP Receive & Send buffers to 128kB. That should be enough for netcams, all mine send frames of size 30kb-55kb (640x480 image). I did begin with 64kB of buffer but noticed that my 5fps webcam seemed to reduce rate a little.
This may help in a low memory environment, or with large numbers of netcams if buffer space is starved. A possible improvement would be to allow a config file parameter to specify (say) 64kB, 128kB, 256kB buffers.
If you are interested in finding out what your machine allocates for TCP buffers, you could use the StatisticsDataPatch
(again, the new patch is not yet posted online) before this patch is applied, then incorporate the patch and see that the buffer size has changed to 128kB.
Also included in the patch is to switch off Nagle's algorithm. This algorithm can delay short TCP packets (such as HTTP requests) in case some more data comes along to fill a packet. In netcam HTTP requests this is not required, and might hurt performance. Although I did not see a measurable change by disabling it, it makes sense.
The patch also changes a couple of netcam delays, one to 20secs and one to 8secs to permit a tcpdump log to identify them. Currently many delays are 5s or 10s, and when there is a problem it is unclear which
delay is being executed.
- 16 Jan 2008
Also posted here is a variant with the anti-syslog-floodling patch integrated. The two individual patches for those fixes cannot be applied one after the other because they both affect the same area of code.
Patch name: SWpatch_netcam-buffers1flood
I think now that setting the Send buffer to 128Kb is a bit wasteful, a typical HTTP request being 111 bytes in my case. Anyone could edit the patch to set a smaller number for the send buffer easily, but I can't do that right now.
- 17 Jan 2008