1

I have been using Bull for background tasks in my node application.

https://github.com/OptimalBits/bull

Now that node is single threaded by nature. Does bull use the same thread on which node application is running or it forks another thread and runs as a separate instance?

Ijaz Khan
  • 41
  • 1
  • 4

2 Answers2

3

From bull quick guide:

The process function can also be run1 in a separate process. This has several advantages:

  • The process is sandboxed so if it crashes it does not affect the worker.
  • You can run blocking code without affecting the queue (jobs will not stall).
  • Much better utilization of multi-core CPUs.
  • Less connections to redis.

In order to use this feature just create a separate file with the processor:

// processor.js
module.exports = function(job){
  // Do some heavy work

  return Promise.resolve(result);
}

And define the processor like this:

// Single process:
queue.process('/path/to/my/processor.js');

// You can use concurrency as well:
queue.process(5, '/path/to/my/processor.js');

// and named processors:
queue.process('my processor', 5, '/path/to/my/processor.js');

1. This indicates, naturally bull doesn't create separate process for execution.

Basic guides: https://github.com/OptimalBits/bull#separate-processes

some user
  • 1,693
  • 2
  • 14
  • 31
0

No, It will not run in worker thread it will run in main thread so it is recommended not to use blocking code in job.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 10 '23 at 04:14