SlideShare a Scribd company logo
Emerging Paradigms - 
Server Side Event Driven 
Programming 
Kamal Hussain 
http://www.linkedin.com/in/hussainkamal/
Agenda 
● Linear Vs Nonlinear Code 
● Concurrency through threads and events 
● Event loop 
● PHP and Javascript 
● Node.js - closeup 
● Important concepts
We are used to .. 
val client = new HttpClient() 
val method = new GetMethod("http: 
//www.google.com") 
val statusCode = client.executeMethod 
(method) 
println("Server responded with %d" . 
format(statusCode))
Event driven approach 
var callback = function(data) { 
console.log("firing callback " + 
data); 
}; 
$.get('/endpoint', callback); 
console.log('Did you see callback?');
Achieving scale and concurrency 
● Multiple threads/processes 
● Size the threadpool correctly 
● Each thread is responsible for one task such 
as serving a request 
● Asynchronous programming
Asynchronous with 
threads/processes
Asynchronous with events
Problems with Threads 
● Hard to program 
● Memory requirements are high 
● Large overhead 
● Context switching 
● Priority inversion
Threads wait 
udemy.com
Cost of IO 
L1 Cache 3 Cycles 
L2 Cache 14 Cycles 
RAM 250 cycles 
Disk 41 000 000 cycles 
Network 240 000 000 cycles
Event Loop Architecture 
courtsey: http://www.johanndutoit.net/
Writing synchronous Vs 
Asynchronous 
// Good: write files asynchronously 
fs.writeFile('message.txt', 'Hello Node', function (err) { 
console.log("It's saved and the server remains responsive!"); 
}); 
// BAD: write files synchronously 
fs.writeFileSync('message.txt', 'Hello Node'); 
console.log("It's saved, but you just blocked ALL requests!"); 
This can cause performance drop from thousands of requests/seconds to a few 
dozen/second. 
http://engineering.linkedin.com/nodejs/blazing-fast-nodejs-10-performance-tips-linkedin- 
mobile
Tale of two languages 
● PHP was invented in 1994 by Rasmus 
Lerdorfas as a replacement for CGI scripts 
● PHP was a substitute for single-threaded C 
programs 
● Brendan Eich developed Javascript in 1995 
for a completely different purpose. JS was 
designed to run within Netscape Navigator 
and was primarily designed to handle 
events. 
PHP -> eventless, Javascript -> eventful
Node.js 
● Ryan Dahl invented Node.js in 2009 as a 
continuation of Javascript heritage. 
● Node.js is modeled after multi-task, multi-page 
handling of a web server.
What's Node.js? 
"Node.js is a server-side software system designed for 
writing scalable Internet applications, notably web servers. 
Programs are written on the server side in JavaScript, 
using event-driven, asynchronous I/O to minimize overhead 
and maximize scalability." 
- from wikipedia
Node.js - asynchronous I/O 
● First class functions 
● Closures 
● Event loop 
● Callback counters 
CPU intensive tasks are delegated to workers
PHP Way 
$fp = fopen("fp.txt", 'w) 
fwrite($fp, "hello world"); 
fclose($fp);
Node.js way 
var fs = require('fs'); 
fs.open('fp.txt', 'w', 0666, 
function(error, fp) { 
fw.write(fp, 'helloworld', null, 
'utf-8', function() { 
fs.close(fp, function(error) { 
}); 
}); 
});
Node.js simple example 
var http = require('http'); 
http.createServer(function(req, res) { 
res.writeHead(200, {'Content-Type' : 
'text/plain'}); 
res.end("Hello Worldn"); 
}).listen(8000, "127.0.0.1"); 
console.log("Server running at http: 
//127.0.0.1:8000");
Node.js Core APIs 
Events 
EventTransmitter 
Event listener 
Event emitter 
Call back 
Http 
I/O
Node.js Workers 
Synchronous call 
Workers are blocked 
Call returns
Workers Vs Events 
Workers 
1 event per connection 
N workers per CPU 
Events 
N connections per CPU 
1 process per CPU
Node.js Typical Applications 
● Proxy 
● API server 
○ REST API calls 
○ Simple transformations 
See performance comparisons at: 
http://www.slideshare.net/FabianFrankDe/nodejs-performance-case-study
Concepts to learn 
First class functions 
Lambdas - anonymous functions 
Closures 
Non-blocking IO
Deploying Node.js 
http://www.slideshare.net/BenLin2/webconf-nodejsproductionarchitecture
Key takeaway 
Learn Javascript and 
functional programming. 
Future is brighter :)
Reference 
● Node - Up and Running by Tom Hughes-Croucher, 
Mike Wilson - Oreilly 
● Node.js for PHP Developers - Oreilly 
● Javascript: The definitive guide - Oreilly 
● LinkedIn, Netflix Blogs 
● http://architects.dzone.com/articles/nodejs-php-programmers- 
1-event 
● https://www.udemy.com/lectures/understanding-the-nodejs- 
event-loop-91298 
● https://speakerdeck.com/guldenpt/before-start-coding-in- 
node-dot-js

More Related Content

What's hot

Let’s talk about JavaScript - WebElement
Let’s talk about JavaScript - WebElementLet’s talk about JavaScript - WebElement
Let’s talk about JavaScript - WebElement
Marian Rusnak
 
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
andreaslubbe
 
Everything ruby
Everything rubyEverything ruby
Everything ruby
ajeygore
 
Node.js System: The Approach
Node.js System: The ApproachNode.js System: The Approach
Node.js System: The Approach
Haci Murat Yaman
 
Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs
Irfan Maulana
 
Node.js concurrency
Node.js concurrencyNode.js concurrency
Node.js concurrency
Giacomo Fornari
 
Event Driven Architecture Concepts in Web Technologies - Part 1
Event Driven Architecture Concepts in Web Technologies - Part 1Event Driven Architecture Concepts in Web Technologies - Part 1
Event Driven Architecture Concepts in Web Technologies - Part 1
Hamidreza Soleimani
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Tom Croucher
 
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Tom Croucher
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
Oleg Podsechin
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challenger
vanphp
 
Javascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To TailJavascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To Tail
Cliffano Subagio
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHP
Thomas Weinert
 
Node.js: CAMTA Presentation
Node.js: CAMTA PresentationNode.js: CAMTA Presentation
Node.js: CAMTA Presentation
Rob Tweed
 
Introduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsIntroduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCats
Derek Anderson
 
20170310 PHP goal pyramid for memorising
20170310 PHP goal pyramid for memorising20170310 PHP goal pyramid for memorising
20170310 PHP goal pyramid for memorising
Sharon Liu
 
Securing Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultSecuring Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp Vault
Bram Vogelaar
 
Shell Scripting & Ruby Hacking
Shell Scripting & Ruby HackingShell Scripting & Ruby Hacking
Shell Scripting & Ruby Hacking
n|u - The Open Security Community
 
Node.js
Node.jsNode.js
Node.js
Jan Dillmann
 
Shell Scripting-training-course-navi-mumbai-shell-scripting-course-provider-n...
Shell Scripting-training-course-navi-mumbai-shell-scripting-course-provider-n...Shell Scripting-training-course-navi-mumbai-shell-scripting-course-provider-n...
Shell Scripting-training-course-navi-mumbai-shell-scripting-course-provider-n...
VibrantGroup
 

What's hot (20)

Let’s talk about JavaScript - WebElement
Let’s talk about JavaScript - WebElementLet’s talk about JavaScript - WebElement
Let’s talk about JavaScript - WebElement
 
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
 
Everything ruby
Everything rubyEverything ruby
Everything ruby
 
Node.js System: The Approach
Node.js System: The ApproachNode.js System: The Approach
Node.js System: The Approach
 
Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs
 
Node.js concurrency
Node.js concurrencyNode.js concurrency
Node.js concurrency
 
Event Driven Architecture Concepts in Web Technologies - Part 1
Event Driven Architecture Concepts in Web Technologies - Part 1Event Driven Architecture Concepts in Web Technologies - Part 1
Event Driven Architecture Concepts in Web Technologies - Part 1
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012
 
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challenger
 
Javascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To TailJavascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To Tail
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHP
 
Node.js: CAMTA Presentation
Node.js: CAMTA PresentationNode.js: CAMTA Presentation
Node.js: CAMTA Presentation
 
Introduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsIntroduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCats
 
20170310 PHP goal pyramid for memorising
20170310 PHP goal pyramid for memorising20170310 PHP goal pyramid for memorising
20170310 PHP goal pyramid for memorising
 
Securing Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultSecuring Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp Vault
 
Shell Scripting & Ruby Hacking
Shell Scripting & Ruby HackingShell Scripting & Ruby Hacking
Shell Scripting & Ruby Hacking
 
Node.js
Node.jsNode.js
Node.js
 
Shell Scripting-training-course-navi-mumbai-shell-scripting-course-provider-n...
Shell Scripting-training-course-navi-mumbai-shell-scripting-course-provider-n...Shell Scripting-training-course-navi-mumbai-shell-scripting-course-provider-n...
Shell Scripting-training-course-navi-mumbai-shell-scripting-course-provider-n...
 

Viewers also liked

Contentspagefeedback
ContentspagefeedbackContentspagefeedback
Contentspagefeedback
jaritluin
 
Silabus Eksponensial dan Logaritma
Silabus Eksponensial dan LogaritmaSilabus Eksponensial dan Logaritma
Silabus Eksponensial dan Logaritma
Trya Wulanabi
 
analisis
analisisanalisis
analisis
cahya17
 
Media reader profile
Media reader profileMedia reader profile
Media reader profile
jaritluin
 
Materi ajar eksponensial
Materi ajar eksponensialMateri ajar eksponensial
Materi ajar eksponensial
Trya Wulanabi
 
A Way Back to You
A Way Back to YouA Way Back to You
A Way Back to You
bellmarie
 
Hyderabad traithlon presentation
Hyderabad traithlon presentationHyderabad traithlon presentation
Hyderabad traithlon presentation
Ravi Chandra
 
Rpp eksponen.tugas tik dlm tp
Rpp eksponen.tugas tik dlm tpRpp eksponen.tugas tik dlm tp
Rpp eksponen.tugas tik dlm tpTrya Wulanabi
 
Journal-RISS2015
Journal-RISS2015Journal-RISS2015
Journal-RISS2015
Feliphe Gonçalves Galiza
 
Materi ajar eksponensial
Materi ajar eksponensialMateri ajar eksponensial
Materi ajar eksponensialTrya Wulanabi
 
Bab 1 bentuk pangkat, akar & logaritma
Bab 1 bentuk pangkat, akar & logaritmaBab 1 bentuk pangkat, akar & logaritma
Bab 1 bentuk pangkat, akar & logaritmaTrya Wulanabi
 
Bab 1 pertumbuhan dan perkembangan tumbuhan
Bab 1 pertumbuhan dan perkembangan tumbuhanBab 1 pertumbuhan dan perkembangan tumbuhan
Bab 1 pertumbuhan dan perkembangan tumbuhanTrya Wulanabi
 
Rpp blog
Rpp blogRpp blog
Rpp blog
Trya Wulanabi
 
Silabus biologi pratiwi jilid 3
Silabus biologi pratiwi jilid 3Silabus biologi pratiwi jilid 3
Silabus biologi pratiwi jilid 3
Trya Wulanabi
 

Viewers also liked (18)

Contentspagefeedback
ContentspagefeedbackContentspagefeedback
Contentspagefeedback
 
Silabus Eksponensial dan Logaritma
Silabus Eksponensial dan LogaritmaSilabus Eksponensial dan Logaritma
Silabus Eksponensial dan Logaritma
 
analisis
analisisanalisis
analisis
 
Media reader profile
Media reader profileMedia reader profile
Media reader profile
 
Senza nome 1
Senza nome 1Senza nome 1
Senza nome 1
 
Materi ajar eksponensial
Materi ajar eksponensialMateri ajar eksponensial
Materi ajar eksponensial
 
A Way Back to You
A Way Back to YouA Way Back to You
A Way Back to You
 
Hyderabad traithlon presentation
Hyderabad traithlon presentationHyderabad traithlon presentation
Hyderabad traithlon presentation
 
Rpp eksponen.tugas tik dlm tp
Rpp eksponen.tugas tik dlm tpRpp eksponen.tugas tik dlm tp
Rpp eksponen.tugas tik dlm tp
 
Journal-RISS2015
Journal-RISS2015Journal-RISS2015
Journal-RISS2015
 
Latihan soal
Latihan soalLatihan soal
Latihan soal
 
Materi ajar eksponensial
Materi ajar eksponensialMateri ajar eksponensial
Materi ajar eksponensial
 
Silabus eksponen
Silabus eksponenSilabus eksponen
Silabus eksponen
 
Bab 1 bentuk pangkat, akar & logaritma
Bab 1 bentuk pangkat, akar & logaritmaBab 1 bentuk pangkat, akar & logaritma
Bab 1 bentuk pangkat, akar & logaritma
 
Materi blog
Materi blogMateri blog
Materi blog
 
Bab 1 pertumbuhan dan perkembangan tumbuhan
Bab 1 pertumbuhan dan perkembangan tumbuhanBab 1 pertumbuhan dan perkembangan tumbuhan
Bab 1 pertumbuhan dan perkembangan tumbuhan
 
Rpp blog
Rpp blogRpp blog
Rpp blog
 
Silabus biologi pratiwi jilid 3
Silabus biologi pratiwi jilid 3Silabus biologi pratiwi jilid 3
Silabus biologi pratiwi jilid 3
 

Similar to Event driven programming -- Node.JS

Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
Kamal Hussain
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
NodeJS
NodeJSNodeJS
NodeJS
Alok Guha
 
Node.js
Node.jsNode.js
Node.js
EU Edge
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js Platform
Naresh Chintalcheru
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
Alex Su
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
Nir Noy
 
Node js beginner
Node js beginnerNode js beginner
Node js beginner
Sureshreddy Nalimela
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Somkiat Puisungnoen
 
Node js
Node jsNode js
Node js
hazzaz
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Tom Croucher
 
Intro to Node
Intro to NodeIntro to Node
Intro to Node
Aaron Stannard
 
Node.js for Rubists
Node.js for RubistsNode.js for Rubists
Node.js for Rubists
Sagiv Ofek
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
Mohammad Qureshi
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
WalaSidhom1
 
NodeJS
NodeJSNodeJS
NodeJS
LinkMe Srl
 
Node.js 1, 2, 3
Node.js 1, 2, 3Node.js 1, 2, 3
Node.js 1, 2, 3
Jian-Hong Pan
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
drupalcampest
 

Similar to Event driven programming -- Node.JS (20)

Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
NodeJS
NodeJSNodeJS
NodeJS
 
Node.js
Node.jsNode.js
Node.js
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js Platform
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
 
Node js beginner
Node js beginnerNode js beginner
Node js beginner
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node js
Node jsNode js
Node js
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
 
Intro to Node
Intro to NodeIntro to Node
Intro to Node
 
Node.js for Rubists
Node.js for RubistsNode.js for Rubists
Node.js for Rubists
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
NodeJS
NodeJSNodeJS
NodeJS
 
Node.js 1, 2, 3
Node.js 1, 2, 3Node.js 1, 2, 3
Node.js 1, 2, 3
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
 

Recently uploaded

留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
uehowe
 
Bengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal BrandingBengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal Branding
Tarandeep Singh
 
Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?
Paul Walk
 
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
3a0sd7z3
 
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
ysasp1
 
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
rtunex8r
 
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
uehowe
 
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
fovkoyb
 
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
xjq03c34
 
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
k4ncd0z
 
Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!
Toptal Tech
 
HijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process HollowingHijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process Hollowing
Donato Onofri
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
davidjhones387
 
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmanuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
wolfsoftcompanyco
 
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
3a0sd7z3
 
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
uehowe
 

Recently uploaded (16)

留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
 
Bengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal BrandingBengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal Branding
 
Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?
 
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
 
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
 
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
 
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
 
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
 
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
 
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
 
Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!
 
HijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process HollowingHijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process Hollowing
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
 
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmanuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
 
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
 
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
 

Event driven programming -- Node.JS

  • 1. Emerging Paradigms - Server Side Event Driven Programming Kamal Hussain http://www.linkedin.com/in/hussainkamal/
  • 2. Agenda ● Linear Vs Nonlinear Code ● Concurrency through threads and events ● Event loop ● PHP and Javascript ● Node.js - closeup ● Important concepts
  • 3. We are used to .. val client = new HttpClient() val method = new GetMethod("http: //www.google.com") val statusCode = client.executeMethod (method) println("Server responded with %d" . format(statusCode))
  • 4. Event driven approach var callback = function(data) { console.log("firing callback " + data); }; $.get('/endpoint', callback); console.log('Did you see callback?');
  • 5. Achieving scale and concurrency ● Multiple threads/processes ● Size the threadpool correctly ● Each thread is responsible for one task such as serving a request ● Asynchronous programming
  • 8. Problems with Threads ● Hard to program ● Memory requirements are high ● Large overhead ● Context switching ● Priority inversion
  • 10. Cost of IO L1 Cache 3 Cycles L2 Cache 14 Cycles RAM 250 cycles Disk 41 000 000 cycles Network 240 000 000 cycles
  • 11.
  • 12. Event Loop Architecture courtsey: http://www.johanndutoit.net/
  • 13. Writing synchronous Vs Asynchronous // Good: write files asynchronously fs.writeFile('message.txt', 'Hello Node', function (err) { console.log("It's saved and the server remains responsive!"); }); // BAD: write files synchronously fs.writeFileSync('message.txt', 'Hello Node'); console.log("It's saved, but you just blocked ALL requests!"); This can cause performance drop from thousands of requests/seconds to a few dozen/second. http://engineering.linkedin.com/nodejs/blazing-fast-nodejs-10-performance-tips-linkedin- mobile
  • 14. Tale of two languages ● PHP was invented in 1994 by Rasmus Lerdorfas as a replacement for CGI scripts ● PHP was a substitute for single-threaded C programs ● Brendan Eich developed Javascript in 1995 for a completely different purpose. JS was designed to run within Netscape Navigator and was primarily designed to handle events. PHP -> eventless, Javascript -> eventful
  • 15. Node.js ● Ryan Dahl invented Node.js in 2009 as a continuation of Javascript heritage. ● Node.js is modeled after multi-task, multi-page handling of a web server.
  • 16. What's Node.js? "Node.js is a server-side software system designed for writing scalable Internet applications, notably web servers. Programs are written on the server side in JavaScript, using event-driven, asynchronous I/O to minimize overhead and maximize scalability." - from wikipedia
  • 17. Node.js - asynchronous I/O ● First class functions ● Closures ● Event loop ● Callback counters CPU intensive tasks are delegated to workers
  • 18. PHP Way $fp = fopen("fp.txt", 'w) fwrite($fp, "hello world"); fclose($fp);
  • 19. Node.js way var fs = require('fs'); fs.open('fp.txt', 'w', 0666, function(error, fp) { fw.write(fp, 'helloworld', null, 'utf-8', function() { fs.close(fp, function(error) { }); }); });
  • 20. Node.js simple example var http = require('http'); http.createServer(function(req, res) { res.writeHead(200, {'Content-Type' : 'text/plain'}); res.end("Hello Worldn"); }).listen(8000, "127.0.0.1"); console.log("Server running at http: //127.0.0.1:8000");
  • 21. Node.js Core APIs Events EventTransmitter Event listener Event emitter Call back Http I/O
  • 22. Node.js Workers Synchronous call Workers are blocked Call returns
  • 23. Workers Vs Events Workers 1 event per connection N workers per CPU Events N connections per CPU 1 process per CPU
  • 24. Node.js Typical Applications ● Proxy ● API server ○ REST API calls ○ Simple transformations See performance comparisons at: http://www.slideshare.net/FabianFrankDe/nodejs-performance-case-study
  • 25. Concepts to learn First class functions Lambdas - anonymous functions Closures Non-blocking IO
  • 27. Key takeaway Learn Javascript and functional programming. Future is brighter :)
  • 28. Reference ● Node - Up and Running by Tom Hughes-Croucher, Mike Wilson - Oreilly ● Node.js for PHP Developers - Oreilly ● Javascript: The definitive guide - Oreilly ● LinkedIn, Netflix Blogs ● http://architects.dzone.com/articles/nodejs-php-programmers- 1-event ● https://www.udemy.com/lectures/understanding-the-nodejs- event-loop-91298 ● https://speakerdeck.com/guldenpt/before-start-coding-in- node-dot-js