SlideShare ist ein Scribd-Unternehmen logo
1 von 37
Downloaden Sie, um offline zu lesen
Lessons Learned
from Node.js
Jason Yau
Director of Engineering
Samsung Accelerator
Tuesday, October 8, 13
1. Node.js
2. Methodology
3. Callbacks
4. Promises
Tuesday, October 8, 13
Node.js is javascript
on the server side.
It’s event-driven, non-
blocking I/O model
makes it FAST and
scalable.
Tuesday, October 8, 13
Tuesday, October 8, 13
In most languages,
the code we write is
synchronous.
aka Blocking
Tuesday, October 8, 13
Blocking
Tuesday, October 8, 13
Waiting
Tuesday, October 8, 13
In javascript, we do
things differently;
asynchronously.
aka Non-blocking
Tuesday, October 8, 13
Non-Blocking
Tuesday, October 8, 13
Parallel
Tuesday, October 8, 13
Fast
http://benchmarksgame.alioth.debian.org/u64/benchmark.php?test=all&lang=v8&lang2=yarv&data=u64
Tuesday, October 8, 13
Javascript
Tuesday, October 8, 13
Popular
Tuesday, October 8, 13
Methodology
Tuesday, October 8, 13
I/O Latency
• L1: 3 cycles
• L2: 14 cycles
• RAM: 250 cycles
• DISK: 41,000,000 cycles
• NETWORK: 240,000,000 cycles
Tuesday, October 8, 13
A theoretical request.
Request Process Results
Query DB or Web Service Write to log file
Format Response
= blocking / waiting
Tuesday, October 8, 13
Scale with Threads
Scale with Processes
Thread 1
Thread 2
Thread 3
Thread 4
Process 1
Process 2
Process 3
Process 4
Tuesday, October 8, 13
Scale with Event Loop
Handles many concurrent requests in a single
process / thread
Process 1
Thread Pool
Tuesday, October 8, 13
Analogy
Tuesday, October 8, 13
Event Queue Thread Pool
Event Loop
Filesystem
Network
Process
Other
Scale with Event Loop
Tuesday, October 8, 13
Challenges with
Callbacks
Tuesday, October 8, 13
Recurring Question
Tuesday, October 8, 13
Callbacks Example
Tuesday, October 8, 13
Pyramid of Doom
Tuesday, October 8, 13
Debugging
Tuesday, October 8, 13
Parallel Example
Tuesday, October 8, 13
Promises
Tuesday, October 8, 13
What are promises?
A promise is an object that represents a one-time
event, typically the outcome of an async task like an
AJAX call. When a promise is returned, at first it is in a
pending state.
Eventually it’s either:
1. resolved - The promise is fulfilled with a value
2. rejected - The promise is broken
Tuesday, October 8, 13
Instead of calling a
passed callback,
return a promise.
Tuesday, October 8, 13
Callback example
Tuesday, October 8, 13
Return a promise
Tuesday, October 8, 13
Passed callback
Tuesday, October 8, 13
Return a promise
Tuesday, October 8, 13
Parallel I/O
Tuesday, October 8, 13
Promises are cleaner
Tuesday, October 8, 13
Instead of calling a
passed callback,
return a promise.
Promise me you’ll
remember promises.
Tuesday, October 8, 13
Thank You
Jason Yau
Director of Engineering, Samsung
work: jason@samsungaccelerator.com
Tuesday, October 8, 13

Weitere ähnliche Inhalte

Was ist angesagt?

Angular – Say Goodbye to Javascript Soup
Angular – Say Goodbye to Javascript SoupAngular – Say Goodbye to Javascript Soup
Angular – Say Goodbye to Javascript Soup
Graeme Foster
 
Rubygem Dev And Workflow
Rubygem Dev And WorkflowRubygem Dev And Workflow
Rubygem Dev And Workflow
Dr Nic Williams
 
