All Projects → allegro → Node Worker Nodes

allegro / Node Worker Nodes

Licence: apache-2.0
A node.js library to run cpu-intensive tasks in a separate processes and not block the event loop.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Worker Nodes

Kudo
Kubernetes Universal Declarative Operator (KUDO)
Stars: ✭ 849 (+81.41%)
Mutual labels:  hacktoberfest, cluster
Orcinus
Agnostic Orchestration Tools
Stars: ✭ 17 (-96.37%)
Mutual labels:  workers, cluster
Node Cluster Email
📨 send email if node cluster throw exception
Stars: ✭ 60 (-87.18%)
Mutual labels:  workers, cluster
Dbfs
Distributed Blockchain-based File Storage 📡
Stars: ✭ 45 (-90.38%)
Mutual labels:  hacktoberfest, cluster
Polaris
Validation of best practices in your Kubernetes clusters
Stars: ✭ 2,397 (+412.18%)
Mutual labels:  hacktoberfest, cluster
terraform-aws-eks-workers
Terraform module to provision an AWS AutoScaling Group, IAM Role, and Security Group for EKS Workers
Stars: ✭ 82 (-82.48%)
Mutual labels:  cluster, workers
Oq Engine
OpenQuake's Engine for Seismic Hazard and Risk Analysis
Stars: ✭ 207 (-55.77%)
Mutual labels:  hacktoberfest, cluster
Kube No Trouble
Easily check your cluster for use of deprecated APIs
Stars: ✭ 280 (-40.17%)
Mutual labels:  hacktoberfest, cluster
Cookiecutter Django Vue
Cookiecutter Django Vue is a template for Django-Vue projects.
Stars: ✭ 462 (-1.28%)
Mutual labels:  hacktoberfest
Json Viewer
A JSON viewer plugin for Notepad++. Displays the selected JSON string in a tree view.
Stars: ✭ 464 (-0.85%)
Mutual labels:  hacktoberfest
Web App
Dictionary database with future API and bot integrations
Stars: ✭ 461 (-1.5%)
Mutual labels:  hacktoberfest
Net6 Mobile Samples
Xamarin .NET 6 *early* preview. Not for production use.
Stars: ✭ 445 (-4.91%)
Mutual labels:  hacktoberfest
Typescript Language Server
TypeScript & JavaScript Language Server
Stars: ✭ 462 (-1.28%)
Mutual labels:  hacktoberfest
Xenon
The MySQL Cluster Autopilot Management with GTID and Raft
Stars: ✭ 461 (-1.5%)
Mutual labels:  cluster
Wp Cli
⚙️ WP-CLI framework
Stars: ✭ 4,474 (+855.98%)
Mutual labels:  hacktoberfest
Node I18n Iso Countries
i18n for ISO 3166-1 country codes
Stars: ✭ 461 (-1.5%)
Mutual labels:  hacktoberfest
Ruby Next
Ruby Next makes modern Ruby code run in older versions and alternative implementations
Stars: ✭ 460 (-1.71%)
Mutual labels:  hacktoberfest
Default
Modern interface to UserDefaults + Codable support
Stars: ✭ 466 (-0.43%)
Mutual labels:  hacktoberfest
Laravel Medialibrary
Associate files with Eloquent models
Stars: ✭ 4,743 (+913.46%)
Mutual labels:  hacktoberfest
Polaris
A cross-platform, minimalist web framework for PowerShell
Stars: ✭ 464 (-0.85%)
Mutual labels:  hacktoberfest

view on npm Build Status

worker-nodes

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 11.7.0 is required

API Reference

WorkerNodes

Kind: global class

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

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

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

Example results:

results for 100 executions

name                time: total [ms]  time usr [ms]  time sys [ms]  worker usr [ms]  worker sys [ms]  mem rss [MB]  worker rss [MB]  errors
------------------  ----------------  -------------  -------------  ---------------  ---------------  ------------  ---------------  ------
no-workers                       148            203             37                0                0            98                0       0
[email protected]               362            390            143              389              143           213              210       0
[email protected]                 367            495            185              492              182           236              245       0
[email protected]              1095            520            207              592              243           216               86       0
[email protected]               1886            749            276              947              299           221               70       0
[email protected]              2002            847            285              986              309           219               74       0
[email protected]              13775           7129           5236             1891              952           363               63       0

  os : Darwin / 19.5.0 / x64
 cpu : Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz × 4
node : 14.3.0 / v8: 8.1.307.31-node.33

See also

sources of inspiration:

License

Copyright Allegro Sp. z o.o.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].