chore: v2.6.41
[poolifier.git] / README.md
index c708c73e5bec44ba9474f6c5587c5f3ec452f83a..3099709bd3bc41327776d1c89fde26771c455486 100644 (file)
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
   <img src="./images/logo.png" width="340px" height="266px"/>
 </div>
 
-<h2 align="center">Node Thread Pool and Cluster Pool :arrow_double_up: :on:</h2>
+<h1 align="center">Node.js Worker_Threads and Cluster Worker Pool</h1>
 
 <p align="center">
   <a href="https://github.com/poolifier/poolifier/graphs/commit-activity">
 Poolifier is used to perform CPU and/or I/O intensive tasks on Node.js servers, it implements worker pools using [worker_threads](https://nodejs.org/api/worker_threads.html) and [cluster](https://nodejs.org/api/cluster.html) Node.js modules.  
 With poolifier you can improve your **performance** and resolve problems related to the event loop.  
 Moreover you can execute your tasks using an API designed to improve the **developer experience**.  
-Please consult our [general guidelines](#general-guidance).
+Please consult our [general guidelines](#general-guidelines).
 
 - Easy to use :white_check_mark:
-- Performance [benchmarks](./benchmarks/README.md) :white_check_mark:
 - Fixed and dynamic pool size :white_check_mark:
 - Easy switch from a pool type to another :white_check_mark:
+- Performance [benchmarks](./benchmarks/README.md) :white_check_mark:
 - No runtime dependencies :white_check_mark:
-- Proper integration with node [async_hooks](https://nodejs.org/api/async_hooks.html) :white_check_mark:
-- Support CommonJS, ESM, and TypeScript :white_check_mark:
+- Proper integration with Node.js [async_hooks](https://nodejs.org/api/async_hooks.html) :white_check_mark:
+- Support for CommonJS, ESM, and TypeScript :white_check_mark:
 - Support for [worker_threads](https://nodejs.org/api/worker_threads.html) and [cluster](https://nodejs.org/api/cluster.html) Node.js modules :white_check_mark:
-- Support multiple task functions :white_check_mark:
-- Support sync and async task functions :white_check_mark:
+- Support for multiple task functions :white_check_mark:
+- Support for sync and async task functions :white_check_mark:
 - Tasks distribution strategies :white_check_mark:
-- General guidance on pool choice :white_check_mark:
+- Lockless tasks queueing :white_check_mark:
+- Queued tasks rescheduling:
+  - Task stealing :white_check_mark:
+  - Tasks stealing under back pressure :white_check_mark:
+  - Tasks redistribution on worker error :white_check_mark:
+- General guidelines on pool choice :white_check_mark:
 - Error handling out of the box :white_check_mark:
 - Widely tested :white_check_mark:
 - Active community :white_check_mark:
@@ -57,27 +62,18 @@ Please consult our [general guidelines](#general-guidance).
   [![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=sqale_index)](https://sonarcloud.io/dashboard?id=pioardi_poolifier)
 - Code security [![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)
 
-## Contents
-
-<h3 align="center">
-  <a href="#overview">Overview</a>
-  <span> · </span>
-  <a href="#installation">Installation</a>
-  <span> · </span>
-  <a href="#usage">Usage</a>
-  <span> · </span>
-  <a href="#node-versions">Node versions</a>
-  <span> · </span>
-  <a href="#api">API</a>
-  <span> · </span>
-  <a href="#general-guidance">General guidance</a>
-  <span> · </span>
-  <a href="#contribute">Contribute</a>
-  <span> · </span>
-  <a href="#team">Team</a>
-  <span> · </span>
-  <a href="#license">License</a>
-</h3>
+## Table of contents
+
+- [Overview](#overview)
+- [Installation](#installation)
+- [Usage](#usage)
+- [Node.js versions](#nodejs-versions)
+- [API](#api)
+- [General guidelines](#general-guidelines)
+- [Worker choice strategies](#worker-choice-strategies)
+- [Contribute](#contribute)
+- [Team](#team)
+- [License](#license)
 
 ## Overview
 
@@ -119,7 +115,7 @@ const { DynamicThreadPool, FixedThreadPool, PoolEvents, availableParallelism } =
 
 // a fixed worker_threads pool
 const pool = new FixedThreadPool(availableParallelism(), './yourWorker.js', {
-  errorHandler: e => console.error(e),
+  errorHandler: (e) => console.error(e),
   onlineHandler: () => console.info('worker is online')
 })
 
@@ -128,7 +124,7 @@ pool.emitter.on(PoolEvents.busy, () => console.info('Pool is busy'))
 
 // or a dynamic worker_threads pool
 const pool = new DynamicThreadPool(Math.floor(availableParallelism() / 2), availableParallelism(), './yourWorker.js', {
-  errorHandler: e => console.error(e),
+  errorHandler: (e) => console.error(e),
   onlineHandler: () => console.info('worker is online')
 })
 
@@ -137,34 +133,48 @@ pool.emitter.on(PoolEvents.ready, () => console.info('Pool is ready'))
 pool.emitter.on(PoolEvents.busy, () => console.info('Pool is busy'))
 
 // the execute method signature is the same for both implementations,
-// so you can easy switch from one to another
+// so you can easily switch from one to another
 pool
   .execute()
-  .then(res => {
+  .then((res) => {
     console.info(res)
   })
-  .catch(err => {
+  .catch((err) => {
     console.error(err)
   })
 ```
 
 You can do the same with the classes _ClusterWorker_, _FixedClusterPool_ and _DynamicClusterPool_.
 
-**See [examples](./examples/) folder for more details (in particular if you want to use a pool with [multiple task functions](./examples/multiFunctionExample.js))**.
+**See [examples](./examples/) for more details**:
+
+- [Javascript](./examples/javascript/)
+- [Typescript](./examples/typescript/)
+  - [HTTP client pool](./examples/typescript/http-client-pool/)
+  - [SMTP client pool](./examples/typescript/smtp-client-pool/)
+  - [HTTP server pool](./examples/typescript/http-server-pool/)
+    - [Express worker_threads pool](./examples/typescript/http-server-pool/express-worker_threads/)
+    - [Express cluster pool](./examples/typescript/http-server-pool/express-cluster/)
+    - [Express hybrid pool](./examples/typescript/http-server-pool/express-hybrid/)
+    - [Fastify worker_threads pool](./examples/typescript/http-server-pool/fastify-worker_threads/)
+    - [Fastify cluster pool](./examples/typescript/http-server-pool/fastify-cluster/)
+    - [Fastify hybrid pool](./examples/typescript/http-server-pool/fastify-hybrid/)
+  - [WebSocket server pool](./examples/typescript/websocket-server-pool/)
+    - [ws worker_threads pool](./examples/typescript/websocket-server-pool/ws-worker_threads/)
+    - [ws cluster pool](./examples/typescript/websocket-server-pool/ws-cluster/)
+    - [ws hybrid pool](./examples/typescript/websocket-server-pool/ws-hybrid/)
 
 Remember that workers can only send and receive structured-cloneable data.
 
-## Node versions
-
-Node versions >= 16.14.x are supported.
+## Node.js versions
 
-## [API](https://poolifier.github.io/poolifier/)
+Node.js versions >= 16.14.x are supported.
 
-[**API Details**](./docs/api-details.md)
+## [API](./docs/api.md)
 
-## General Guideline
+## [General guidelines](./docs/general-guidelines.md)
 
-For general guidelines, please refer to [this document](./docs/general-guidelines.md)
+## [Worker choice strategies](./docs/worker-choice-strategies.md)
 
 ## Contribute
 
@@ -178,11 +188,14 @@ See [CONTRIBUTING](CONTRIBUTING.md) guidelines.
 
 - [**Alessandro Pio Ardizio**](https://github.com/pioardi)
 
-**_Contributors_**
+**Maintainers:**
 
-- [**Shinigami92**](https://github.com/Shinigami92)
 - [**Jérôme Benoit**](https://github.com/jerome-benoit)
 
+**Contributors:**
+
+- [**Shinigami92**](https://github.com/Shinigami92)
+
 ## License
 
 [MIT](./LICENSE)