Answer the question
In order to leave comments, you need to log in
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
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.
You can run a child process in which to perform heavy tasks without blocking the main one.
Documentation
In addition to the above, nodejs has recently introduced an experimental ability to run code in separate threads, called Worker Threads .
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.
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 questionAsk a Question
731 491 924 answers to any question