18
I wrote a .NET 4.5 application that buffers colour, infrared, and depth data from a Kinect v2, performs some processing on it, and then dumps it to disk, in uncompressed form; the .NET application also starts ffmpeg as a subprocess and pipes colour data to it to be encoded as H.264.
Because I'm not using an SSD, the video data arrives quicker than I can write to disk. But that's ok, it's acceptable for me to discard video frames when I'm low on RAM. My only requirement is that whatever I keep be mostly contiguous 8- to 10-second chunks of video. So I have added some logic in my .NET 4.5 application to start discarding video frames when I don't have enough RAM to buffer contiguous 8 to 10 seconds of video (roughly 1.5 to 2 GB).
And, to prevent page thrashing, I have completely disabled paging files. This leaves me with a total of 16 GB physical RAM.
My problem is that even with that mechanism in place, sometimes my .NET application or the ffmpeg subprocess still get killed when Windows 8.1 freaks out about low RAM, because obviously my application is using the most RAM when it has a huge backlog of video data to write to disk. Is there a way to tell Windows that my processes are more important than others so that Windows would start killing other less important processes first?
10I didn't think windows killed processes, I thought that was a linux only feature. – Scott Chamberlain – 2014-12-18T03:58:07.027
can you try to limit the ram used by your app to always leave behind a couple of GBs spare? Because it seems you are not able to discard as fast as the data is adding up. – A-b – 2014-12-18T11:15:15.500
4@ScottChamberlain: That's because turning off the paging file on Windows is very rare. It gets you all kinds of unexpected and unusual behavior. The obvious answer here is "don't turn off the paging file; that forces Windows to keep unused data in RAM so your app can't use that RAM" – MSalters – 2014-12-18T13:44:46.957
1If this was a StackOverflow question, I could point you to
CreateMemoryResourceNotification
which is a lot less hacky. – MSalters – 2014-12-18T13:49:55.423If the bottleneck is writing to disk, then fix that. Uncompressed data is ridiculous. Use something like Lagarith http://lags.leetcode.net/codec.html to compress before writing to disk. It's lossless, but very fast.
– longneck – 2014-12-18T14:32:07.560@longneck I have considered the compression option. However, the machine only has a dual-core Core i3 and ffmpeg is already struggling with keeping up with encoding H.264 at 30fps in realtime. I think my best bet at the moment is to increase the padding. – Kal – 2014-12-18T14:39:45.540
Do you have to encode in realtime? – longneck – 2014-12-18T14:43:30.137
The H.264 encoding has to happen in real time because it runs 24/7. My estimate is that it will produce about 95 GB for every 24 hours. The size would be ridiculous in raw uncompressed form. In comparison, I'm only keeping raw uncompressed frames for select 8- to 10-second periods - when the Kinect detects a body - so the size is more manageable. – Kal – 2014-12-18T14:56:40.393
7@Kal: If disk access is a bottleneck, use a stronger compression, if CPU is a bottleneck, use a faster compression. If both are a bottleneck, rethink your entire design and start over, or get better hardware. – Mooing Duck – 2014-12-18T20:26:42.903
You disabled the page file. What did you think was going to happen. – Factor Mystic – 2014-12-19T03:09:57.663
Its pretty insane to use .net for ANY real time application, but most of all for video processing. It is likely you would get "acceptable" performance by doing the entire pipeline in OpenCL including a compression step. – Aron – 2014-12-19T03:10:05.187
1@FactorMystic OMG he did what? Disabling page file is going to reduce your usable RAM significantly. – Aron – 2014-12-19T03:12:17.160
Disabling the page file is actually not as bad as you might imagine. The computer uses about 2 GB out of 16 GB when sitting idle. I find that reduction in usable RAM acceptable, and it's much better than page thrashing for my purposes. – Kal – 2014-12-19T03:27:19.497
Can you lower the resolution of your input\output? This could lead to much lower memory consumption and faster encoding performances for your Core i3 processor. – mordack550 – 2014-12-19T09:51:25.567
@Kal Beware what you mean by "uses". If you're referring to the working set/resident memory, which is represented as "used" in the Windows Task Manager, then note that that does not accurately represent available memory with a page file disabled. Windows will refuse to allocate ("commit") memory when there isn't enough virtual memory (physical + pagefile) available. Many applications will commit far more memory than they ever use, which has to be reserved and unused in physical RAM when the page file is disabled. If you have 2 GB "used", you could have > 4 GB "committed"/unavailable. – Bob – 2014-12-21T23:39:54.283