F
F
ff0xff2019-06-17 11:23:43
Node.js
ff0xff, 2019-06-17 11:23:43

Run tasks in separate threads on nodejs while maintaining the maximum number of threads, what are the solutions?

Good day dear friends.
Let's take a look at the diagram right away.
5d074b5d83f6e085378047.png
I have a large pool of different tasks that need to be solved in parallel.
Each task can run for a different amount of time.
The first solution was simple, we create a pool of tasks, wait for the completion of all tasks, and so on in a circle.
But the problem is that there are tasks that are solved quite quickly, for example, in 3 seconds. and there are those that are solved slowly, for example, in 120 seconds. it turns out that until the last task is solved, the new pool will not be processed. I really want to get rid of this.
The following requirements must be met.


  1. It should be possible to specify how many child processes we can create.
  2. We need to get the status of the response from the process (for example was it successful or not) - something very simple like bool type.
  3. We need the ability to crash the process if it works more than n of the specified time (for example, it freezes)
  4. Upon completion of one process (successfully or crashed), a new process should start with the next task.

What are nodejs solutions for es6 that meet all 4 conditions?
Does anyone have good examples of such tasks?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Shumov, 2019-06-17
@ff0xff

As a result - queues, any) there is a whole directory, if necessary . I'm rooting for RabbitMQ in most cases

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question