What do you think when I say Node.js is fast?

What do you think when I say Node.js is fast?

Daily short news for you
  • Rust is the time of its coming... It's "redefining" a whole bunch of things. Even the coreutils package containing basic Linux commands has been rewritten by it, and it runs on multiple platforms too 🫣

    uutils.github.io

    » Read more
  • Attention everyone 🔥, Gemini 2.0 is the latest and most powerful model from Google, currently available for free trial, and the API is also free (But it seems they are imposing more restrictions as there are many users).

    » Read more
  • I just discovered a very simple way to public localhost on the Internet using VSCode. First, open the Panel using the shortcut Command + J (or Ctrl + J), click on the PORTS tab, click on the "Forward a Port" button, then enter the port you want to public and hit Enter, and that's it. VSCode will create a URL mapped to the port on your local machine 🤓

    » Read more

The Issue

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.

Single Thread

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.

Asynchronous I/O

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.

V8 Engine

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.

Comparing Node.js Performance to Other Languages or Platforms

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.

Benchmark

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.

Conclusion

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.

Premium
Hello

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!

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!

View all

Subscribe to receive new article notifications

or
* The summary newsletter is sent every 1-2 weeks, cancel anytime.
Author

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.

Did you find this article helpful?
NoYes

Comments (3)

Leave a comment...
Avatar
Tuan Nguyen1 year ago
Tại sao lại sử dụng nodejs: - Typescript - một ngôn ngữ tuyệt vời, càng code càng mê - Khả năng xử lý json của javascript cực kỳ bá đạo ( phải nói là bá đạo nhất trong các ngôn ngữ ) - Non-Blocking language:  - Thế giới của library - Tuy nhiên ( rất nhiều library rác ) - IDE support tận răng ( với vscode )
Reply
Avatar
Trần Ngọc Hải2 years ago
V8 có thể nhanh, nhưng cơ chế quản lý bộ nhớ của nó không thực sự hiệu quả. Bằng chứng là chrome đang ngốm quá nhiều bộ nhớ. Khi bộ nhớ bị chiếm đến mức độ nào đó thì hiệu năng sẽ giảm
Reply
Avatar
Trần Huy Hoàng2 years ago
Theo mình nghĩ nodejs không có gì nổi bật ngoài việc được js hậu thuẫn, còn đâu quá nặng và chậm chạp
Reply
Avatar
Xuân Hoài Tống2 years ago
Node có mức tiêu thụ bộ nhớ nhiều thật nhưng tốc độ phát triển khi dùng Node là khá nhanh