用于后台任务的 NodeJs Bull
NodeJs Bull for Background tasks
我一直在使用 Bull 在我的节点应用程序中执行后台任务。
https://github.com/OptimalBits/bull
现在该节点本质上是单线程的。 bull 使用与节点应用程序 运行 相同的线程还是分叉另一个线程并作为单独的实例运行?
来自大牛快速指南:
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.
要使用此功能,只需使用处理器创建一个单独的文件:
// processor.js
module.exports = function(job){
// Do some heavy work
return Promise.resolve(result);
}
并像这样定义处理器:
// 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。这表明,bull 自然不会创建单独的执行过程。
我一直在使用 Bull 在我的节点应用程序中执行后台任务。
https://github.com/OptimalBits/bull
现在该节点本质上是单线程的。 bull 使用与节点应用程序 运行 相同的线程还是分叉另一个线程并作为单独的实例运行?
来自大牛快速指南:
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.
要使用此功能,只需使用处理器创建一个单独的文件:
// processor.js
module.exports = function(job){
// Do some heavy work
return Promise.resolve(result);
}
并像这样定义处理器:
// 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。这表明,bull 自然不会创建单独的执行过程。