Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ZeroMQ Poll function use excessive CPU on .NET?

Tags:

c#

zeromq

I have a simple console application that uses ZeroMQ to send and receive messages. In the receive portion, I have the following message pump code:

   ZMQ.Context _context = new ZMQ.Context(1);

   ZMQ.PollItem[] pollItems = new ZMQ.PollItem[0];

   while (!_finished)
   {
       if (pollItems.Length > 0)
           context.Poll(pollItems, pollTimeout);
       else
           Thread.Sleep(1);

       if (_receiversChanged)
           UpdatePollItems(ref pollItems);
   }

(The idea is that I can add and remove items from the poller at run-time, as I need to add receivers. UpdatePollItems simply creates a new array whenever the set of receivers changes.)

I have tried pollTimeout values of 50ms and 500ms but the app (which is sitting on its main thread on Console.ReadKey) still uses 100% of one core, even when no messages are being sent. I ran the app under the profiler and confirmed that it is ZMQ.Context.Poller that is chewing all the CPU.

Have others seen similar behaviour? I am using the latest ZeroMQ C# binding (clrzmq-x64.2.2.3 from NuGet).

like image 845
SteveWilkinson Avatar asked Sep 14 '25 12:09

SteveWilkinson


1 Answers

Yes there is a bug in the driver. I hit that as well. Looking at the code it is possible that the .net 4 version should fare better, but you have to recompile it. I will check whether the code I rewrote could be reintegrated as a pull request.

like image 72
mgoetzke Avatar answered Sep 16 '25 03:09

mgoetzke