SlideShare ist ein Scribd-Unternehmen logo
1 von 21
node.jsbuilding for high performance & high concurrency Nam Ho KMS Technology
About me ALT.NET Saigon (a .NET user group) Twitter - @hotrannam #altnetsg
Agenda Server models Non-Blocking I/O Programming model Demo
Multi-Threaded server Request A thread is created  in response to the request
Multi-Threaded server Spawning threads to handle concurrent requests
Multi-Threaded server Long running operations cause threads to block. Subsequent requests are in queue.
Multi-Threaded server Disadvantages Thread context switching is slow Threads take up too much memory Thread-per-connection does not scale
Blocking I/O Synchronous I/O Wait for I/O operations to complete Idle time var post = db.query(“select * from posts where id = 1”); // waiting, waiting, waiting showPost(post); // do something unrelated to post doAnotherThing();
Non-Blocking I/O Asynchronous I/O Continue processing Improve throughputand latency var post = db.query(“select * from posts where id = 1”, callback); doAnotherThing(); callback = function(post){ showPost(post);    }
Single-Threaded server Endless event-loop fires off long running operations and then moves to next request
Multi-Threaded vs. Single-Threaded http://blog.webfaction.com/a-little-holiday-present
Multi-Threaded vs. Single-Threaded http://blog.webfaction.com/a-little-holiday-present
What is Node Created by Ryan Dahl Google’s V8 JavaScript engine Event loop Non-blocking I/O Event binding
Where does Node fit Node is ideal for apps which have tens of thousands of  concurrent connections.
Why JavaScript First class function Closure  V8 is fast
A simple web server var http = require("http"); http.createServer(function(req, res){    res.writeHead(200, {"Content-Type": "text/plain"});    return res.end("Hello Barcamp Saigon"); }).listen(8080); console.log("Server running at port 8080");
Callback var http = require("http"); var callback = function(req, res){    res.writeHead(200, {"Content-Type": "text/plain"});    return res.end("Hello Barcamp Saigon"); } http.createServer(callback).listen(8080); console.log("Server running at port 8080");
Event binding var fs = require(“fs"); var readStream = fs.createReadStream(“/etc/sources”); readStream.addListener(“data”, function(data){    console.log(data); }); readStream.addListener(“end”, function(data){ console.log(“file ended”); });
Parallel vs. Serial var fs = require("fs"); function writeBarcamp(){    return fs.writeFile('./barcamp.txt', 'Hi Barcamp!',  function writeFile(err){         fs.readFile('./barcamp.txt', 'UTF-8', readFile);   }); } function writeNode(){    return fs.writeFile('./node.txt', 'Hi Node!',  function writeFile(err){          fs.readFile('./node.txt', 'UTF-8', readFile);    }); } function readFile(err){} writeBarcamp(); writeNode();
Demo
Thanks you! @hotrannam

Weitere ähnliche Inhalte

Was ist angesagt?

Life of an Fluentd event
Life of an Fluentd eventLife of an Fluentd event
Life of an Fluentd event
Kiyoto Tamura
 
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Fwdays
 

Was ist angesagt? (20)

Fluentd vs. Logstash for OpenStack Log Management
Fluentd vs. Logstash for OpenStack Log ManagementFluentd vs. Logstash for OpenStack Log Management
Fluentd vs. Logstash for OpenStack Log Management
 
Fluentd and AWS at classmethod
Fluentd and AWS at classmethodFluentd and AWS at classmethod
Fluentd and AWS at classmethod
 
Life of an Fluentd event
Life of an Fluentd eventLife of an Fluentd event
Life of an Fluentd event
 
Learn ELK in docker
Learn ELK in dockerLearn ELK in docker
Learn ELK in docker
 
Logging & Docker - Season 2
Logging & Docker - Season 2Logging & Docker - Season 2
Logging & Docker - Season 2
 
Attack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and KibanaAttack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and Kibana
 
From zero to hero - Easy log centralization with Logstash and Elasticsearch
From zero to hero - Easy log centralization with Logstash and ElasticsearchFrom zero to hero - Easy log centralization with Logstash and Elasticsearch
From zero to hero - Easy log centralization with Logstash and Elasticsearch
 
Fluentd v1 and Roadmap
Fluentd v1 and RoadmapFluentd v1 and Roadmap
Fluentd v1 and Roadmap
 
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
 
Logstash: Get to know your logs
Logstash: Get to know your logsLogstash: Get to know your logs
Logstash: Get to know your logs
 
MySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELKMySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELK
 
The ELK Stack - Get to Know Logs
The ELK Stack - Get to Know LogsThe ELK Stack - Get to Know Logs
The ELK Stack - Get to Know Logs
 
Logstash
LogstashLogstash
Logstash
 
The State of Logging on Docker
The State of Logging on DockerThe State of Logging on Docker
The State of Logging on Docker
 
On Centralizing Logs
On Centralizing LogsOn Centralizing Logs
On Centralizing Logs
 
Logging logs with Logstash - Devops MK 10-02-2016
Logging logs with Logstash - Devops MK 10-02-2016Logging logs with Logstash - Devops MK 10-02-2016
Logging logs with Logstash - Devops MK 10-02-2016
 
elk_stack_alexander_szalonnas
elk_stack_alexander_szalonnaselk_stack_alexander_szalonnas
elk_stack_alexander_szalonnas
 
Writing a fast HTTP parser
Writing a fast HTTP parserWriting a fast HTTP parser
Writing a fast HTTP parser
 
Load Balancing Applications with NGINX in a CoreOS Cluster
Load Balancing Applications with NGINX in a CoreOS ClusterLoad Balancing Applications with NGINX in a CoreOS Cluster
Load Balancing Applications with NGINX in a CoreOS Cluster
 
Rsyslog log normalization
Rsyslog log normalizationRsyslog log normalization
Rsyslog log normalization
 

Andere mochten auch (6)

Ruby on Rails 3
Ruby on Rails 3Ruby on Rails 3
Ruby on Rails 3
 
Multi tenancy
Multi tenancyMulti tenancy
Multi tenancy
 
Applied Redis
Applied RedisApplied Redis
Applied Redis
 
jQuery plugins - templates, data link, globalization
jQuery plugins - templates, data link, globalizationjQuery plugins - templates, data link, globalization
jQuery plugins - templates, data link, globalization
 
Microsoft Windows Azure in short
Microsoft Windows Azure in shortMicrosoft Windows Azure in short
Microsoft Windows Azure in short
 
Building real time web apps with Meteor
Building real time web apps with MeteorBuilding real time web apps with Meteor
Building real time web apps with Meteor
 

Ähnlich wie Node.js

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Richard Lee
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
martincabrera
 
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
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.io
Rick Copeland
 

Ähnlich wie Node.js (20)

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
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 
Intro to Node
Intro to NodeIntro to Node
Intro to Node
 
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...
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
No callbacks, No Threads - Cooperative web servers in Ruby 1.9No callbacks, No Threads - Cooperative web servers in Ruby 1.9
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
 
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...
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
Node.js: CAMTA Presentation
Node.js: CAMTA PresentationNode.js: CAMTA Presentation
Node.js: CAMTA Presentation
 
Scaling Ruby with Evented I/O - Ruby underground
Scaling Ruby with Evented I/O - Ruby undergroundScaling Ruby with Evented I/O - Ruby underground
Scaling Ruby with Evented I/O - Ruby underground
 
GeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime WebGeekCampSG - Nodejs , Websockets and Realtime Web
GeekCampSG - Nodejs , Websockets and Realtime Web
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.io
 
Javazone 2010-lift-framework-public
Javazone 2010-lift-framework-publicJavazone 2010-lift-framework-public
Javazone 2010-lift-framework-public
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
 
No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

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, ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
"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 ...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Node.js

  • 1. node.jsbuilding for high performance & high concurrency Nam Ho KMS Technology
  • 2. About me ALT.NET Saigon (a .NET user group) Twitter - @hotrannam #altnetsg
  • 3. Agenda Server models Non-Blocking I/O Programming model Demo
  • 4. Multi-Threaded server Request A thread is created in response to the request
  • 5. Multi-Threaded server Spawning threads to handle concurrent requests
  • 6. Multi-Threaded server Long running operations cause threads to block. Subsequent requests are in queue.
  • 7. Multi-Threaded server Disadvantages Thread context switching is slow Threads take up too much memory Thread-per-connection does not scale
  • 8. Blocking I/O Synchronous I/O Wait for I/O operations to complete Idle time var post = db.query(“select * from posts where id = 1”); // waiting, waiting, waiting showPost(post); // do something unrelated to post doAnotherThing();
  • 9. Non-Blocking I/O Asynchronous I/O Continue processing Improve throughputand latency var post = db.query(“select * from posts where id = 1”, callback); doAnotherThing(); callback = function(post){ showPost(post); }
  • 10. Single-Threaded server Endless event-loop fires off long running operations and then moves to next request
  • 11. Multi-Threaded vs. Single-Threaded http://blog.webfaction.com/a-little-holiday-present
  • 12. Multi-Threaded vs. Single-Threaded http://blog.webfaction.com/a-little-holiday-present
  • 13. What is Node Created by Ryan Dahl Google’s V8 JavaScript engine Event loop Non-blocking I/O Event binding
  • 14. Where does Node fit Node is ideal for apps which have tens of thousands of concurrent connections.
  • 15. Why JavaScript First class function Closure V8 is fast
  • 16. A simple web server var http = require("http"); http.createServer(function(req, res){ res.writeHead(200, {"Content-Type": "text/plain"}); return res.end("Hello Barcamp Saigon"); }).listen(8080); console.log("Server running at port 8080");
  • 17. Callback var http = require("http"); var callback = function(req, res){ res.writeHead(200, {"Content-Type": "text/plain"}); return res.end("Hello Barcamp Saigon"); } http.createServer(callback).listen(8080); console.log("Server running at port 8080");
  • 18. Event binding var fs = require(“fs"); var readStream = fs.createReadStream(“/etc/sources”); readStream.addListener(“data”, function(data){ console.log(data); }); readStream.addListener(“end”, function(data){ console.log(“file ended”); });
  • 19. Parallel vs. Serial var fs = require("fs"); function writeBarcamp(){ return fs.writeFile('./barcamp.txt', 'Hi Barcamp!', function writeFile(err){ fs.readFile('./barcamp.txt', 'UTF-8', readFile); }); } function writeNode(){ return fs.writeFile('./node.txt', 'Hi Node!', function writeFile(err){ fs.readFile('./node.txt', 'UTF-8', readFile); }); } function readFile(err){} writeBarcamp(); writeNode();
  • 20. Demo