Skip to main content

One post tagged with "no_silver_bullet"

View All Tags

Node.js fork is slow; Deal with it

ยท 5 min read

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:

  1. Accept a request
  2. Fork a process with child_process.fork
  3. Execute some code within that process
  4. Exit from the child process
  5. 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.