T
T
tiwana62020-02-18 17:19:35
JavaScript
tiwana6, 2020-02-18 17:19:35

How to organize complex calculations in NodeJS?

You need to organize the assembly of the angular application on the server (ssr). The task itself is resource intensive. There are other complex calculations that you don't want to be done on the main thread.

There are options, but all with drawbacks:
- MQ Message broker (Kafka, RabbitMQ). Of the minuses, an overhead for messaging, I would like to instantly give an answer.
- Node Cluster. Here it is not clear how many threads to create? What to do if all threads are busy, but the result is needed?
- Worker threads. Minus - everything is in one thread, calculations are not normally parallelized. How much will it affect the main thread?

Of all the options listed, there is no serious experience anywhere. Would like to hear the opinions of others. Share your experience, how do you solve the problem of complex calculations in NodeJS?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twolegs, 2020-02-18
@twolegs

SSR is not such a difficult task. If it runs for a very long time, then there are questions about optimizing your application.
In general, first of all you need to answer two questions:
1. What load do you expect? How many rps are expected?
2. Have you done any load testing yet? Are you sure that one node instance is not enough for you now?
If the number of requests is large and one instance cannot cope, I would use a couple of node instances using, for example, pm2, which will act as a balancer.
In general, in the case of web development on node, it is not so often that some really complex calculations are performed on the main thread, the largest delays occur in IO / database operations and other asynchronous things. Are the rest of your complex calculations really clogging up the main thread a lot? In this case, yes, it's better to use workers, they run in a separate thread.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question