Merge pull request #153 from pioardi/add-worker-test
[poolifier.git] / README.md
index e42597d7289efcbb638ac802edc5d041b070fce7..ad01a6eea95c36911ca02150f4c7fa6f032e471d 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,19 +1,30 @@
-# Node Thread Pool :arrow_double_up: :on:
-
-[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
-[![Dependabot](https://badgen.net/dependabot/dependabot/dependabot-core/?icon=dependabot)](https://badgen.net/dependabot/dependabot/dependabot-core/?icon=dependabot)
-[![npm w](https://img.shields.io/npm/dw/poolifier)](https://www.npmjs.com/package/poolifier)
-[![Actions Status](https://github.com/pioardi/node-pool/workflows/NodeCI/badge.svg)](https://github.com/pioardi/node-pool/actions)
-[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=alert_status)](https://sonarcloud.io/dashboard?id=pioardi_poolifier)
- [![SonarCloud Coverage](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=coverage)](https://sonarcloud.io/component_measures/metric/coverage/list?id=pioardi_poolifier)
-[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
-[![NODEP](https://img.shields.io/static/v1?label=dependencies&message=no%20dependencies&color=brightgreen)](https://img.shields.io/static/v1?label=dependencies&message=no%20dependencies&color=brightgreen)
-[![Gitter](https://badges.gitter.im/poolifier/community.svg)](https://gitter.im/poolifier/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
-
 <div align="center">
-<img src="./docs/logo.png" width="250" height="300"/>
+<img src="./docs/logo.png" width="475" height="400"/>
 </div>
 
+<h2 align="center">Node Thread Pool :arrow_double_up: :on:</h2>
+
+<p align="center">
+  <a href="https://www.npmjs.com/package/poolifier">
+    <img alt="Weekly Downloads" src="https://img.shields.io/npm/dw/poolifier"></a>
+  <a href="https://github.com/pioardi/node-pool/actions">
+    <img alt="Actions Status" src="https://github.com/pioardi/node-pool/workflows/NodeCI/badge.svg"></a>
+  <a href="https://sonarcloud.io/dashboard?id=pioardi_poolifier">
+    <img alt="Quality Gate Status" src="https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=alert_status"></a>
+  <a href="https://sonarcloud.io/component_measures/metric/coverage/list?id=pioardi_poolifier">
+    <img alt="Code coverage" src="https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=coverage"></a>
+  <a href="https://standardjs.com">
+    <img alt="Javascript Standard Style Guide" src="https://img.shields.io/badge/code_style-standard-brightgreen.svg"></a>
+  <a href="https://gitter.im/poolifier/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge">
+    <img alt="Gitter chat" src="https://badges.gitter.im/poolifier/community.svg"></a>
+  <a href="https://badgen.net/dependabot/dependabot/dependabot-core/?icon=dependabot">
+    <img alt="Dependabot" src="https://badgen.net/dependabot/dependabot/dependabot-core/?icon=dependabot"></a>
+  <a href="http://makeapullrequest.com">
+    <img alt="PR Welcome" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square"></a>
+  <a href="https://img.shields.io/static/v1?label=dependencies&message=no%20dependencies&color=brightgreen">
+    <img alt="No dependencies" src="https://img.shields.io/static/v1?label=dependencies&message=no%20dependencies&color=brightgreen"></a>
+</p>
+
 ## Why Poolifier?
 
 Poolifier is used to perform heavy CPU bound tasks on nodejs servers, it implements thread pools (yes, more thread pool implementations, so you can choose which one fit better for you) using [worker-threads](https://nodejs.org/api/worker_threads.html#worker_threads_worker_threads).  
@@ -22,23 +33,23 @@ Moreover you can execute your CPU tasks using an API designed to improve the **d
 
 - Performance :racehorse:
 - Security :bank: :cop: [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=security_rating)](https://sonarcloud.io/dashboard?id=pioardi_poolifier) [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=pioardi_poolifier)
-
-- No runtime dependencies :heavy_check_mark: (until now we don't have any expectations to add some)- Easy to use :couple:
+- Easy to use :couple:
+- Easy switch from a pool to another, easy to tune :heavy_check_mark:
+- Dynamic pool size :heavy_check_mark:
+- No runtime dependencies :heavy_check_mark:
+- Proper async integration with node async hooks :heavy_check_mark:
+- Support for worker threads and cluster node modules :heavy_check_mark:
+- Support sync and async tasks :heavy_check_mark:
+- General guidance on pools to use :heavy_check_mark:
+- Widely tested :heavy_check_mark:
+- Error handling out of the box :heavy_check_mark:
+- Active community :heavy_check_mark:
 - Code quality :octocat: [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=bugs)](https://sonarcloud.io/dashboard?id=pioardi_poolifier)
-[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=code_smells)](https://sonarcloud.io/dashboard?id=pioardi_poolifier)
-[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=pioardi_poolifier)
-[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=pioardi_poolifier)
-[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=pioardi_poolifier)
-[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=sqale_index)](https://sonarcloud.io/dashboard?id=pioardi_poolifier)
-- Easy switch from a pool to another, easy to tune
-- Dynamic pool size
-- Proper async integration with node async hooks
-- Support for worker threads and cluster node modules
-- Active community
-- Support sync and async tasks
-- General guidance on pools to use
-- Widely tested
-- Error handling out of the box 
+  [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=code_smells)](https://sonarcloud.io/dashboard?id=pioardi_poolifier)
+  [![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=pioardi_poolifier)
+  [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=pioardi_poolifier)
+  [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=pioardi_poolifier)
+  [![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=sqale_index)](https://sonarcloud.io/dashboard?id=pioardi_poolifier)
 
 ## Contents
 
@@ -163,8 +174,18 @@ This method will call the terminate method on each worker.
 `fn` (mandatory) The function that you want to execute on the worker thread  
 `opts` (optional) An object with these properties:
 
-- `maxInactiveTime` - Max time to wait tasks to work on ( in ms) , after this period the new worker threads will die.
+- `maxInactiveTime` - Max time to wait tasks to work on (in ms), after this period the new worker threads will die.  
+The last active time of your worker unit will be updated when a task is submitted to a worker or when a worker terminate a task.  
+If `killBehavior` is set to `KillBehaviors.HARD` this value represents also the timeout for the tasks that you submit to the pool, when this timeout expires your tasks is interrupted and the worker is killed if is not part of the minimum size of the pool.  
+If `killBehavior` is set to `KillBehaviors.SOFT` your tasks have no timeout and your workers will not be terminated until your task is completed.  
+Default: 60.000 ms
+
 - `async` - true/false, true if your function contains async pieces else false
+- `killBehavior` - Dictates if your async unit (worker/process) will be deleted in case that a task is active on it.  
+**SOFT**: If `currentTime - lastActiveTime` is greater than `maxInactiveTime` but a task is still running, then the worker **wont** be deleted.  
+**HARD**: If `lastActiveTime` is greater than `maxInactiveTime` but a task is still running, then the worker will be deleted.  
+This option only apply to the newly created workers.  
+Default: `SOFT`
 
 ## Choose your pool