From: Jérôme Benoit Date: Wed, 9 Aug 2023 20:06:50 +0000 (+0200) Subject: docs: improve documentation X-Git-Tag: v2.6.22~8 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4f8e444d4f7f3492d7aa09f12ced5a320ab68d30;p=poolifier.git docs: improve documentation Signed-off-by: Jérôme Benoit --- diff --git a/README.md b/README.md index ea23397f..ff51fdb8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -

Node Thread Pool and Cluster Pool :arrow_double_up: :on:

+

Node Thread Pool and Cluster Pool

@@ -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 - -

- Overview - · - Installation - · - Usage - · - Node versions - · - API - · - General guidelines - · - Contribute - · - Team - · - License -

+## 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 diff --git a/benchmarks/README.md b/benchmarks/README.md index 81a6cc79..60f84062 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -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` diff --git a/benchmarks/versus-external-pools/README.md b/benchmarks/versus-external-pools/README.md index 9ad45c3a..1511dcd4 100644 --- a/benchmarks/versus-external-pools/README.md +++ b/benchmarks/versus-external-pools/README.md @@ -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** diff --git a/docs/api.md b/docs/api.md index fdba0f9d..60a0a8be 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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 diff --git a/docs/general-guidelines.md b/docs/general-guidelines.md index 26bc7eda..aa8e1c63 100644 --- a/docs/general-guidelines.md +++ b/docs/general-guidelines.md @@ -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. diff --git a/src/pools/selection-strategies/README.md b/docs/worker-choice-strategies.md similarity index 88% rename from src/pools/selection-strategies/README.md rename to docs/worker-choice-strategies.md index 95eee007..0a066279 100644 --- a/src/pools/selection-strategies/README.md +++ b/docs/worker-choice-strategies.md @@ -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`.