บรรณานุกรม
บรรณานุกรมบรรณานุกรม
บรรณานุกรม
IShadow' Leo'os
 

Was ist angesagt? (20)

My month with Ruby
My month with RubyMy month with Ruby
My month with Ruby
 
Node.js Talk at jQuery Pittsburgh
Node.js Talk at jQuery PittsburghNode.js Talk at jQuery Pittsburgh
Node.js Talk at jQuery Pittsburgh
 
WordPress 201
WordPress 201WordPress 201
WordPress 201
 
Angular – Say Goodbye to Javascript Soup
Angular – Say Goodbye to Javascript SoupAngular – Say Goodbye to Javascript Soup
Angular – Say Goodbye to Javascript Soup
 
You’ll Never Believe How Easy Deployments Can Really Be... (PHPSW November 2015)
You’ll Never Believe How Easy Deployments Can Really Be... (PHPSW November 2015)You’ll Never Believe How Easy Deployments Can Really Be... (PHPSW November 2015)
You’ll Never Believe How Easy Deployments Can Really Be... (PHPSW November 2015)
 
Jetty and Tomcat
Jetty and TomcatJetty and Tomcat
Jetty and Tomcat
 
Rubygem Dev And Workflow
Rubygem Dev And WorkflowRubygem Dev And Workflow
Rubygem Dev And Workflow
 
Going Beyond Google Analytics
Going Beyond Google AnalyticsGoing Beyond Google Analytics
Going Beyond Google Analytics
 
Jump start php environment
Jump start php environmentJump start php environment
Jump start php environment
 
บรรณานุกรม
บรรณานุกรมบรรณานุกรม
บรรณานุกรม
 
JavaScript development methodology
JavaScript development methodologyJavaScript development methodology
JavaScript development methodology
 
Performance and optimization
Performance and optimizationPerformance and optimization
Performance and optimization
 
First Steps to Be Non-blocking on the Web
First Steps to Be Non-blocking on the WebFirst Steps to Be Non-blocking on the Web
First Steps to Be Non-blocking on the Web
 
Avatar Maven
Avatar MavenAvatar Maven
Avatar Maven
 
Websocket
WebsocketWebsocket
Websocket
 
PuppetConf 2015 - Testing - Richard Pijnenburg
PuppetConf 2015 - Testing - Richard PijnenburgPuppetConf 2015 - Testing - Richard Pijnenburg
PuppetConf 2015 - Testing - Richard Pijnenburg
 
Put kajakken på hylden - og få sexede windows services
Put kajakken på hylden - og få sexede windows servicesPut kajakken på hylden - og få sexede windows services
Put kajakken på hylden - og få sexede windows services
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Vue.JS Hello World
Vue.JS Hello WorldVue.JS Hello World
Vue.JS Hello World
 
The Once And Future Script Loader (v2)
The Once And Future Script Loader (v2)The Once And Future Script Loader (v2)
The Once And Future Script Loader (v2)
 

Ähnlich wie Lessons learned from Node.js - Callbacks / Promises

Web security at Meteor (Pivotal Labs)
Web security at Meteor (Pivotal Labs)Web security at Meteor (Pivotal Labs)
Web security at Meteor (Pivotal Labs)
Emily Stark
 
Intro to PHP Testing
Intro to PHP TestingIntro to PHP Testing
Intro to PHP Testing
Ran Mizrahi
 
