Ask a Node.js developer what they like about the platform and you're likely to hear that "Node.js is fast." If you ask why it's fast, you may hear that it's because JavaScript is fast, or because of its asynchronous nature, single-threadedness, or the V8 Engine...
All of these reasons may be valid in some sense. The mechanisms of Node.js, regardless of how they work, ultimately aim to increase its processing power. However, it's important to note that it's not only Node.js that implements these features, and many other languages or platforms have implemented them as well, and even implemented them better.
So, how fast is Node.js really? In this article, I will present my perspective on the issue of "Node.js being fast."
But first, let's take a look at the mechanisms that people commonly mention when concluding that Node.js is fast.
Node.js uses a single thread model through the Event Loop to handle asynchronous operations. This allows Node.js to handle multiple requests at the same time with ease.
To understand this concept, consider languages that do not follow the single thread model, like PHP. For each connection, PHP creates a thread to handle it. Clearly, the server has to allocate resources such as CPU and memory for each thread created. Now imagine what happens when multiple requests are sent?
This model brings some advantages to Node.js, such as reducing the number of threads to minimize resource consumption while still being able to handle a large number of concurrent requests.
Rarely does a web application not need to interact with a database. We all know that connecting to and querying a database takes more time than regular commands. Let's say an API endpoint needs to make a query that takes 2 seconds to return a result. With Node's single-threaded model, doesn't the second request have to wait at least 2 seconds to be processed? What about the third, fourth... requests? Wouldn't this create an exponential increase in latency?
Don't worry, because one of Node.js' strengths is its ability to handle asynchronous I/O. A certain number of requests can be almost simultaneously processed. However, Node.js will respond to each request one by one, and this process usually happens very quickly. In PHP, because threads are independent, they can comfortably return results simultaneously.
When talking about Node.js, we can't ignore the V8 Engine. This tool is a just-in-time compiler that translates JS code into machine code and runs it. The speed of V8 is extremely impressive among all JavaScript engines.
So, how fast is Node.js exactly?
You may have heard someone recommend that Node.js is particularly suitable for certain scenarios such as building API systems, real-time applications like chat, or tasks that are heavily I/O based. However, there are very few articles praising Node.js for its processing speed.
Performance is always a concern for any language or platform when it comes to handling a large number of concurrent requests. Each language is created to focus on solving a specific problem. Therefore, it is not accurate to say that Node.js is fast, but rather we should evaluate in which cases Node.js is a suitable choice and why.
That being said, it doesn't mean that Node.js is not "fast." But I believe that the speed of Node.js lies in its deployment and release speed.
Node provides a JS runtime environment, and JS is extremely popular on the programming language landscape. Therefore, the Node community is large, and you can quickly find a development partner for your project. Also, due to this development, countless libraries have been implemented for Node through npm. You don't have to reinvent the wheel because the community will help you with that.
In conclusion, what determines a powerful language or platform is the attitude of its developers and the coverage it has within the community.
If you still don't believe that Node.js is "fast," Techempower has taken the time to measure the power of various languages or platforms against each other. To ensure fairness, they run multiple tests, each performed on multiple languages or platforms, in exactly the same environment. Moreover, they regularly update the latest versions of languages or platforms and retest.
In the most recent measurements in July 2022, for the plaintext server response test (a type of "hello world"), Node.js with a popular framework like fastify ranks at 156 with a throughput of 575,967 req/s, much lower than other frameworks based on languages like C#, Java, or Golang. Specifically, aspcore with C# can achieve a throughput of more than 7 million req/s.
For a database query speed test, fastify-mysql can handle 9,383 req/s, still much lower than the response rate of more than 20k achieved by C#.
There are many other performance tests available. Readers can further explore them along with Techempower's benchmark criteria at Project Information Framework Tests Overview.
In this article, I just want to clarify what we mean when we say "Node.js is fast." At the same time, I emphasize that each language or platform has its reasons for existence, and comparing their speed doesn't necessarily reflect all of their strengths. Instead, we should understand their strengths and weaknesses and apply them appropriately to each problem.
What do you think? Is Node.js really "fast"? Please share your opinion in the comments below.
5 profound lessons
Every product comes with stories. The success of others is an inspiration for many to follow. 5 lessons learned have changed me forever. How about you? Click now!
Subscribe to receive new article notifications
Hello, my name is Hoai - a developer who tells stories through writing ✍️ and creating products 🚀. With many years of programming experience, I have contributed to various products that bring value to users at my workplace as well as to myself. My hobbies include reading, writing, and researching... I created this blog with the mission of delivering quality articles to the readers of 2coffee.dev.Follow me through these channels LinkedIn, Facebook, Instagram, Telegram.
Comments (3)