R
R
Richard Hendrix2018-12-19 19:22:24
Node.js
Richard Hendrix, 2018-12-19 19:22:24

What ways do you know of doing heavy tasks with node.js?

What methods/tricks/maneuvers/life hacks do you know of performing heavy tasks (like iterating over large loops) without blocking the event loop, that is, asynchronously, in NODE.JS?

Answer the question

In order to leave comments, you need to log in

7 answer(s)
A
Anatoly Zharov, 2018-12-19
@SeaBreeze876

The most obvious thing is not to use nodejs for tasks like this, it's purely for IO. You can put a service side by side that does not suffer from single-threading problems and use rpc.

A
Alexey Laud, 2018-12-20
@kshshe

You can run a child process in which to perform heavy tasks without blocking the main one.
Documentation

A
Alexey, 2018-12-20
@MAKAPOH

In addition to the above, nodejs has recently introduced an experimental ability to run code in separate threads, called Worker Threads .

A
Anton Shvets, 2018-12-20
@Xuxicheta

And finally, in addition to the above
process.nextTick()

M
McBernar, 2018-12-20
@McBernar

Workers.
Or just the second node.

A
Andrew, 2018-12-27
@iCoderXXI

The node is not for calculations, or it’s smart to split up and call individual fragments via setTimeout, which is still a crutch and the logic will be like noodles, or colleagues have already advised above.

P
Pavel Volintsev, 2019-03-04
@copist

Use the job queue
1. NodeJS accepts the job (HTTP POST request with parameters), transfers service information to the queue (Apache Kafka, RabbitMQ) 2. The executor
retrieves the job, processes it, sends a completion
notification.
resource-intensive operations are best done in compiled languages, that is, C ++, Erlang, GoLang

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question