[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design
Christopher Schmitt
 
실시간 웹 협업도구 만들기 V0.3
실시간 웹 협업도구 만들기 V0.3실시간 웹 협업도구 만들기 V0.3
실시간 웹 협업도구 만들기 V0.3
NAVER D2
 

Ähnlich wie Lessons learned from Node.js - Callbacks / Promises (20)

Bkbiet day1
Bkbiet day1Bkbiet day1
Bkbiet day1
 
DevOps Nirvana: Seven Steps to a Peaceful Life on AWS (ARC210) | AWS re:Inven...
DevOps Nirvana: Seven Steps to a Peaceful Life on AWS (ARC210) | AWS re:Inven...DevOps Nirvana: Seven Steps to a Peaceful Life on AWS (ARC210) | AWS re:Inven...
DevOps Nirvana: Seven Steps to a Peaceful Life on AWS (ARC210) | AWS re:Inven...
 
Microservices and functional programming
Microservices and functional programmingMicroservices and functional programming
Microservices and functional programming
 
Introduction to node.js by Ran Mizrahi @ Reversim Summit
Introduction to node.js by Ran Mizrahi @ Reversim SummitIntroduction to node.js by Ran Mizrahi @ Reversim Summit
Introduction to node.js by Ran Mizrahi @ Reversim Summit
 
Web security at Meteor (Pivotal Labs)
Web security at Meteor (Pivotal Labs)Web security at Meteor (Pivotal Labs)
Web security at Meteor (Pivotal Labs)
 
Front end-performance
Front end-performanceFront end-performance
Front end-performance
 
When Tdd Goes Awry
When Tdd Goes AwryWhen Tdd Goes Awry
When Tdd Goes Awry
 
Continuous Delivery for the Web Platform
Continuous Delivery for the Web PlatformContinuous Delivery for the Web Platform
Continuous Delivery for the Web Platform
 
2nd Annual Start-up Launches with Dr. Werner Vogels (SPOT101) | AWS re:Invent...
2nd Annual Start-up Launches with Dr. Werner Vogels (SPOT101) | AWS re:Invent...2nd Annual Start-up Launches with Dr. Werner Vogels (SPOT101) | AWS re:Invent...
2nd Annual Start-up Launches with Dr. Werner Vogels (SPOT101) | AWS re:Invent...
 
Continuous Delivery at Netflix
Continuous Delivery at NetflixContinuous Delivery at Netflix
Continuous Delivery at Netflix
 
Node.js: CAMTA Presentation
Node.js: CAMTA PresentationNode.js: CAMTA Presentation
Node.js: CAMTA Presentation
 
Reintroducing AlloyUI
Reintroducing AlloyUIReintroducing AlloyUI
Reintroducing AlloyUI
 
Intro to PHP Testing
Intro to PHP TestingIntro to PHP Testing
Intro to PHP Testing
 
Big Data & Cloud | Cloud Storage Simplified | Adrian Cole
Big Data & Cloud | Cloud Storage Simplified | Adrian ColeBig Data & Cloud | Cloud Storage Simplified | Adrian Cole
Big Data & Cloud | Cloud Storage Simplified | Adrian Cole
 
[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design
 
Become a Frontend Developer Ninja using HTML5, JavaScript and CSS3 - Marco Ca...
Become a Frontend Developer Ninja using HTML5, JavaScript and CSS3 - Marco Ca...Become a Frontend Developer Ninja using HTML5, JavaScript and CSS3 - Marco Ca...
Become a Frontend Developer Ninja using HTML5, JavaScript and CSS3 - Marco Ca...
 
Ruby meetup 7_years_in_testing
Ruby meetup 7_years_in_testingRuby meetup 7_years_in_testing
Ruby meetup 7_years_in_testing
 
XPages Blast - Lotusphere 2013
XPages Blast - Lotusphere 2013XPages Blast - Lotusphere 2013
XPages Blast - Lotusphere 2013
 
실시간 웹 협업도구 만들기 V0.3
실시간 웹 협업도구 만들기 V0.3실시간 웹 협업도구 만들기 V0.3
실시간 웹 협업도구 만들기 V0.3
 
Workers of the web - BrazilJS 2013
Workers of the web - BrazilJS 2013Workers of the web - BrazilJS 2013
Workers of the web - BrazilJS 2013
 

Kürzlich hochgeladen

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

Lessons learned from Node.js - Callbacks / Promises