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.
Alexander Gladysh
source share