NODE.JS INTRO
A Talk By Ioseb Dzmanashvili
@iosebi

Wednesday, December 25, 13
ABOUT ME

Software Architect at AzRy LLC
Assistant Professor at CST
Ph.D Student at Technical University of
Georgia
V8 Con...
ABOUT NODE.JS

Released in 2009 by Ryan Dahl
Is built on V8 JavaScript Engine
Based on event-driven non-blocking I/O
Platf...
WHAT MAKES IT AWESOME?
Easy of use
Server side JavaScript
Active community
Repository of awesome modules
npm install [modu...
SERIOUSLY? IS THAT ALL?

Wednesday, December 25, 13
WELL, NO
Built on V8 JavaScript engine
Node.js never blocks on I/O operations
You do not need to manage threads
No expensi...
V8 ADVANTAGES
Fastest JavaScript runtime
No JIT, it compiles JavaScript into
Assembler
Short(really short) garbage collect...
MAJOR BOTTLENECKS

I/O operations (Disk, RAM, Network)
Threaded concurrency

Wednesday, December 25, 13
I/O LATENCY
I/O
L1-Cache

3

L2-Cache

14

RAM

250

Hard Disk

41.000.000

Network

Wednesday, December 25, 13

CPU Cycle...
WHAT CONTRIBUTES TO
LATENCY?

Wednesday, December 25, 13
TYPICAL CODE EXAMPLE
var query = "SELECT * FROM t";
var result = db.query(query);
while(result.hasNext()) {
print(result.n...
NON BLOCKING EXAMPLE
var query = "SELECT * FROM t";
db.query(query, function(result) {
while(result.hasNext()) {
print(res...
FILE I/O EXAMPLE
$file = fopen("file.txt", "r");
while(!feof($file)){
$line = fgets($file);
// do something with line
}
fc...
ASYNC I/O WITH FILES
function readFile(file) {
var br = new BufferedReader(file, ...);
br.on("error", function(error) {
//...
HOW NODE.JS SOLVES I/O
PROBLEMS FOR ME?

Wednesday, December 25, 13
SINGLE THREADED

1
Wednesday, December 25, 13
EVENT LOOP

Single
Thread

Wednesday, December 25, 13
PROGRAM EXECUTION
FLOW
fn0();

I/O is handled
asynchronously

Wednesday, December 25, 13

fn1();

NETWORK I/O

fn2();

FS ...
DISADVANTAGES?

Wednesday, December 25, 13
IT IS JAVASCRIPT

Wednesday, December 25, 13
QUESTIONS?

Wednesday, December 25, 13
THANK YOU

Wednesday, December 25, 13
Upcoming SlideShare
Loading in …5
×

იოსებ ძმანაშვილი Node.js

573 views

Published on

სტუდენტური ჰაკათონი - cst.unihack.ge
პრეზენტაცია იოსებ ძმანაშვილი - Node.JS

http://www.youtube.com/watch?v=GO74oM2Fb4o
uniHack hack@CST

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
573
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

იოსებ ძმანაშვილი Node.js

  1. 1. NODE.JS INTRO A Talk By Ioseb Dzmanashvili @iosebi Wednesday, December 25, 13
  2. 2. ABOUT ME Software Architect at AzRy LLC Assistant Professor at CST Ph.D Student at Technical University of Georgia V8 Contributor Wednesday, December 25, 13
  3. 3. ABOUT NODE.JS Released in 2009 by Ryan Dahl Is built on V8 JavaScript Engine Based on event-driven non-blocking I/O Platform for fast and scalable network apps Wednesday, December 25, 13
  4. 4. WHAT MAKES IT AWESOME? Easy of use Server side JavaScript Active community Repository of awesome modules npm install [module name] Wednesday, December 25, 13
  5. 5. SERIOUSLY? IS THAT ALL? Wednesday, December 25, 13
  6. 6. WELL, NO Built on V8 JavaScript engine Node.js never blocks on I/O operations You do not need to manage threads No expensive context switching No memory waste on execution stacks Wednesday, December 25, 13
  7. 7. V8 ADVANTAGES Fastest JavaScript runtime No JIT, it compiles JavaScript into Assembler Short(really short) garbage collector cycles Great implementation of EcmaScript 5 and EcmaScript 6 Wednesday, December 25, 13
  8. 8. MAJOR BOTTLENECKS I/O operations (Disk, RAM, Network) Threaded concurrency Wednesday, December 25, 13
  9. 9. I/O LATENCY I/O L1-Cache 3 L2-Cache 14 RAM 250 Hard Disk 41.000.000 Network Wednesday, December 25, 13 CPU Cycles 240.000.000
  10. 10. WHAT CONTRIBUTES TO LATENCY? Wednesday, December 25, 13
  11. 11. TYPICAL CODE EXAMPLE var query = "SELECT * FROM t"; var result = db.query(query); while(result.hasNext()) { print(result.next()); } db.free(result); Wednesday, December 25, 13
  12. 12. NON BLOCKING EXAMPLE var query = "SELECT * FROM t"; db.query(query, function(result) { while(result.hasNext()) { print(result.next()); } }); // do something here Wednesday, December 25, 13
  13. 13. FILE I/O EXAMPLE $file = fopen("file.txt", "r"); while(!feof($file)){ $line = fgets($file); // do something with line } fclose($file); Wednesday, December 25, 13
  14. 14. ASYNC I/O WITH FILES function readFile(file) { var br = new BufferedReader(file, ...); br.on("error", function(error) { // handle error }).on("line", function(line) { // do something meaningful with line }).on("end", function() { // we are done }).read(); } readFile("/path/to/file"); Wednesday, December 25, 13
  15. 15. HOW NODE.JS SOLVES I/O PROBLEMS FOR ME? Wednesday, December 25, 13
  16. 16. SINGLE THREADED 1 Wednesday, December 25, 13
  17. 17. EVENT LOOP Single Thread Wednesday, December 25, 13
  18. 18. PROGRAM EXECUTION FLOW fn0(); I/O is handled asynchronously Wednesday, December 25, 13 fn1(); NETWORK I/O fn2(); FS I/O fn3(); Program never waits for I/ O operations completion DB I/O FS I/O
  19. 19. DISADVANTAGES? Wednesday, December 25, 13
  20. 20. IT IS JAVASCRIPT Wednesday, December 25, 13
  21. 21. QUESTIONS? Wednesday, December 25, 13
  22. 22. THANK YOU Wednesday, December 25, 13

×