Why is spawning a new process in Node so slow?
Node.js shows slow performance in spawning processes, handling 651 requests per second compared to over 2,200 for Deno and Bun, and over 5,000 for Go and Rust. Improvements were noted with child processes.
Read original articleNode.js has been observed to have slow performance when spawning new processes, particularly under load, with a maximum of 40 spawns per second and significant main thread blocking. This issue was highlighted in a benchmarking exercise comparing Node.js with Deno, Bun, Go, and Rust, where Node.js performed the worst, handling only 651 requests per second. In contrast, Deno and Bun achieved over 2,200 requests per second, while Go and Rust reached over 5,000.
To address the performance bottleneck, various strategies were explored, including using Node's cluster module to spawn multiple processes and distribute requests. This approach improved performance to 1,766 requests per second but still lagged behind Deno and Bun. Another method involved moving spawn calls to worker threads, which resulted in even lower performance due to the overhead of coordinating between threads.
Ultimately, switching to child processes for handling requests yielded better results, with Node achieving 2,209 requests per second when using child processes. The exploration also included attempts to optimize logging and output handling, with mixed results across different implementations. The findings suggest that while Node.js can be improved through various techniques, it still struggles to match the performance of compiled languages like Go and Rust, as well as newer runtimes like Deno and Bun.
Related
Show HN: Simulating 20M Particles in JavaScript
This article discusses optimizing JavaScript performance for simulating 1,000,000 particles in a browser. It covers data access optimization, multi-threading with SharedArrayBuffers and web workers, and memory management strategies.
How we tamed Node.js event loop lag: a deepdive
Trigger.dev team resolved Node.js app performance issues caused by event loop lag. Identified Prisma timeouts, network congestion from excessive traffic, and nested loop inefficiencies. Fixes reduced event loop lag instances, aiming to optimize payload handling for enhanced reliability.
The Cost of JavaScript
JavaScript significantly affects website performance due to download, execution, and parsing costs. Optimizing with strategies like code-splitting, minification, and caching is crucial for faster loading and interactivity, especially on mobile devices. Various techniques enhance JavaScript delivery and page responsiveness.
Deno 1.45: Workspace and Monorepo Support
Deno 1.45 introduces workspace and monorepo support, enhances Node.js compatibility, updates deno install, deprecates deno vendor, and more. Improved dependency management and configuration sharing streamline development workflows.
Node.js Is Here to Stay
Node.js, a key technology for 15 years, powers 6.3 million sites and 98% of Fortune 500 companies. Its lightweight, event-driven design suits real-time and high-concurrency needs. Security updates, Linux preference, and new features like ECMAScript Modules ensure Node.js remains a versatile and secure tool for modern web development.
- Performance differences in process spawning are influenced by the operating system, with Linux generally being faster due to features like vfork().
- Profiling tools like strace can provide insights into system calls and help understand speed discrepancies.
- There are limitations in Deno's implementation of the cluster module, which may affect performance compared to Node.js.
- Some users share personal experiences with process spawning in Node.js, noting variations in speed based on their environments.
- Comments suggest exploring alternatives to fork(), such as vfork() or posix_spawn(), to improve performance.
[1] https://docs.deno.com/runtime/manual/node/compatibility/
Is that…intentional on Unix’s part? Seems kind of a weird thing to implement.
As a heads up, the author confuses its and it's. Makes the article look unprofessional. https://youryoure.com/?its here's how to differentiate
Did you happen to look at how the load on the 8 cores looked at any given time?
Related
Show HN: Simulating 20M Particles in JavaScript
This article discusses optimizing JavaScript performance for simulating 1,000,000 particles in a browser. It covers data access optimization, multi-threading with SharedArrayBuffers and web workers, and memory management strategies.
How we tamed Node.js event loop lag: a deepdive
Trigger.dev team resolved Node.js app performance issues caused by event loop lag. Identified Prisma timeouts, network congestion from excessive traffic, and nested loop inefficiencies. Fixes reduced event loop lag instances, aiming to optimize payload handling for enhanced reliability.
The Cost of JavaScript
JavaScript significantly affects website performance due to download, execution, and parsing costs. Optimizing with strategies like code-splitting, minification, and caching is crucial for faster loading and interactivity, especially on mobile devices. Various techniques enhance JavaScript delivery and page responsiveness.
Deno 1.45: Workspace and Monorepo Support
Deno 1.45 introduces workspace and monorepo support, enhances Node.js compatibility, updates deno install, deprecates deno vendor, and more. Improved dependency management and configuration sharing streamline development workflows.
Node.js Is Here to Stay
Node.js, a key technology for 15 years, powers 6.3 million sites and 98% of Fortune 500 companies. Its lightweight, event-driven design suits real-time and high-concurrency needs. Security updates, Linux preference, and new features like ECMAScript Modules ensure Node.js remains a versatile and secure tool for modern web development.