Merge dependabot/npm_and_yarn/examples/typescript/http-server-pool/express-hybrid...
[poolifier.git] / docs / worker-choice-strategies.md
CommitLineData
a47027a0
JB
1# Worker choice strategies
2
3All duration or timestamp are expressed in milliseconds.
4
5## Table of contents
6
7- [Strategies](#strategies)
8 - [Fair share](#fair-share)
9 - [Weighted round robin](#weighted-round-robin)
1a28f967 10 - [Interleaved weighted round robin (experimental)](#interleaved-weighted-round-robin-experimental)
a47027a0 11- [Statistics](#statistics)
dc021bcc 12 - [Simple moving median](#simple-moving-median)
a47027a0
JB
13
14## Strategies
15
16### Fair share
17
dc021bcc
JB
18Its goal is to distribute the load evenly across all workers. To achieve this, the strategy keeps track of the simple moving 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) + simple_moving_average_task_execution_time`.
19By default, the strategy uses the simple moving average task execution time for each worker but it can be configured to use the simple moving average task event loop utilization (ELU) active time instead.
a47027a0
JB
20
21### Weighted round robin
22
619f403b 23The worker weights are maximum tasks execution time. Once the worker has reached its maximum tasks execution time, the next task is assigned to the next worker. The default worker weight is the same for each and computed given the CPU cores speed and theirs numbers.
a47027a0 24
619f403b 25### Interleaved weighted round robin (experimental)
a47027a0 26
b808b625 27The worker weights are maximum tasks execution time. The rounds are the deduplicated worker weights in ascending order.
afb97e1d 28During a round, if the worker weight is superior or equal to the current round weight and its tasks execution time is inferior to the current round weight, the task is assigned to the worker. Once all workers weight have been tested, the next round starts.
313f98ac 29The default worker weights is the same for each and computed given the CPU cores speed and theirs numbers. So the default 'rounds' consists of a unique worker weight.
a47027a0
JB
30
31## Statistics
32
33Worker choice strategies enable only the statistics that are needed to choose the next worker to avoid unnecessary overhead.
34
dc021bcc 35### Simple moving median
a47027a0 36
3baa0837 37Strategies using the simple moving average task execution time for each worker can use the simple moving median instead. Simple moving median is more robust to outliers and can be used to avoid assigning tasks to workers that are currently overloaded.