SlideShare a Scribd company logo
1 of 30
Download to read offline
Efficient use of
NodeJS

Yuriy Bogdanov
Inspiration-driven software engineer
My experience
• 10 years of web development
• 2009-2012 own projects
• 3 years of NodeJS on production, starting
  from earliest versions
• Full-stack-JS projects
Eventr, 2010
• Have ~70k RSS/Atom up to date
• Tricky TTL logic
• ~10 feeds per second (in peak)
• A lot of I/O, less CPU
• On PHP was a lot of processes, and a lot of
  redundancy
• http://habrahabr.ru/post/95526/
Eventr, 2010
• NodeJS v0.1.x
• Rewritten feeds updating on Node
• Performance x25 vs PHP
• Despite the newness of technology, it was
  successful
Tactoom, 2011
• Being inspired, I decided to write the next
  project completely on JS
• NodeJS v0.4.x
• It was a failure, the technology wasn’t
  justified in this context
• http://habrahabr.ru/post/130345/
NodeJS, 2012
• Successful experience with NodeJS
• Realtime solutions for IP-telephony
• Big data exchange on S3
Efficient use of NodeJS

• NodeJS is easy-going, but it's unpredictable
  outside of your laptop
• NodeJS though seems to be multipurpose,
  but for my opinion, has a rather narrow
  scope of effective usage
• You better not use NodeJS in cases where
  Ruby, PHP, etc. will do it easily
Mythology
Node.js is a platform built on Chrome's JavaScript runtime for easily
building fast, scalable network applications. Node.js uses an event-
driven, non-blocking I/O model that makes it lightweight and
efficient, perfect for data-intensive real-time applications that run
across distributed devices.


                                                    (c) nodejs.org
Fast?
• V8 - yes, fast, but this speed is not the main
  bottleneck today
• non-blocking I/O - makes sense, if you really
  have a lot of I/O
A typical task
                 User’s page
• Display a page with following data:
  1. Posts
  2. Following
  3. Followers
Arithmetics
User’s page:               Ti me


• db.getUserFeed()              CPU
                                10%
• db.getUserFollowing()
• db.getUserFollowers()
                          I/O
Time:                     90%

• I/O - query to DB
• CPU - handling data
Arithmetics
     userPageAction: function(callback) {
50ms   db.getUserFeed(function(err, feed){
         if (err) return callback(err);
30ms     db.getUserFollowing(function(err, following){
           if (err) return callback(err);
40ms       db.getUserFollowers(function(err, followers){
             if (err) return callback(err);
             callback(null, {
               feed: feed,
               following: following,
               followers: followers
             });
           });
         });
       });

                          ~120ms
     }
Arithmetics
       userPageAction: function(callback) {

50ms
         async.parallel({
           feed: function(callback) {
                                                 50ms
45 + 5        db.getUserFeed(callback);
           },
30ms       following: function(callback) {
27 + 3        db.getUserFollowing(callback);
           },
40ms       followers: function(callback) {
36 + 4        db.getUserFollowers(callback);
           }
         }, callback);
       }
                                        45 + 5 = 50ms
                            node-async
                             by Caolan McMahon
Arithmetics
     userPageAction: function() {
       var feed = db.getUserFeed.future(db),
            following = db.getUserFollowing.future(db),
            followers = db.getUserFollowers.future(db);
       return {
50ms      feed: feed.yield(),
30ms      following: following.yield(),
40ms      followers: followers.yield()
       };
     }.async()



                                        45 + 5 = 50ms
                           node-sync
                             by Yuriy Bogdanov
Arithmetics
120ms                                 50ms
S e qu en ti al                            Parallel
                                                            5+3+4=
                                                            12ms
        CPU
        10%                                           CPU
                                                      21%




                                     I/O
I/O                                  79%
90%



                   CPU utilization
Arithmetics
Your laptop              Production

       CPU
       21%

                                 CPU
                                 100%

I/O
79%




        While CPU is free,
       parallelism is efficient
Arithmetics
                                  concurrency

     CPU 21%                                    ~ Response time
           benchmark                    expected            real
 ab -n 1 -c 1                              50ms             52ms

 ab -n 100 -c 1                            50ms             50ms

 ab -n 100 -c 10                           50ms            123ms
                                                             x2

 ab -n 100 -c 100                          50ms            981ms
                                                             x20

https://github.com/0ctave/node-bench                   120ms x 8
Arithmetics
                        concurrency


CPU    Response time Response time under load


21%            50ms                             981ms


