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
  • swapy is a library that helps you create drag-and-drop actions to easily swap the positions of components.

    The library supports a wide range of platforms, making it perfect for building something personalized like a user’s Dashboard.

    » Read more
  • After waking up, I saw the news feed flooded with articles about Microsoft rewriting the TypeScript compiler - tsc in Go, achieving performance that is 10 times faster than the current one. Wow!

    But when I saw this news, the question immediately popped into my head: "Why not Rust?" You know, the trend of rewriting everything in Rust is hotter than ever, and it’s not an exaggeration to say that it's sweeping through the rankings of previous legacy tools.

    What’s even more interesting is the choice of Go - which supposedly provides the best performance to date - as they say. Many people expressed disappointment about why it wasn’t C# instead 😆. When something is too famous, everything is scrutinized down to the smallest detail, and not everyone listens to what is said 🥶

    Why Go? #411

    » Read more
  • I read this article Migrating Off Oh-My-Zsh and other recent Yak Shavings - the author essentially states that he has been using Oh-My-Zsh (OMZ) for a long time, but now the game has changed, and there are many more powerful tools that have come out, so he realizes, oh, he doesn't need OMZ as much anymore.

    I also tried to follow along because I find this situation quite similar to the current state. It was surprising to discover something new. I hope to soon write a post about this next migration for my readers 😁

    » 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

The secret stack of Blog

As a developer, are you curious about the technology secrets or the technical debts of this blog? All secrets will be revealed in the article below. What are you waiting for, click now!

As a developer, are you curious about the technology secrets or the technical debts of this blog? All secrets will be revealed in the article below. What are you waiting for, click now!

View all

Subscribe to receive new article notifications

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

Comments (4)

Leave a comment...
Avatar
Ẩn danh1 month ago
blog méo gì đọc được 2, 3 dòng có cái QC :))) hài vl, chào tạm biệt và thân ái
Reply
Avatar
Xuân Hoài Tống1 month ago
Đầu xuân năm mới, chúc bạn nhiều sức khỏe. Mình gắn qc để vừa giúp quảng bá sản phẩm đến cộng đồng, vừa kiếm được một ít hoa hồng nhưng không đáng kể đâu ạ. Ai cũng có công việc riêng của mình vậy nên vài nữa mình phát hành bản trả phí rất mong bạn và nhiều người nữa quan tâm 😅
Avatar
Tuan Nguyen2 years 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