Single-thread

Every time a new user request arrives at the backend server it will create a new thread for the request, this is the classic behavior for backend servers that don't use Node.js. Once the server sends the response to the user, it releases the thread. Handling just a few threads is not an issue but, imagine what would happen if you need to handle millions of users at the same time? Let's graph this issue:

Node.js does not have this issue because of its single-thread strategy. Instead of starting a new thread for each request, it will use the same main thread to handle all the requests and will be supported by the event-loop. The following diagram depicts this scenario:

This scenario is better for CPU utilization; multiple threads allow NodeJS to take advantage of multi-core CPUs. However, we need more than a simple chapter to talk about them. We strongly encourage you to visit the official Node.js site at https://nodejs.org/en/.

Now it's time to code a simple HTTP Server and start the fun part!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset