I am trying to transfer a huge array of bytes (size: 12 MegaBytes) using ZeroMQ in Windows 10 64 Bit OS. The rate of transfer is 15 Frame Per Second approximately.
The code is throwing following error:
Exception thrown: 'System.OutOfMemoryException' in ZeroMQ.dll
During debugging using Visual Studio, it shows 4GB process memory as shown in the screenshot below:
However, when I checked the memory consumption in OS, it shows 7.1GB out of 8GB. But 801MB is still unused, which makes me wonder about System.OutOfMemoryException
exception.
See below the screenshot:
The computer is equipped with Gigabit Ethernet card. See below the card usage:
Please see below the code:
ZContext zmqContext;
ZSocket publisher;
Stopwatch watch;
readonly byte[] longByteArray = new byte[12000000];
Program()
{
zmqContext = new ZContext();
publisher = new ZSocket(zmqContext, ZSocketType.PUB);
publisher.Bind("tcp://*:11111");
var timer = new Timer();
timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
timer.Interval = 1000.0 / 15;//15 FPS
timer.Enabled = true;
}
private void OnTimedEvent(object source, ElapsedEventArgs e)
{
var frame = new ZFrame(longByteArray);
publisher.Send(frame);
frame.Dispose();
}
Below is my observation:
- Although, it is not possible to change the FPS in real code, however, the above code snippet is sample code and in this code, I changed FPS from 15 to 10. The error still pops up after some time. Initially, the memory consumption was less but it keeps on increasing as time passes.
My questions are following:
- As per my observation above it seems that ZeroMQ publisher is keeping messages in a queue, which is eating a lot of memory. I am wondering if it is possible to configure ZeroMQ to keep only one message (last i.e. newest message) in the queue so that ZeroMQ can discard other messages resulting less memory consumption.
- Why is the exception being thrown, even though 801MB memory is still available?
- Is there any other workaround to make the code work?