10%           120ms                            1212ms
                                                   +23%



                ab -n 100 -c 100
      http://www.slideshare.net/yurabogdanov/nodejs-8223169
Arithmetics
PHP                  NodeJS




           Time




CPU/IO            CPU         I/O
thread            thread   threads
Arithmetics
                    conclusions


• As more I/O part, as more profitable to use
  NodeJS
• And vice-versa :)
• Parallelism within a single request does
  nothing (under load)
• That is, synchronous Ruby have done better
  with given task
• But there are other problems...
Language & Platform
• JavaScript is super flexible, which is not
  always an advantage for the server
  technology
• There are many non-obvious nuances of
  the technology itself, which must always be
  considered
• In the absence of a clear convention it’s
  difficult to design a great app
JavaScript
getUserNetwork: function(callback) {
  var db = this.getDb();
      userId = this.getSessionUserId();

    db.getUserFollowing(userId, function(err, following){
      if (err) return callback(err);

      db.getUserFollowers(userId, function(err, followers){
        if (err) return callback(err);

        callback(null, {
          following: following,
          followers: followers
        });
      });
    });
}
JavaScript
• CoffeeScript
• JSLint
• node --use_strict (starting from 0.9.х)
$ node --use_strict app.js

./node_modules/express/node_modules/debug/lib/debug.js:119
    + ' +' + humanize(ms) + '033[0m'

SyntaxError: Octal literals are not allowed in strict mode.
Language & Platform
• monkey-patching is convenient, but it
  leads to difficulties when debugging
• event emitter difficult to debug and it is
  often misused
• Difficult to avoid memory leaks, especially
  with the use of third-party libraries
• There is no decent way to debug, especially
  on production
Language & Platform
JavaScript is much easier on front-end:

• No multi-user aspect
• Memory leaks is not a such problem
• Less async stuff
• Mature frameworks and standards
Language & Platform
                    Bad reliability

•   One process serves many request at the time

•   Therefore, the error in a single request can:

    •   lead to loss / collision of data
    •   hanging the hundreds of other requests
    •   compromise the integrity of the system

•   No guaranteed isolation stack for each request /
    session (as, for example, in erlang)
Language & Platform
             Bad reliability

      CPU1      CPU2      CPU3      CPU4



     node1      node2     node3     node4




                                     -250
                  1,000
               connections

   http://mr-aleph.livejournal.com/322682.html
Shared state
var counter = 0;
app.get('/', function(req, res){
  res.send('Counter: ' + counter);
  counter++;
});



• Very convenient for a sort of tasks
• Loses favor when scaling
• Difficult to make reliable
So what to do with NodeJS?
• Far from users as possible
• Where thethroat" predictable, where you
  can "pinch
              load is

• I/O intensive, CPU free
• Do «kill -9» reliable
 •   have a persistence data layer
 •   do atomic operations
 •   use transactions when possible
• Not for a vital features
• Things you can not do without it
Yuriy Bogdanov
About.me: http://about.me/bogdanov
    Github: https://github.com/0ctave
   Twitter: http://twitter.com/yuriybogdanov
 LinkedIn: http://linkedin.com/in/yuriybogdanov
Habrahabr: http://octave.habrahabr.ru/

     Email: octave@tactoom.com


         Thanks for your attention

More Related Content

What's hot

Building Google Cloud ML Engine From Scratch on AWS with PipelineAI - ODSC Lo...
Building Google Cloud ML Engine From Scratch on AWS with PipelineAI - ODSC Lo...Building Google Cloud ML Engine From Scratch on AWS with PipelineAI - ODSC Lo...
Building Google Cloud ML Engine From Scratch on AWS with PipelineAI - ODSC Lo...Chris Fregly
 
Parallelization using open mp
Parallelization using open mpParallelization using open mp
Parallelization using open mpranjit banshpal
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded ProgrammingSri Prasanna
 
Intro to OpenMP
Intro to OpenMPIntro to OpenMP
Intro to OpenMPjbp4444
 
High Performance TensorFlow in Production - Big Data Spain - Madrid - Nov 15 ...
High Performance TensorFlow in Production - Big Data Spain - Madrid - Nov 15 ...High Performance TensorFlow in Production - Big Data Spain - Madrid - Nov 15 ...
High Performance TensorFlow in Production - Big Data Spain - Madrid - Nov 15 ...Chris Fregly
 
Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on G...
Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on G...Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on G...
Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on G...Chris Fregly
 
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...srisatish ambati
 
