Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower Level Poller Pattern Question #596

Closed
peske opened this issue Jul 31, 2016 · 8 comments
Closed

Lower Level Poller Pattern Question #596

peske opened this issue Jul 31, 2016 · 8 comments
Labels

Comments

@peske
Copy link

peske commented Jul 31, 2016

In NetMQ poller is obviously implemented in NetMQPoller class, as "event-driven reactor". It's definitely easier pattern than original ZeroMQ implementation, but I've ran into a situation where I need lower level pattern (like mspoller from ZeroMQ guide). Basically I need to get a message (single message) from any of two receiver sockets (or to wait up to timeout for one to arrive). After that the thread should do some other work, and repeat cycle again (getting message -> other work), in an infinite loop. I hope that you understand what I need - it's actually the same exact thing as the linked example from above.

Does NetMQ offer some lower-level poller API that would allow this? Any alternative approach?

Thanks!

@somdoron
Copy link
Member

We used to have something like that in the old poller, anyway I suggest two solutions:

  1. Make a pull request to netmq and add a RunOnce method which will receive a timeout and will run until timeout or first receive ready.
  2. Wrap netmqpoller, should be pretty simple, each receive ready should immediately cancel the poller, you can also have netmqtimeout, which also cancel the poller, use the sync run version.

@peske
Copy link
Author

peske commented Jul 31, 2016

@somdoron Thanks for replying so fast!

Regarding the first suggestion: I'm still beginner with NetMQ, and I'm not feeling comfortable enough to PR, but if I come up with something good - I'll share. There's another thing that worries me about this approach: implementing lower-level API (zmq_poll wrapper) by further building upon the existing higher level API (NetMQPoller) does not sound as the right thing to do. Things are usually done in the opposite direction: create performant lower level API, and then build the higher level upon it. It is especially true if we are ware of the fact that NetMQPoller can be performance expensive, and especially in projects like NetMQ where performances are crucial.

About the second approach I'll have to ask you for advice: We are talking about the system that should be able to handle 20,000+ messages per second. It means that I should start / stop poller 20,000+ times per second. Do you still think I can go this way?

Thank you very much for trying to help!

@peske
Copy link
Author

peske commented Jul 31, 2016

I've tried, but I'm far from understanding NetMQPoller.cs, so I'll give up on creating pr with RunOnce. I'll have to try with the second suggested approach.

In any case I suggest you to consider adding some light-weight version of zmq_poll. NetMQPoller is obviously too massive (and too slow), and at the moment it is the only way to access some kind of polling.

@drewnoakes
Copy link
Member

Here's the old Poller class at the time NetMQPoller was introduced, including PollOnce:

https://github.com/zeromq/netmq/blob/932bf9d3e31090aa33ab495050c7b8f5a48a7ddb/src/NetMQ/Poller.cs

NetMQPoller has a lot in common with the Poller from that time, and was merged with (the now removed) NetMQScheduler, giving the class you've been looking at today.

Would that implementation be light-weight enough for your requirement? It still uses much of the same machinery underneath.

@peske
Copy link
Author

peske commented Aug 1, 2016

Thanks for trying to help!

As far as I can see in the code, there would be no difference in performances if I implement RunOnce comparing to using the existing implementation and calling Stop as soon as the first event happen. So I'll do the later.

I'm still afraid a bit that NetMQPoller class will be a bottleneck, and I'll compare performances with clrzmq implementation of zmq_poll when I have bit more time, and let you know about the results.

Thanks again!

@peske
Copy link
Author

peske commented Aug 2, 2016

I've ran into problems with NetMQPoller and opened another issue: #598

@stale
Copy link

stale bot commented May 15, 2020

This issue has been automatically marked as stale because it has not had activity for 365 days. It will be closed if no further activity occurs within 56 days. Thank you for your contributions.

@stale stale bot added the stale label May 15, 2020
@stale stale bot closed this as completed Jul 11, 2020
@poroburu
Copy link

Signalling my interest in a NetMQTimeout.

Working through the zguide in F# using FsNetMQ. fszmq is now deprecated.
Managed to work around C style ZMQ_POLL using Poller. Almost reaching F# example parity at the end of chapter 3 until peering2, then the polling logic got a bit complicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants