docs: improve documentation
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 9 Aug 2023 20:06:50 +0000 (22:06 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 9 Aug 2023 20:06:50 +0000 (22:06 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
README.md
benchmarks/README.md
benchmarks/versus-external-pools/README.md
docs/api.md
docs/general-guidelines.md
docs/worker-choice-strategies.md [moved from src/pools/selection-strategies/README.md with 88% similarity]

index ea23397fdf2f3f9a0a5fe2a40ad4035a639b370a..ff51fdb8eebf1a558c2f8eaecfcf3da06a9693f5 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 Thread Pool and Cluster Pool</h1>
 
 <p align="center">
   <a href="https://github.com/poolifier/poolifier/graphs/commit-activity">
@@ -57,27 +57,18 @@ Please consult our [general guidelines](#general-guidelines).
   [![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-guidelines">General guidelines</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 versions](#node-versions)
+- [API](#api)
+- [General guidelines](#general-guidelines)
+- [Worker choice strategies](#worker-choice-strategies)
+- [Contribute](#contribute)
+- [Team](#team)
+- [License](#license)
 
 ## Overview
 
@@ -160,7 +151,9 @@ Node versions >= 16.14.x are supported.
 
 ## [API](./docs/api.md)
 
-## [General Guidelines](./docs/general-guidelines.md)
+## [General guidelines](./docs/general-guidelines.md)
+
+## [Worker choice strategies](./docs/worker-choice-strategies.md)
 
 ## Contribute
 
index 81a6cc7919a9233bafdda94962ac02f692983f96..60f84062175b2efa99f6be19f111ad434efc4b5a 100644 (file)
@@ -36,10 +36,8 @@ We chose to use this tool because it allows to run isolated Node.js processes so
 
 > :warning: **We would need funds to run our benchmarks more often and on Cloud VMs, please consider to sponsor this project**
 
-### Internal
+Read [README.md](./versus-external-pools/README.md) to know how to run the benchmarks.
 
-To run the internal benchmarks, you just need to navigate to the root of poolifier project and run `pnpm benchmark`
-
-## Versus other pools
+## Internal
 
-Read [README.md](./versus-external-pools/README.md)
+To run the internal benchmarks, you just need to navigate to the root of poolifier project and run `pnpm benchmark`
index 9ad45c3a081e585f3cd8989aa83da7b3a382eae8..1511dcd4d3b756e51e28d84daaaca06cb2656d88 100644 (file)
@@ -6,4 +6,4 @@ To run the benchmark versus other pools you will need to:
 - Run `pnpm install` into the `versus-external-pools` folder
 - Run the `./bench.sh` script into the `versus-external-pools` folder
 
-> :warning: **Please be sure to use a quite PC when you run the benchmarks**
+> :warning: **Please be sure to use a quiet PC when you run the benchmarks**
index fdba0f9d1077e408d730007c9be341f5b629be31..60a0a8be08194bc201b4d248d827ca1155a9bf72 100644 (file)
@@ -1,4 +1,19 @@
-## [API](https://poolifier.github.io/poolifier/)
+# [API](https://poolifier.github.io/poolifier/)
+
+## Table of contents
+
+- [Pool](#pool)
+  - [`pool = new FixedThreadPool/FixedClusterPool(numberOfThreads/numberOfWorkers, filePath, opts)`](#pool--new-fixedthreadpoolfixedclusterpoolnumberofthreadsnumberofworkers-filepath-opts)
+  - [`pool = new DynamicThreadPool/DynamicClusterPool(min, max, filePath, opts)`](#pool--new-dynamicthreadpooldynamicclusterpoolmin-max-filepath-opts)
+  - [`pool.execute(data, name)`](#poolexecutedata-name)
+  - [`pool.destroy()`](#pooldestroy)
+  - [`PoolOptions`](#pooloptions)
+    - [``ThreadPoolOptions extends PoolOptions`](#threadpooloptions-extends-pooloptions)
+    - [`ClusterPoolOptions extends PoolOptions`](#clusterpooloptions-extends-pooloptions)
+- [Worker](#worker)
+  - [`class YourWorker extends ThreadWorker/ClusterWorker`](#class-yourworker-extends-threadworkerclusterworker)
+
+## Pool
 
 ### `pool = new FixedThreadPool/FixedClusterPool(numberOfThreads/numberOfWorkers, filePath, opts)`
 
@@ -80,6 +95,8 @@ An object with these properties:
 
 - `settings` (optional) - An object with the cluster settings. See [cluster](https://nodejs.org/api/cluster.html#cluster_cluster_settings) for more details.
 
+## Worker
+
 ### `class YourWorker extends ThreadWorker/ClusterWorker`
 
 `taskFunctions` (mandatory) The task function or task functions object `{ name_1: fn_1, ..., name_n: fn_n }` that you want to execute on the worker  
index 26bc7eda2d909b0ef40aa34d2494a1f766628c85..aa8e1c636ccb03e216d356f30ca151ee47a7f243 100644 (file)
@@ -1,9 +1,15 @@
-## General Guidelines
+# General guidelines
 
 Performance is one of the main target of these worker pool implementations, poolifier team wants to have a strong focus on this.  
 Poolifier already has a [benchmarks](./benchmarks/) folder where you can find some comparisons.
 
-### Internal Node.js thread pool
+## Table of contents
+
+- [Internal Node.js thread pool](#internal-nodejs-thread-pool)
+- [Cluster vs Threads worker pools](#cluster-vs-threads-worker-pools)
+- [Fixed vs Dynamic pools](#fixed-vs-dynamic-pools)
+
+## Internal Node.js thread pool
 
 Before to jump into each poolifier pool type, let highlight that **Node.js comes with a thread pool already**, the libuv thread pool where some particular tasks already run by default.  
 Please take a look at [which tasks run on the libuv thread pool](https://nodejs.org/en/docs/guides/dont-block-the-event-loop/#what-code-runs-on-the-worker-pool).
@@ -16,7 +22,7 @@ and/or
 
 - Use poolifier cluster pools that are spawning child processes, they will also increase the number of libuv threads since that any new child process comes with a separated libuv thread pool. **More threads does not mean more fast, so please tune your application**.
 
-### Cluster vs Threads worker pools
+## Cluster vs Threads worker pools
 
 **If your task does not run into libuv thread pool** and is CPU intensive then poolifier **thread pools** (_FixedThreadPool_ and _DynamicThreadPool_) are suggested to run CPU intensive tasks, you can still run I/O intensive tasks into thread pools, but performance enhancement is expected to be minimal.  
 Thread pools are built on top of Node.js [worker_threads](https://nodejs.org/api/worker_threads.html) module.
@@ -28,7 +34,7 @@ Cluster pools are built on top of Node.js [cluster](https://nodejs.org/api/clust
 If your task contains code that runs on libuv plus code that is CPU intensive or I/O intensive you either split it either combine more strategies (i.e. tune the number of libuv threads and use cluster/thread pools).  
 But in general, **always profile your application**.
 
-### Fixed vs Dynamic pools
+## Fixed vs Dynamic pools
 
 To choose your pool consider first that with a _FixedThreadPool_/_FixedClusterPool_ or a _DynamicThreadPool_/_DynamicClusterPool_ your application memory footprint will increase.  
 By doing so, your application will be ready to execute in parallel more tasks, but during idle time your application will consume more memory.  
similarity index 88%
rename from src/pools/selection-strategies/README.md
rename to docs/worker-choice-strategies.md
index 95eee0079f6bbbb7d4bdb37c7b7cf665c076d1f4..0a06627951661e7c803cc15f5a611ebfaa29b4ce 100644 (file)
@@ -1,9 +1,18 @@
 # Worker choice strategies
 
-All duration or timestamp are expressed in milliseconds.
+## Table of contents
+
+- [Strategies](#strategies)
+  - [Fair share](#fair-share)
+  - [Weighted round robin](#weighted-round-robin)
+  - [Interleaved weighted round robin](#interleaved-weighted-round-robin)
+- [Statistics](#statistics)
+  - [Median](#median)
 
 ## Strategies
 
+All duration or timestamp are expressed in milliseconds.
+
 ### Fair share
 
 Its goal is to distribute the load evenly across all workers. To achieve this, the strategy keeps track of the average task execution time for each worker and assigns the next task to the worker with the lowest task end prediction time: `task_end_prediction = max(current_time, task_end_prediction) + average_task_execution_time`.