0% found this document useful (0 votes)
5 views

NodeJS Notes

Node.js is a JavaScript runtime environment that utilizes Google Chrome's V8 engine, enabling fast server-side execution of JavaScript. It is designed for high concurrency through an event-driven, non-blocking I/O model, allowing it to handle numerous simultaneous requests efficiently. This platform allows developers to use the same JavaScript code on both client and server sides, enhancing performance and reducing context switching.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

NodeJS Notes

Node.js is a JavaScript runtime environment that utilizes Google Chrome's V8 engine, enabling fast server-side execution of JavaScript. It is designed for high concurrency through an event-driven, non-blocking I/O model, allowing it to handle numerous simultaneous requests efficiently. This platform allows developers to use the same JavaScript code on both client and server sides, enhancing performance and reducing context switching.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 9

 A JavaScript runtime environment running

Google Chrome’s V8 engine


◦ a.k.a. a server-side solution for JS
◦ Compiles JS, making it really fast
 Runs over the command line
 Designed for high concurrency

◦ Without threads or new processes


 Never blocks, not even for I/O
 Uses the CommonJS framework

◦ Making it a little closer to a real OO language


 Instead of threads Node uses an event loop
with a stack
 Alleviates overhead of context switching
Threads Asynchronous Event-driven

Lock application / request with only one thread, which


listener-workers threads repeatedly fetches an event
Using incoming-request model Using queue and then processes
it
multithreaded server might manually saves state and then
block the request which might goes on to process the next
involve multiple events event
Using context switching no contention and no context
switches
Using multithreading Using asynchronous I/O facilities
environments where listener (callbacks, not poll/select or
and workers threads are used O_NONBLOCK) environments
frequently to take an incoming-
request lock
 Request for “index.html” comes in
 Stack unwinds and ev_loop goes to sleep
 File loads from disk and is sent to the client
 Servers do nothing but I/O
◦ Scripts waiting on I/O requests degrades
performance
 To avoid blocking, Node makes use of the
event driven nature of JS by attaching
callbacks to I/O requests
 Scripts waiting on I/O waste no space

because they get popped off the stack when


their non-I/O related code finishes executing
 Use of JS on both the client and server-side
should remove need to “context switch”
◦ Client-side JS makes heavy use of the DOM, no
access to files/databases
◦ Server-side JS deals mostly in files/databases, no
DOM
 JSDom project for Node works for simple tasks, but
not much else
1. It's fast
2. It can handle tons of concurrent requests
3. It's written in JavaScript (which means you can
use the same code server side and client side)

Platform Number of request per


second
PHP ( via Apache) 3187,27
Static ( via Apache ) 2966,51
Node.js 5569,30
 http://nodejs.org/
 http://nodejs.org/cinco_de_node.pdf
 http://ajaxian.com/archives/google-chrome-
chromium-and-v8
 http://blog.chromium.org/2010/12/new-cran
kshaft-for-v8.html
 http://news.softpedia.com/news/IE9-RC-vs-C
hrome-10-9-vs-Opera-11-vs-Firefox-11-Perfo
rmance-Comparison-183973.shtml

You might also like