0

Trying to implement queue processor(s) in node.js application using rsmq-worker (https://github.com/mpneuried/rsmq-worker). Have to run multiple workers to process messages in parallel.

How do we setup multiple workers?

Exploring on using - https://github.com/Automattic/kue#parallel-processing-with-cluster

1
  • @nvartolomei, I understand running multiple node processes is the ultimate parallelism option. However, I think running multiple instances of the rsmq-worker per node process would also be beneficial in terms of performance, given that the message processing might involve a lot of I/O. Makes sense? Commented Aug 30, 2017 at 12:21

2 Answers 2

1

Simply create multiple instances of the RSMQWorker pointing to the same queue.

Example:

var workers = [];
for (let i = 0; i < NUMBER_OF_WORKERS; i++) {
        workers[i] = createWorker(i);
}

function createWorker(i) {
    const worker = new RSMQWorker(QUEUE_NAME, {...});
    worker.on("message", processMessage)
    return worker;
}

Then you can use the auto-start option of the rsmq-worker or start them manually:

for (let i = 0; i < workers.length; i++) {
    workers[i].start();
}

With this approach you will be processing multiple messages in parallel using one single Node.js instance. It improves the performance if your message processing logic involves some I/O.

For an additional level of parallelism, you can run the above code in multiple instances of Node.js, as mentioned in other answer.

Sign up to request clarification or add additional context in comments.

1 Comment

What is the recommend number of workers to start with 1 GB on memory?
0

You just launch multiple worker processes and they will start to process messages in parallel. RSMQ states that it guarantees that messages will be delivered only once so only one worker will process a single message.

Take a look at RSMQ readme, https://github.com/smrchy/rsmq. Pay attention to:

Guaranteed delivery of a message to exactly one recipient within a messages visibility timeout.

Please have a look at the createQueue and receiveMessage methods described below for optional parameters like visibility timeout and delay.

4 Comments

Thanks nvartolomei. 'launch multiple works processes' - you mean to run multiple node.js processees?
Right, multiple node processes.
You can use this too, under the hood it will launch multiple node processes, the only difference is that you can use inter process communication, but this works only for tcp connections, ie http server. But you don't need any of these.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.