About Piyas De

Piyas is Sun Microsystems certified Enterprise Architect with 10+ years of professional IT experience in various areas such as Architecture Definition, Define Enterprise Application, Client-server/e-business solutions.

Node.js Non-Blocking IO Model

Now-a-days developers know about Node.js as a server -side javascript execution platform.

According to nodejs.org,- “Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.”

Now node.js opens a new way of performing or serving to the web requests or any other type of server requests – which is called Non-blocking IO Operation.

We have came across the following link – http://code.danyork.com/2011/01/25/node-js-doctors-offices-and-fast-food-restaurants-understanding-event-driven-programming/,  which is an excellent way of showing the non-blocking concepts of node.js with relate to real-life working scenarios.

As my background for last 5-6 years as J2ee Programmer, I knew and understood the Servlet Programming Model in J2ee Environment, which is a multi-threaded programming model i.e. when a web request come to java based web server, the request hit to the servlet with the request and the servlet opens a new thread to handle the request and response the data back to the client. All the database related methods or any server resource intensive call, which are shared in nature, are to be handled carefully from the servlet to avoid any deadlock or other unwanted situations which will be related to shared objects.

Though through this way a process parts in threads and serves the web request within thread which are having relatively small overhead as compared to server processes. But still if some database call amounts to a significant time within the execution of request and response which is within a thread call, it will hold the client for this with their synchronous activity which is blocking IO operation.

Now it is time to understand the non-blocking I/O, on which node.js platform is defined.

First of all, node.js application environment will run on a single threaded programming model.

All the web requests and server requests call in node.js are of non-blocking I/Os. An web request comes in node.js web server and the web server accepts this request and handle this request to a listener object to process the response. Also this web server will remain ready to accept any new web request. And the previous response handling will remain in a queue for performing the rest of operations. Now the node.js environment takes care of preparing the web response which again can be a database call from the actual application. Also this database query can also consists of callback functions with the response from database as being ready. Those operations are executed in a queue and also called as event driven programming and all of these operations are asynchronous in nature.

So the whole point to discuss here is, all the function calls within node.js context are non-blocking input-output operations. In node.js environment, the performing operation is executed by one object and the results of the operation are handled by the callback functions.

We will talk more about the node.js execution model, event-driven programming and asynchronous operations as we work further in these line of application architecture.

That is all for now. Comments are well come.
 

Reference: Node.js Non-Blocking IO Model from our JCG partner Piyas De at the Phlox Blog blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

One Response to "Node.js Non-Blocking IO Model"

  1. Arjun says:

    Just a thought…
    What if we have a web server which will maintain a thread pool for incoming request handling and each thread behave in asynchronous manner as it works in Node.js.. will it perform better than Node.js as Node.js is only single threaded ?

Leave a Reply


− six = 1



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close