Understanding the round robin behavior between processes #944
-
I am just trying to understand how the Round robin works between processes. Quoting from the docs What I understand is that if I run two Node processes and each creates a worker instance using
However, testing it shows different results altogether. In the shared video I have two processes running to process the jobs and then one process adds one job at a time to the queue. I am waiting for 4-5 seconds to ensure that the process which processed the job becomes idle. round-robin-bull.movCode for adding a new jobconst { Queue } = require('bullmq')
const name = process.argv.slice(2)
const videoQueue = new Queue('video transcoding', 'redis://127.0.0.1:6379')
videoQueue.add('wall', { name }) Code for processing the jobconst { Worker } = require('bullmq')
const name = process.argv.slice(2)
console.log(name)
new Worker('video transcoding', function (job) {
console.log(job.data)
console.log({ name })
}) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hmm. But in the video you are starting the workers manually. If you have a fleet of workers online waiting for jobs to arrive to the queue the jobs will be distributed in a round-robin fashion, this comes from the fact that idle workers are waiting for jobs using Redis BRPOPLPUSH command, and Redis do wake up the blocked connections in the same order as they were created (the blocked connection). |
Beta Was this translation helpful? Give feedback.
-
Ok, so the issue is that the default "drainDelay" is too low for this example to behave as you expect. If you change it to 30s it will behave correcty: new Worker(
"video transcoding",
function (job) {
console.log(job.data);
console.log({ name });
},
{ drainDelay: 30 }
); |
Beta Was this translation helpful? Give feedback.
Ok, so the issue is that the default "drainDelay" is too low for this example to behave as you expect. If you change it to 30s it will behave correcty: