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.
Related Whitepaper:

Software Architecture

This guide will introduce you to the world of Software Architecture!

This 162 page guide will cover topics within the field of software architecture including: software architecture as a solution balancing the concerns of different stakeholders, quality assurance, methods to describe and evaluate architectures, the influence of architecture on reuse, and the life cycle of a system and its architecture. This guide concludes with a comparison between the professions of software architect and software engineer.

Get it Now!  

Leave a Reply


seven − = 1



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
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.

Sign up for our Newsletter

20,709 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books