493 sao GitHub và vẫn tăng — allegro/node-worker-nodes là dự án JavaScript mà TopGit đang theo dõi trên nền tảng. A node.js library to run cpu-intensive tasks in a separate processes and not block the event loop.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
A node.js library to run cpu-intensive tasks in a separate processes and to not to block the event loop.
Installation
$ npm install worker-nodes
Node.js greater than 14.0.0 is required
API Reference
WorkerNodes
Kind: global class
WorkerNodes
new WorkerNodes(path, [options])
.call : Proxy
.ready() ⇒ Promise
.terminate() ⇒ Promise
.profiler(duration) ⇒ void
.takeSnapshot() ⇒ void
.getUsedWorkers() ⇒ Array.<Worker>
new WorkerNodes(path, [options])
Param
Type
Description
path
String
An absolute path to the module that will be run in the workers.
[options]
Object
See WorkerNodesOptions for a detailed description.
workerNodes.call : Proxy
This exposes the api of a module that the worker nodes are working on. If the module is a function, you
can call this directly. If the module exports multiple functions, you can call them as they were properties
of this proxy.
Kind: instance property of WorkerNodes
workerNodes.ready() ⇒ Promise
A method to check if the minimum required number of workers are ready to serve the calls.
Kind: instance method of WorkerNodes Returns: Promise - resolves with a WorkerNodes instance
workerNodes.terminate() ⇒ Promise
Starts the process of terminating this instance.
Kind: instance method of WorkerNodes Returns: Promise - - resolved when the instance is terminated.
workerNodes.profiler(duration) ⇒ void
Run CPU Profiler and save result on main process directory
Kind: instance method of WorkerNodes
Param
Type
duration
number
workerNodes.takeSnapshot() ⇒ void
Take Heap Snapshot and save result on main process directory
Kind: instance method of WorkerNodes
workerNodes.getUsedWorkers() ⇒ Array.<Worker>
Return list with used workers in pool
Kind: instance method of WorkerNodes
WorkerNodesOptions
Describes a WorkerNodes options.
Kind: global class
WorkerNodesOptions
.autoStart : Boolean
.lazyStart : Boolean
.asyncWorkerInitialization : Boolean
.minWorkers : Number
.maxWorkers : Number
.maxTasks : Number
.maxTasksPerWorker : Number
.taskTimeout : Number
.taskMaxRetries : Number
.workerEndurance : Number
.workerStopTimeout : Number
.resourceLimits : Object
.workerType : string
options.autoStart : Boolean
Whether should initialize the workers before a first call.
If true, depending on the lazyStart option, it will start the
min or max number of workers.
Kind: instance property of WorkerNodesOptions Default: false
options.lazyStart : Boolean
Whether should start a new worker only if all the others are busy.
Kind: instance property of WorkerNodesOptions Default: false
options.asyncWorkerInitialization : Boolean
Enables async initialization of worker.
To start handling task over worker, need to invoke sendWorkerMessage('ready') function when it fully initialized.
For examples please refer to the test cases
Kind: instance property of WorkerNodesOptions Default: false
options.minWorkers : Number
The minimum number of workers that needs to be running to consider the whole pool as operational.
Kind: instance property of WorkerNodesOptions Default: 0
options.maxWorkers : Number
The maximum number of workers that can be running at the same time.
Defaults to the number of cores the operating system sees.
Kind: instance property of WorkerNodesOptions
options.maxTasks : Number
The maximum number of calls that can be handled at the same time.
Exceeding this limit causes MaxConcurrentCallsError to be thrown.
Kind: instance property of WorkerNodesOptions Default: Infinity
options.maxTasksPerWorker : Number
The number of calls that can be given to a single worker at the same time.
Kind: instance property of WorkerNodesOptions Default: 1
options.taskTimeout : Number
The number milliseconds after which a call is considered to be lost.
Exceeding this limit causes TimeoutError to be thrown and a worker that performed that task to be killed.
Kind: instance property of WorkerNodesOptions Default: Infinity
options.taskMaxRetries : Number
The maximum number of retries that will be performed over a task before reporting it as incorrectly terminated.
Exceeding this limit causes ProcessTerminatedError to be thrown.
Kind: instance property of WorkerNodesOptions Default: 0
options.workerEndurance : Number
The maximum number of calls that a single worker can handle during its whole lifespan.
Exceeding this limit causes the termination of the worker.
Kind: instance property of WorkerNodesOptions Default: Infinity
options.workerStopTimeout : Number
The timeout value (in milliseconds) for the worker to stop before sending SIGKILL.
Kind: instance property of WorkerNodesOptions Default: 100
options.resourceLimits : Object
Provides the set of JS engine resource constraints inside this Worker thread. (Usable when using workerType: thread only)
Kind: instance property of WorkerNodesOptions Properties
Name
Type
Description
maxYoungGenerationSizeMb
Number
The maximum size of a heap space for recently created objects
maxOldGenerationSizeMb
Number
The maximum size of the main heap in MB
codeRangeSizeMb
Number
The size of a pre-allocated memory range used for generated code
stackSizeMb
Number
The default maximum stack size for the thread. Small values may lead to unusable Worker instances
options.workerType : string
Can be either process or thread (default), that controls the underlying implementation used, either child_process or worker_threads.
Most usecases are perfectly fine with thread implementation, some work loads though, might need to use process, for example, if you are using
process.chdir() call which is not supported in worker_threads.
Example
Given /home/joe.doe/workspace/my-module.js:
module.exports = function myTask() {
return 'hello from separate process!';
};
you can run it through the worker nodes as follows:
const WorkerNodes = require('worker-nodes');
const myModuleWorkerNodes = new WorkerNodes('/home/joe.doe/workspace/my-module');
myModuleWorkerNodes.call().then(msg => console.log(msg)); // -> 'hello from separate process!'
For more advanced examples please refer to the test cases.
Running tests
Check out the library code and then:
$ npm install
$ npm test
Benchmarks
To run tests, type:
$ npm install
$ npm run benchmark
It will run a performance test against the selected libraries:
data in: an object that consists of a single field that is a 0.5MB random string
data out: received object stringified and concatenated with another 1MB string
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
allegro/node-worker-nodes có 493 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/allegro/node-worker-nodes. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
allegro/node-worker-nodes có phải mã nguồn mở không?
Có — allegro/node-worker-nodes phát hành theo license Apache-2.0, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/allegro/node-worker-nodes.
allegro/node-worker-nodes còn đang phát triển không?
Commit gần nhất trên allegro/node-worker-nodes là 2.2 năm trước (theo timestamp GitHub). Repo có 32 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
allegro/node-worker-nodes là gì?
allegro/node-worker-nodes (allegro/node-worker-nodes) là dự án JavaScript trên GitHub. Theo mô tả gốc: A node.js library to run cpu-intensive tasks in a separate processes and not block the event loop.
allegro/node-worker-nodes so với các dự án Backend khác thế nào?
allegro/node-worker-nodes được TopGit xếp vào nhóm Backend, với 493 sao GitHub và viết bằng JavaScript. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc thêm về allegro/node-worker-nodes ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/allegro/node-worker-nodes là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
node-worker-nodes có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về node-worker-nodes.