Answer the question
In order to leave comments, you need to log in
How to run a function on multiple threads in Node JS?
How to run a function in multiple threads?
Let's say I have a function that makes ten GET requests to some URL in a loop:
function makeReq(param1, param2) {
for(i = 0, i < 10, i++) {
// Do something
}
}
Answer the question
In order to leave comments, you need to log in
https://nodejs.org/api/cluster.html
On a node, it is very difficult to lose performance to python (in the V8 code, everything is optimized by bloody enterprise competition, while python is grown in a more relaxed atmosphere of laboratory research, when it is not very important, the script will be executed in one second or ten). In your case, in general, everything rests on IO, you can write at least in BASIC, the interpreter itself will not slow down, it will constantly wait for IO.
And just in case, I'll ask - why do you need to send requests in several threads? After all, they are still serialized in TCP and will go in order. Very similar to a naive attempt to implement didos :).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question