I am attempting to build a nodejs clustered HTTP web server.
I am using cluster to fork the same number of workers as my desktop has cpu's. Each worker has its own unique key counter. for example worker 1 starts counting from 1000,000 worker 2 from 2000,000 etc.
at a random point in time i need all workers to reset there counters back to the starting value, e.g. worker 1 must reset to 1000,000, worker 2 must reset to 2000,000
i want to trigger thus reset operation by using a url endpoint parameter along the lines of
http://localhost:8888/aaaa/bbbb/cccc?resetCounter=true
The worker that receives this url request must send a message to the cluster master process, then the master process will broadcast to all the active workers instructing them to reset their particular counter.
how do you do this?
Node.js's standard cluster
module has built-in support for messaging between the master and worker processes. Start here to get a feel for how messaging works. It's pretty straight-forward.