Optimizing, Profiling, and Deploying TensorFlow AI Models in Production with ...
Optimizing, Profiling, and Deploying TensorFlow AI Models in Production with ...Optimizing, Profiling, and Deploying TensorFlow AI Models in Production with ...
Optimizing, Profiling, and Deploying TensorFlow AI Models in Production with ...Chris Fregly
 
Presentation on Shared Memory Parallel Programming
Presentation on Shared Memory Parallel ProgrammingPresentation on Shared Memory Parallel Programming
Presentation on Shared Memory Parallel ProgrammingVengada Karthik Rangaraju
 
PipelineAI Optimizes Your Enterprise AI Pipeline from Distributed Training to...
PipelineAI Optimizes Your Enterprise AI Pipeline from Distributed Training to...PipelineAI Optimizes Your Enterprise AI Pipeline from Distributed Training to...
PipelineAI Optimizes Your Enterprise AI Pipeline from Distributed Training to...Chris Fregly
 
Hyper-Parameter Tuning Across the Entire AI Pipeline GPU Tech Conference San ...
Hyper-Parameter Tuning Across the Entire AI Pipeline GPU Tech Conference San ...Hyper-Parameter Tuning Across the Entire AI Pipeline GPU Tech Conference San ...
Hyper-Parameter Tuning Across the Entire AI Pipeline GPU Tech Conference San ...Chris Fregly
 
Timelapse: interactive record/replay for the web
Timelapse: interactive record/replay for the webTimelapse: interactive record/replay for the web
Timelapse: interactive record/replay for the webbrrian
 
Advanced Spark and TensorFlow Meetup May 26, 2016
Advanced Spark and TensorFlow Meetup May 26, 2016Advanced Spark and TensorFlow Meetup May 26, 2016
Advanced Spark and TensorFlow Meetup May 26, 2016Chris Fregly
 

What's hot (20)

Building Google Cloud ML Engine From Scratch on AWS with PipelineAI - ODSC Lo...
Building Google Cloud ML Engine From Scratch on AWS with PipelineAI - ODSC Lo...Building Google Cloud ML Engine From Scratch on AWS with PipelineAI - ODSC Lo...
Building Google Cloud ML Engine From Scratch on AWS with PipelineAI - ODSC Lo...
 
Open mp intro_01
Open mp intro_01Open mp intro_01
Open mp intro_01
 
Parallelization using open mp
Parallelization using open mpParallelization using open mp
Parallelization using open mp
 
OpenMP
OpenMPOpenMP
OpenMP
 
OpenMP And C++
OpenMP And C++OpenMP And C++
OpenMP And C++
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
 
Intro to OpenMP
Intro to OpenMPIntro to OpenMP
Intro to OpenMP
 
High Performance TensorFlow in Production - Big Data Spain - Madrid - Nov 15 ...
High Performance TensorFlow in Production - Big Data Spain - Madrid - Nov 15 ...High Performance TensorFlow in Production - Big Data Spain - Madrid - Nov 15 ...
High Performance TensorFlow in Production - Big Data Spain - Madrid - Nov 15 ...
 
Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on G...
Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on G...Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on G...
Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on G...
 
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
 
openmp
openmpopenmp
openmp
 
Optimizing, Profiling, and Deploying TensorFlow AI Models in Production with ...
Optimizing, Profiling, and Deploying TensorFlow AI Models in Production with ...Optimizing, Profiling, and Deploying TensorFlow AI Models in Production with ...
Optimizing, Profiling, and Deploying TensorFlow AI Models in Production with ...
 
Presentation on Shared Memory Parallel Programming
Presentation on Shared Memory Parallel ProgrammingPresentation on Shared Memory Parallel Programming
Presentation on Shared Memory Parallel Programming
 
Apache con 2011 gd
Apache con 2011 gdApache con 2011 gd
Apache con 2011 gd
 
PipelineAI Optimizes Your Enterprise AI Pipeline from Distributed Training to...
PipelineAI Optimizes Your Enterprise AI Pipeline from Distributed Training to...PipelineAI Optimizes Your Enterprise AI Pipeline from Distributed Training to...
PipelineAI Optimizes Your Enterprise AI Pipeline from Distributed Training to...
 
Ndp Slides
Ndp SlidesNdp Slides
Ndp Slides
 
Open Source Debugging v1.3.2
Open Source Debugging v1.3.2Open Source Debugging v1.3.2
Open Source Debugging v1.3.2
 
