PUB / SUB with short-lived publisher and long-lived subscribers

Context: OS: Linux (Ubuntu), language: C (actually Lua, but that doesn't matter).

I would prefer a solution based on ZeroMQ, but still I will accept something enough.

Note. For technical reasons, I cannot use POSIX signals here.

I have several identical long-lived processes on the same machine ("workers").

From time to time I need to deliver a control message for each of the processes using the command line tool. Example:

  $ command-and-control worker-type run-collect-garbage

Each of the workers on this computer should receive a run-collect-garbage message. Note: it would be ideal if the solution somehow worked for all workers on all machines in the cluster, but I can write this part myself.

This is easy to do if I keep some information about working. For example, save the PIDs for them in a known place and open the Unix control domain of the domain at a known path with PID somewhere in it. Or open a TCP socket and save the host and port somewhere.

But this will require careful management of the stored information - for example, what if the workflow suddenly dies? (Nothing uncontrollable, but, nevertheless, additional fuss.) In addition, the information must be stored somewhere, which will add additional complexity.

Is there any good way to do this in PUB / SUB style? That is, the employees are subscribers, the command and control tool is the publisher, and all they know is the only "channel URL", so to speak, to which you want to send messages.

Additional requirements:

  • Messages on the control channel should awaken the workers from the survey (choose whatever) the cycle.
  • Message delivery must be guaranteed, and it must reach every working listener.
  • An employee should have a way to track messages without blocking - ideally, the poll / select / whatever loop described above.
  • Ideally, the workflow should be a "server" in a sense - it should not worry about maintaining connections to a "channel server" (if any), permanent, etc. - or it should be done transparently using the framework.
+7
source share
4 answers

Typically, such a template requires a proxy server for the publisher, i.e. you send a proxy server that immediately accepts the delivery, and then reliably rewrites the end user subscribers. The ZeroMQ Guide describes several different ways to implement it.

http://zguide.zeromq.org/page:all

+3
source

Given your requirements, Steve’s suggestion seems the simplest: launch a daemon that listens to two known sockets β€” workers connect to it, and a command tool pushes it to be redistributed to connected workers.

You could do something complicated that would probably work by effectively appointing one of the workers. For example, at startup, workers try to bind () the PUB ipc: // socket somewhere available, for example tmp. One that wins the bind () s of the second IPC as a PULL socket and acts as a forwarding device on top of its usual duties, others connect () to the original IPC. The command line tool connects () s to the second IPC and pushes it. The risk is that the winner dies leaving a locked file. You can determine this in the command line tool, then reconfigure, then hibernate (so that connections can be established). However, all this is a bit more complicated, I think I will go with a proxy!

+2
source

I think that what you describe will go well with the implementation of a mechanism / supervisor.

Gearman is an excellent task queue manager and supervisor that allows you to make sure that all processes are running. It is also based on TCP, so you can have clients / workers on different machines.

http://gearman.org/

http://supervisord.org/

I recently installed something with multiple transmission nodes and nodes associated with multiple workers, so there is no single point of failure

edit: Sorry - I feel bad, I just re-read and saw that this might not be ideal.

Redis has nice and simple pub / sub features that I haven't used yet, but it sounds promising.

0
source

Use mulitcast PUB / SUB. You must make sure that the pgm parameter pgm compiled into your ZeroMQ distribution ( man 7 zmq_pgm ).

0
source

All Articles