• Stars
    star
    489
  • Rank 89,990 (Top 2 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created almost 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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 14.0.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

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

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.

More Repositories

1

bigcache

Efficient cache for gigabytes of data written in Go.
Go
7,508
star
2

ralph

Ralph is the CMDB / Asset Management system for data center and back office hardware.
Python
2,200
star
3

tipboard

Tipboard - in-house, tasty, local dashboarding system
JavaScript
1,106
star
4

php-protobuf

PHP Protobuf - Google's Protocol Buffers for PHP
PHP
911
star
5

allRank

allRank is a framework for training learning-to-rank neural models based on PyTorch.
Python
842
star
6

hermes

Fast and reliable message broker built on top of Kafka.
Java
808
star
7

turnilo

Business intelligence, data exploration and visualization web application for Druid, formerly known as Swiv and Pivot
TypeScript
725
star
8

axion-release-plugin

Gradle release & version management plugin.
Groovy
556
star
9

typescript-strict-plugin

Typescript plugin that allows turning on strict mode in specific files or directories.
TypeScript
337
star
10

json-avro-converter

JSON to Avro conversion tool designed to make migration to Avro easier.
Groovy
275
star
11

embedded-elasticsearch

Tool that ease up creation of integration tests with Elasticsearch
Java
269
star
12

vaas

VaaS
Python
229
star
13

grunt-maven-plugin

Grunt + Maven integration done right
Java
213
star
14

allegro-api

Issue tracker and wiki for Allegro REST API
212
star
15

tradukisto

A Java i18n library created to convert numbers to their word representations.
Groovy
203
star
16

marathon-consul

Integrates Marathon apps with Consul service discovery.
Go
190
star
17

restapi-guideline

Allegro REST API Guideline.
CSS
183
star
18

bigflow

A Python framework for data processing on GCP.
Python
116
star
19

handlebars-spring-boot-starter

Spring Boot auto-configuration for Handlebars
Groovy
109
star
20

envoy-control

Envoy Control is a platform-agnostic, production-ready Control Plane for Service Mesh based on Envoy Proxy.
Kotlin
98
star
21

akubra

Simple solution to keep a independent S3 storages in sync
Go
86
star
22

elasticsearch-analysis-morfologik

Morfologik Polish Lemmatizer plugin for Elasticsearch
Java
83
star
23

ecto-cursor-based-stream

Elixir library that allows for cursor-based streaming of Ecto records, that does not require database transaction.
Elixir
81
star
24

allms

A versatile and powerful library designed to streamline the process of querying LLMs
Python
70
star
25

opel

OPEL - asynchronous expression language
Java
68
star
26

HerBERT

HerBERT is a BERT-based Language Model trained on Polish Corpora using only MLM objective with dynamic masking of whole words.
64
star
27

fogger

Fogger - a library to create blurred background under Android's UI elements
Java
60
star
28

mesos-executor

Customizable Apache Mesos task executor
Go
49
star
29

json-logic-kmp

Kotlin multiplatform JsonLogic expressions evaluation engine. Targets iOS and JVM (also Android).
Kotlin
49
star
30

elasticsearch-reindex-tool

Elasticsearch reindexing tool.
Java
45
star
31

selena

SELENA is a tool used to test website performance by measuring response times or verifying the content of replies.
JavaScript
45
star
32

kafka-offset-monitor-graphite

Graphite reporter for Kafka Offset Monitor.
Scala
44
star
33

dotnet-utils

C#
37
star
34

cassandra-modeling-kata

Cassandra Modeling Kata
Java
36
star
35

mongo-migration-stream

Tool for online migrations of MongoDB databases.
Kotlin
33
star
36

swift-junit

A Swift library for creating JUnit XML test results that can be interpreted by tools such as Bamboo or Jenkins. Macos and Linux ready.
Swift
29
star
37

slinger

Slinger - deep linking library for Android
Java
29
star
38

django-powerdns-dnssec

Django application managing PowerDNS database
Python
27
star
39

ralph-cli

Command-line interface for the Ralph system.
Go
26
star
40

allegro.tech

TypeScript
23
star
41

hacktoberfest-dashboard

Allegro Hactoberfest activity dashboard
TypeScript
23
star
42

klejbenchmark-baselines

Fine-tuning scripts for evaluating transformer-based models on KLEJ benchmark.
Python
23
star
43

quanta

Fast image optimization as a service, based on mozjpeg, written in Swift
C
21
star
44

bigcache-bench

Benchmarks for BigCache project
Go
20
star
45

pyhermes

The Python interface to the Hermes message broker.
Python
19
star
46

swiftbox

SwiftBox is a package that helps building Swift/Vapor microservices.
Swift
19
star
47

consul-registration-hook

Hook that can be used for synchronous registration and deregistration in Consul discovery service on Kubernetes or Mesos cluster with Allegro executor
Go
18
star
48

marathon-appcop

Marathon applications law enforcement
Go
18
star
49

leader-only-spring-boot-starter

Java
17
star
50

newrelic-gradle-plugin

Newrelic Gradle plugin.
Groovy
17
star
51

map-with-indifferent-access

Elixir
17
star
52

grunt-maven-npm

npm tasks for grunt-maven-plugin 1.2+
JavaScript
16
star
53

redux-storage-decorator-engines

Composing decorator for redux-storage to use different storage types
JavaScript
15
star
54

spunit

Spunit – Spock elegance in Kotlin JUnit 5 tests
Kotlin
14
star
55

cosmosdb-utils

A collection of useful Azure CosmosDb SDK v3 extensions and utilities, developed as part of Allegro Pay product.
C#
13
star
56

envoy-perf-pprof

Convenient Envoy on-CPU performance analysis with perf and pprof.
Dockerfile
13
star
57

dotnet-sdk

C#
12
star
58

prometheus-net-metrics

C#
12
star
59

camus-compressor

Camus Compressor merges files created by Camus and saves them in a compressed format.
Java
12
star
60

blog

HTML
11
star
61

consul-recipes

Java library for interacting with Consul.
Java
11
star
62

ralph_pricing

A pricing module for Ralph
Python
11
star
63

solr-fast-collapsing-query-parser

Java
9
star
64

klejbenchmark-allegroreviews

Allegro Reviews is a sentiment analysis dataset, consisting of 11,588 product reviews written in Polish and extracted from Allegro.pl - a popular e-commerce marketplace.
9
star
65

inkpy-jinja

Generate PDF documents from ODT templates.
Python
8
star
66

allegro-tech-labs-microservices

Allegro Tech Labs Microservices workshop materials
Java
8
star
67

TypedListAdapter

Kotlin
7
star
68

logextractx

Python
7
star
69

django-bob

Django bob is a set of django helpers, widgets and form filters for Ralph DCIM/CMDB project .
JavaScript
7
star
70

solr-ids-export-plugin

Java
6
star
71

toper

PHP Rest client based on popular Guzzle Rest Client.
PHP
6
star
72

atm-event-app

ATM event application
JavaScript
5
star
73

application-insights

5
star
74

graphql-extended-audit-intstrumentation

Java
5
star
75

votakvot

Python
5
star
76

banana-split

JavaScript
5
star
77

conformal-prediction-wut

Jupyter Notebook
5
star
78

AlleNoise

Python
4
star
79

warsztaty-podstawy-ml-03-2019

Machine learning basics workshop
Jupyter Notebook
4
star
80

selena-agent

Agent for Selena
Python
4
star
81

json-cache

Java
3
star
82

swiftbox-config

Swift
3
star
83

vaas-registration-hook

Go
3
star
84

braincode

HTML
3
star
85

oauth-mock

Kotlin
3
star
86

parallel-test-execution-workshop

Resources for Parallel test execution workshop
Groovy
3
star
87

swiftbox-metrics-statsd

Swift
2
star
88

atm-hero-generator

JavaScript
2
star
89

client-side-logic-dsl

Kotlin
2
star
90

eslint-plugin-test-comments

TypeScript
2
star
91

couchbase-commons

Kotlin
1
star
92

hermes-page

Hermes OpenSource page.
HTML
1
star
93

ml

TypeScript
1
star
94

swiftbox-logging

Swift
1
star
95

podcast.allegro.tech

CSS
1
star
96

axion-release-example

Kotlin
1
star
97

jobs-conf

allegro.tech jobs postings
HTML
1
star
98

allegro-tech-labs-iot

Allegro Tech Labs IoT workshop materials
Python
1
star
99

versionlens.nvim

1
star