Hyper-Parameter Tuning Across the Entire AI Pipeline GPU Tech Conference San ...
Hyper-Parameter Tuning Across the Entire AI Pipeline GPU Tech Conference San ...Hyper-Parameter Tuning Across the Entire AI Pipeline GPU Tech Conference San ...
Hyper-Parameter Tuning Across the Entire AI Pipeline GPU Tech Conference San ...
 
Timelapse: interactive record/replay for the web
Timelapse: interactive record/replay for the webTimelapse: interactive record/replay for the web
Timelapse: interactive record/replay for the web
 
Advanced Spark and TensorFlow Meetup May 26, 2016
Advanced Spark and TensorFlow Meetup May 26, 2016Advanced Spark and TensorFlow Meetup May 26, 2016
Advanced Spark and TensorFlow Meetup May 26, 2016
 

Viewers also liked

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
5 Ways to use Node in the Network
5 Ways to use Node in the Network5 Ways to use Node in the Network
5 Ways to use Node in the NetworkF5 Networks
 
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...Ivan Loire
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginnersEnoch Joshua
 
When to use Node? Lessons learned
When to use Node? Lessons learnedWhen to use Node? Lessons learned
When to use Node? Lessons learnedbeatlevic
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to NodejsGabriele Lana
 
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介NodeJS基礎教學&簡介
NodeJS基礎教學&簡介GO LL
 
Alphorm.com Formation NodeJS, les fondamentaux
Alphorm.com Formation NodeJS, les fondamentauxAlphorm.com Formation NodeJS, les fondamentaux
Alphorm.com Formation NodeJS, les fondamentauxAlphorm
 
What is Node and Why does it Matter?
What is Node and Why does it Matter?What is Node and Why does it Matter?
What is Node and Why does it Matter?Dominiek ter Heide
 

Viewers also liked (11)

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
5 Ways to use Node in the Network
5 Ways to use Node in the Network5 Ways to use Node in the Network
5 Ways to use Node in the Network
 
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
 
When to use Node? Lessons learned
When to use Node? Lessons learnedWhen to use Node? Lessons learned
When to use Node? Lessons learned
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介NodeJS基礎教學&簡介
NodeJS基礎教學&簡介
 
Nodejs intro
Nodejs introNodejs intro
Nodejs intro
 
Alphorm.com Formation NodeJS, les fondamentaux
Alphorm.com Formation NodeJS, les fondamentauxAlphorm.com Formation NodeJS, les fondamentaux
Alphorm.com Formation NodeJS, les fondamentaux
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
What is Node and Why does it Matter?
What is Node and Why does it Matter?What is Node and Why does it Matter?
What is Node and Why does it Matter?
 

Similar to Efficient use of NodeJS

Performance Oriented Design
Performance Oriented DesignPerformance Oriented Design
Performance Oriented DesignRodrigo Campos
 
Python Load Testing - Pygotham 2012
Python Load Testing - Pygotham 2012Python Load Testing - Pygotham 2012
Python Load Testing - Pygotham 2012Dan Kuebrich
 
Node.js Performance Case Study
Node.js Performance Case StudyNode.js Performance Case Study
Node.js Performance Case StudyFabian Frank
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.jsChris Cowan
 
Making fitting in RooFit faster
Making fitting in RooFit fasterMaking fitting in RooFit faster
Making fitting in RooFit fasterPatrick Bos
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1Mohammad Qureshi
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorStéphane Maldini
 
PerfUG 3 - perfs système
PerfUG 3 - perfs systèmePerfUG 3 - perfs système
PerfUG 3 - perfs systèmeLudovic Piot
 
IBM InterConnect: Java vs JavaScript for Enterprise WebApps
IBM InterConnect: Java vs JavaScript for Enterprise WebAppsIBM InterConnect: Java vs JavaScript for Enterprise WebApps
IBM InterConnect: Java vs JavaScript for Enterprise WebAppsChris Bailey
 
Speed up R with parallel programming in the Cloud
Speed up R with parallel programming in the CloudSpeed up R with parallel programming in the Cloud
Speed up R with parallel programming in the CloudRevolution Analytics
 
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"LogeekNightUkraine
 
From Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptxFrom Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptxVictor Rentea
 
Capacity Planning for fun & profit
Capacity Planning for fun & profitCapacity Planning for fun & profit
Capacity Planning for fun & profitRodrigo Campos
 
JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015Charles Nutter
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Advanced Python, Part 2
Advanced Python, Part 2Advanced Python, Part 2
Advanced Python, Part 2Zaar Hai
 
OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...
OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...
OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...OpenNebula Project
 
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.9Ilya Grigorik
 

Similar to Efficient use of NodeJS (20)

Performance Oriented Design
Performance Oriented DesignPerformance Oriented Design
Performance Oriented Design
 
Python Load Testing - Pygotham 2012
Python Load Testing - Pygotham 2012Python Load Testing - Pygotham 2012
Python Load Testing - Pygotham 2012
 
Node.js Performance Case Study
Node.js Performance Case StudyNode.js Performance Case Study
Node.js Performance Case Study
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
Making fitting in RooFit faster
Making fitting in RooFit fasterMaking fitting in RooFit faster
Making fitting in RooFit faster
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and Reactor
 
PerfUG 3 - perfs système
PerfUG 3 - perfs systèmePerfUG 3 - perfs système
PerfUG 3 - perfs système
 
IBM InterConnect: Java vs JavaScript for Enterprise WebApps
IBM InterConnect: Java vs JavaScript for Enterprise WebAppsIBM InterConnect: Java vs JavaScript for Enterprise WebApps
IBM InterConnect: Java vs JavaScript for Enterprise WebApps
 
Speed up R with parallel programming in the Cloud
Speed up R with parallel programming in the CloudSpeed up R with parallel programming in the Cloud
Speed up R with parallel programming in the Cloud
 
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
 
From Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptxFrom Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptx
 
Cloud Probing
Cloud ProbingCloud Probing
Cloud Probing
 
Capacity Planning for fun & profit
Capacity Planning for fun & profitCapacity Planning for fun & profit
Capacity Planning for fun & profit
 
JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Advanced Python, Part 2
Advanced Python, Part 2Advanced Python, Part 2
Advanced Python, Part 2
 
Load testing with Blitz
Load testing with BlitzLoad testing with Blitz
Load testing with Blitz
 
OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...
OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...
OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...
 
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
 

