Since long time I wanted to write about nodejs, So finally the day is came today.
Introduction
nodejs is a software by which we can use JavaScript on server side which means we can use the JavaScript for http request and can do read/write kind of operations on server.
It's not a web server like Apache, it does not do anything by itself, you have to create a server who handles about http request and response by using it's various modules.
nodejs is usually used for real time application, something like chat, audio, video etc. It is used for I/O kind of applications eg:- database reading/writing, make network connection etc. It uses the non-blocking concept for scalable network application. It uses V8 engine for great performance on server side. The V8 engine is made by google used in google-chrome browser for fast browser experience.
nodejs uses the JavaScript's asynchronous behavior(event loop), which means when you would apply the particular task for particular event and don't worry about that task, whenever that event is occurred that particular assigned task would be performed, so nodejs uses this nature of JavaScript for performance of scalable network application.
So here we would know how the nodejs increases the performance on scalable network application.
As you can see in above image, there is multiple http requests for server santa, the request is about to read the content from database and response back to server and finally display the content in browser/computer.
With traditional way, the whole Process 1 http request for read page and response the page to server could take the long time, the Process 2 is not started until the Process 1 is finished. The RAM and it's CPU would be in idle state until the Process 1 is completed. So this blocking nature does waste the lot of RAM and CPU when large of users would come.
This kind of situation can be handled by multiple threads, However switching between threads and RAM does waste the memory and CPU.
JavaScript is single thread language, so how nodejs achieves huge performance let's see, as we already knew JavaScript has asynchronous behavior. At above figure, to start Process 2, there is no need to complete the Process 1. So second connection/http request can be made without completed first request which means the Process 2 could be started without finished Process 1.
We don't have wait here, So no extra expenses of RAM and CPU. That's how there could make a lot of concurrent connections at same time which increases the performance on network scalable application .
2) It can handle lot of concurrent connections.
3) It uses the single thread for make lot of network connections.
4) Because of single thread, there is a lot of benefit on Memory and CPU of server.
5) Same context on client and server, which means we can use JavaScript both in client and server that we don't need to worry about the switching the programming language for client and server.
Introduction
nodejs is a software by which we can use JavaScript on server side which means we can use the JavaScript for http request and can do read/write kind of operations on server.
It's not a web server like Apache, it does not do anything by itself, you have to create a server who handles about http request and response by using it's various modules.
nodejs is usually used for real time application, something like chat, audio, video etc. It is used for I/O kind of applications eg:- database reading/writing, make network connection etc. It uses the non-blocking concept for scalable network application. It uses V8 engine for great performance on server side. The V8 engine is made by google used in google-chrome browser for fast browser experience.
nodejs uses the JavaScript's asynchronous behavior(event loop), which means when you would apply the particular task for particular event and don't worry about that task, whenever that event is occurred that particular assigned task would be performed, so nodejs uses this nature of JavaScript for performance of scalable network application.
http requests for read operation |
As you can see in above image, there is multiple http requests for server santa, the request is about to read the content from database and response back to server and finally display the content in browser/computer.
With traditional way, the whole Process 1 http request for read page and response the page to server could take the long time, the Process 2 is not started until the Process 1 is finished. The RAM and it's CPU would be in idle state until the Process 1 is completed. So this blocking nature does waste the lot of RAM and CPU when large of users would come.
This kind of situation can be handled by multiple threads, However switching between threads and RAM does waste the memory and CPU.
JavaScript is single thread language, so how nodejs achieves huge performance let's see, as we already knew JavaScript has asynchronous behavior. At above figure, to start Process 2, there is no need to complete the Process 1. So second connection/http request can be made without completed first request which means the Process 2 could be started without finished Process 1.
We don't have wait here, So no extra expenses of RAM and CPU. That's how there could make a lot of concurrent connections at same time which increases the performance on network scalable application .
Main Benefits
1) It uses the non-blocking concept.2) It can handle lot of concurrent connections.
3) It uses the single thread for make lot of network connections.
4) Because of single thread, there is a lot of benefit on Memory and CPU of server.
5) Same context on client and server, which means we can use JavaScript both in client and server that we don't need to worry about the switching the programming language for client and server.
You can get the nodejs from nodejs
No comments:
Post a Comment