Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Buffering to the hard disk

I am receiving a large quantity of data at a fixed rate. I need to do some processing on this data on a different thread, but this may run slower than the data is coming in, so I need to buffer the data. Due to the quantity of data coming in the available RAM would be quickly exhausted, so it needs to overflow onto the hard disk. What I could do with is something like a filesystem-backed pipe, so the writer could be blocked by the filesystem, but not by the reader running too slowly.

Here's a rough set of requirements:

  • Writing should not be blocked by the reader running too slowly.
  • If data is read slow enough that the available RAM is exhausted it should overflow to the filesystem. It's ok for writes to the disk to block.
  • Reading should block if no data is available unless the stream has been closed by the writer.
  • If the reader is able to keep up with the data then it should never hit the hard disk as the RAM buffer would be sufficient (nice but not essential).
  • Disk space should be recovered as the data is consumed (or soon after).

Does such a mechanism exist in Windows?

like image 959
spencercw Avatar asked Nov 11 '22 01:11

spencercw


1 Answers

This looks like a classic message queue. Did you consider MSMQ or similar? MSMQ has all the properties you are asking for. You may want to use direct addressing to avoid Active Directory http://msdn.microsoft.com/en-us/library/ms700996(v=vs.85).aspx and use local or TCP/IP queue address.

like image 114
JurekM Avatar answered Nov 14 '22 23:11

JurekM