Motion - Feature Request 2008x 01x 16x 222003

Feature Request: Set Receive Buffer size for Netcam

Description

In debugging a recent problem with an IP9100A (see WorkingDevices) 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.

Cheers, Simon.

-- SimonW - 16 Jan 2008

Follow up

Comments

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.

-- SimonW - 17 Jan 2008

FeatureRequestForm edit

TopicTitle Set Receive Buffer size for Netcam
FeatureRequestStatus New
SubmittedBy SimonW
I Attachment Action Size Date Who Comment
SWpatch_netcam-buffers1EXT SWpatch_netcam-buffers1 manage 3 K 16 Jan 2008 - 22:40 UnknownUser Patch to SVN292 to set netcam buffers to 128kB and disable Nagle's algorithm.
SWpatch_netcam-buffers1floodEXT SWpatch_netcam-buffers1flood manage 4 K 17 Jan 2008 - 20:44 UnknownUser Patch to SVN305 to set Netcam buffer sizes, disable Nagle algorithm and will not flood syslog (1 error message/minute)
Topic revision: r3 - 17 Jan 2008, SimonW
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Please do not email Kenneth for support questions (read why). Use the Support Requests page or join the Mailing List.
This website only use harmless session cookies. See Cookie Policy for details. By using this website you accept the use of these cookies.