Node.js fork is slow; Deal with it
Yes. I know. Forking a process in Node.js
is slow. Instead of crying about it, let's see how we can handle it!
Let's assume that you have a service in which you:
- Accept a request
- Fork a process with
child_process.fork
- Execute some code within that process
- Exit from the child process
- Complete the request
Probably the first thing you tried was to receive the request, spin up a process, do whatever you need in the processor, and exit. You timed the whole thing and your jaw dropped that it took a million years for the request to complete, even if you are just doing a console.log('I love kittens')
inside your processor.
Don't bother. I will tell you right now that the bottleneck is the forking.