Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

0MQ with green threads?

Tags:

erlang

zeromq

I've grown to like erlang, and it's a great (cough) architectural fit to my problem. Meanwhile I still like to imagine that I can kludge erlang processes & asynchronous message passing in python (I am currently in therapy to rid myself of this obsession).

During a recent binge I came across 0MQ & I like its messaging features. These may be self-evident to an erlang/OTP expert, but I'm just a humble python programmer (my shrink will no doubt get to read this clever argument). The 0MQ user-guide states that it uses native OS threads, and not virtual "green" threads.

  1. Is there a way to make 0MQ work with say eventlet/gevent?

  2. Or, should I avoid the green-eyed monster and stick to a single Python app thread, with non-blocking I/O handled by 0MQ's message queuing & its own (skilled) use of native threads?

  3. Or, check out of rehab & go back to erlang?

like image 763
user402476 Avatar asked Aug 10 '10 19:08

user402476


People also ask

Does zmq queue messages?

Every zeromq socket has both send and recv queues (The limits are set via high water mark). In the case of a brokerless PUB/SUB the messages could be queued on the sender or the receiver. Example: If there is network congestion the sender may queue on its send queue.

Is Zmq thread safe?

A ØMQ context is thread safe and may be shared among as many application threads as necessary, without any additional locking required on the part of the caller. Individual ØMQ sockets are not thread safe except in the case where full memory barriers are issued when migrating a socket from one thread to another.

What is ZeroMQ used for?

ZeroMQ is a library used to implement messaging and communication systems between applications and processes - fast and asynchronously.

What is a Zmq context?

Contexts help manage any sockets that are created as well as the number of threads ZeroMQ uses behind the scenes. Create one when you initialize a process and destroy it as the process is terminated. Contexts can be shared between threads and, in fact, are the only ZeroMQ objects that can safely do this.


2 Answers

Responding to a stale thread because I am kind of in the same boat. Thought I would share my thoughts.

1: It looks like all the heavy lifting has already been done: https://github.com/traviscline/gevent-zeromq has integrated the gevent loop with a nonblocking zmq socket and even some Cpython speedups. It also seems to be (at the time of this writing), reasonably well maintainted.

2: It depends; if you are writing something that can use zmq without a ton of external event logic, then you should just use zmq. If OTOH you need to integrate with other protocols, you may want to use gevent (or twisted perhaps, although it has no workable zmq now at all). My projects generally require multiple protocols (ie: private queue manager, public http, public https, private memcache, etc), so I am investigating switching to gevent for quicker project turnaround than my current favorite: twisted.

3: You may want to skip zmq entirely and integrate with an existing erlang based solution like rabbitMQ; the performance advantages of zmq may not be as important as you think, and then you have an erlang message queue that easily integrates with python with existing libraries.

Also see: Messsage Queue comparison at second life wiki

like image 195
Enki Avatar answered Sep 28 '22 04:09

Enki


Zero MQ now works with Eventlet:

https://lists.secondlife.com/pipermail/eventletdev/2010-October/000907.html

like image 34
Noah F SanTsorbutz Avatar answered Sep 28 '22 03:09

Noah F SanTsorbutz