SUCHMOKUO / node-worker-threads-pool

Simple worker threads pool using node's worker_threads module.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Difference between `staticPool` & `dynamicPool`?

LeMoussel opened this issue · comments

I don't quite understand the difference between staticPool & dynamicPool.
Can you explain in more detail? staticPool vs dynamicPool.?

thank you.

commented

Hi!

The main difference is that every worker in a StaticPool can only do the same task while every worker in a DynamicPool can do different tasks.

For example:

If you create a StaticPool with task T1 (task can be a function or a worker file), every worker in that pool will have the exactly same logic, they all do the task T1, and for the worker, the task is immutable, that's why it's called 'static'.

However, if you need a thead pool to process different tasks, like different heavy calculation functions, using a StaticPool is inconvenient. So that's why you need DynamicPool.

'dynamic' means each worker in the pool can execute different task (function). You can tell the difference between the 'exec' method of staticPool and dynamicPool, you can pass a function to the 'exec' method of a dynamicPool, so that the pool will choose a worker to execute the function you passed, and the function you passed can be different, so, that means you can do different tasks in the same pool.

Hope it helps. :)

Thank you for your help :)

It would be really nice if you could add this directly to the readme :)

awesomelib

Hello @SUCHMOKUO as at version 1.5.1 (now) is the following still true?

'dynamic' means each worker in the pool can execute different task (function). You can tell the difference between the 'exec' method of staticPool and dynamicPool, you can pass a function to the 'exec' method of a dynamicPool, so that the pool will choose a worker to execute the function you passed, and the function you passed can be different, so, that means you can do different tasks in the same pool.

it looks to me like the arguments to exec for both static and dynamic pools are the same.