Recently uploaded

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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 WorkerThousandEyes
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
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 Scriptwesley chun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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 DevelopmentsTrustArc
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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 educationjfdjdjcjdnsjd
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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 FresherRemote DBA Services
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Efficient use of NodeJS

  • 1. Efficient use of NodeJS Yuriy Bogdanov Inspiration-driven software engineer
  • 2. My experience • 10 years of web development • 2009-2012 own projects • 3 years of NodeJS on production, starting from earliest versions • Full-stack-JS projects
  • 3. Eventr, 2010 • Have ~70k RSS/Atom up to date • Tricky TTL logic • ~10 feeds per second (in peak) • A lot of I/O, less CPU • On PHP was a lot of processes, and a lot of redundancy • http://habrahabr.ru/post/95526/
  • 4. Eventr, 2010 • NodeJS v0.1.x • Rewritten feeds updating on Node • Performance x25 vs PHP • Despite the newness of technology, it was successful
  • 5. Tactoom, 2011 • Being inspired, I decided to write the next project completely on JS • NodeJS v0.4.x • It was a failure, the technology wasn’t justified in this context • http://habrahabr.ru/post/130345/
  • 6. NodeJS, 2012 • Successful experience with NodeJS • Realtime solutions for IP-telephony • Big data exchange on S3
  • 7. Efficient use of NodeJS • NodeJS is easy-going, but it's unpredictable outside of your laptop • NodeJS though seems to be multipurpose, but for my opinion, has a rather narrow scope of effective usage • You better not use NodeJS in cases where Ruby, PHP, etc. will do it easily
  • 8. Mythology Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event- driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. (c) nodejs.org
  • 9. Fast? • V8 - yes, fast, but this speed is not the main bottleneck today • non-blocking I/O - makes sense, if you really have a lot of I/O
  • 10. A typical task User’s page • Display a page with following data: 1. Posts 2. Following 3. Followers
  • 11. Arithmetics User’s page: Ti me • db.getUserFeed() CPU 10% • db.getUserFollowing() • db.getUserFollowers() I/O Time: 90% • I/O - query to DB • CPU - handling data
  • 12. Arithmetics userPageAction: function(callback) { 50ms db.getUserFeed(function(err, feed){ if (err) return callback(err); 30ms db.getUserFollowing(function(err, following){ if (err) return callback(err); 40ms db.getUserFollowers(function(err, followers){ if (err) return callback(err); callback(null, { feed: feed, following: following, followers: followers }); }); }); }); ~120ms }
  • 13. Arithmetics userPageAction: function(callback) { 50ms async.parallel({ feed: function(callback) { 50ms 45 + 5 db.getUserFeed(callback); }, 30ms following: function(callback) { 27 + 3 db.getUserFollowing(callback); }, 40ms followers: function(callback) { 36 + 4 db.getUserFollowers(callback); } }, callback); } 45 + 5 = 50ms node-async by Caolan McMahon
  • 14. Arithmetics userPageAction: function() { var feed = db.getUserFeed.future(db), following = db.getUserFollowing.future(db), followers = db.getUserFollowers.future(db); return { 50ms feed: feed.yield(), 30ms following: following.yield(), 40ms followers: followers.yield() }; }.async() 45 + 5 = 50ms node-sync by Yuriy Bogdanov
  • 15. Arithmetics 120ms 50ms S e qu en ti al Parallel 5+3+4= 12ms CPU 10% CPU 21% I/O I/O 79% 90% CPU utilization
  • 16. Arithmetics Your laptop Production CPU 21% CPU 100% I/O 79% While CPU is free, parallelism is efficient
  • 17. Arithmetics concurrency CPU 21% ~ Response time benchmark expected real ab -n 1 -c 1 50ms 52ms ab -n 100 -c 1 50ms 50ms ab -n 100 -c 10 50ms 123ms x2 ab -n 100 -c 100 50ms 981ms x20 https://github.com/0ctave/node-bench 120ms x 8
  • 18. Arithmetics concurrency CPU Response time Response time under load 21% 50ms 981ms 10% 120ms 1212ms +23% ab -n 100 -c 100 http://www.slideshare.net/yurabogdanov/nodejs-8223169
  • 19. Arithmetics PHP NodeJS Time CPU/IO CPU I/O thread thread threads
  • 20. Arithmetics conclusions • As more I/O part, as more profitable to use NodeJS • And vice-versa :) • Parallelism within a single request does nothing (under load) • That is, synchronous Ruby have done better with given task • But there are other problems...
  • 21. Language & Platform • JavaScript is super flexible, which is not always an advantage for the server technology • There are many non-obvious nuances of the technology itself, which must always be considered • In the absence of a clear convention it’s difficult to design a great app
  • 22. JavaScript getUserNetwork: function(callback) { var db = this.getDb(); userId = this.getSessionUserId(); db.getUserFollowing(userId, function(err, following){ if (err) return callback(err); db.getUserFollowers(userId, function(err, followers){ if (err) return callback(err); callback(null, { following: following, followers: followers }); }); }); }
  • 23. JavaScript • CoffeeScript • JSLint • node --use_strict (starting from 0.9.х) $ node --use_strict app.js ./node_modules/express/node_modules/debug/lib/debug.js:119 + ' +' + humanize(ms) + '033[0m' SyntaxError: Octal literals are not allowed in strict mode.
  • 24. Language & Platform • monkey-patching is convenient, but it leads to difficulties when debugging • event emitter difficult to debug and it is often misused • Difficult to avoid memory leaks, especially with the use of third-party libraries • There is no decent way to debug, especially on production
  • 25. Language & Platform JavaScript is much easier on front-end: • No multi-user aspect • Memory leaks is not a such problem • Less async stuff • Mature frameworks and standards
  • 26. Language & Platform Bad reliability • One process serves many request at the time • Therefore, the error in a single request can: • lead to loss / collision of data • hanging the hundreds of other requests • compromise the integrity of the system • No guaranteed isolation stack for each request / session (as, for example, in erlang)
  • 27. Language & Platform Bad reliability CPU1 CPU2 CPU3 CPU4 node1 node2 node3 node4 -250 1,000 connections http://mr-aleph.livejournal.com/322682.html
  • 28. Shared state var counter = 0; app.get('/', function(req, res){ res.send('Counter: ' + counter); counter++; }); • Very convenient for a sort of tasks • Loses favor when scaling • Difficult to make reliable
  • 29. So what to do with NodeJS? • Far from users as possible • Where thethroat" predictable, where you can "pinch load is • I/O intensive, CPU free • Do «kill -9» reliable • have a persistence data layer • do atomic operations • use transactions when possible • Not for a vital features • Things you can not do without it
  • 30. Yuriy Bogdanov About.me: http://about.me/bogdanov Github: https://github.com/0ctave Twitter: http://twitter.com/yuriybogdanov LinkedIn: http://linkedin.com/in/yuriybogdanov Habrahabr: http://octave.habrahabr.ru/ Email: octave@tactoom.com Thanks for your attention