
Kar started this conversation 1 week ago.
Slow performance / high resource usage when spawning many child processes
My Node.js app launches multiple shell commands via child_process.spawn() in parallel. It's slow, causes spikes in memory and CPU, and sometimes crashes. What alternatives can help avoid these slowdowns?
Digiaru
Posted 1 week ago
Spawning many OS-level processes is expensive and not scalable—especially when tasks run concurrently in high volume. Each spawn consumes overhead in process creation and communication ([turn0reddit24]turn0reddit25). Fixes: • Use Worker Threads for tasks that don't require external shells. • Maintain a process pool instead of spawning per task—reuse workers or child processes. • Throttle concurrency using async queues or libraries like p-limit or async.js. • Evaluate whether logic can run inside Node.js instead of separate processes.
🏷️ Suggested Posting Tags arduino Copy code nodejs, EMFILE, too-many-open-files, graceful-fs, file-descriptors, event-loop, performance, worker-threads, event-loop-blocking, child_process, spawn, concurrency, process-pooling