際際滷

際際滷Share a Scribd company logo
Performance Case Study
          @Fabian_Frank
       <fabian@pagefault.de>

       Yahoo! Search, Engineer
      Youthmedia.eu,Volunteer
A Dynamic Website
self-contained App
self-contained App
self-contained App
node v0.4.X
                                   multi-core




http://developer.yahoo.com/blogs/ydn/posts/2010/07/multicore_http_server_with_nodejs/
Time Sharing

 Workers

 Event Queue
Event Queue
 does only one thing at a time

 events that occur are queued for
  processing


 after an event was processed the next one
  is fetched from the queue
The difference
   Workers                    Event Queue

1. synchronous call        1. asynchronous call that
                              speci鍖es event(s) that can
2. worker blocked             occur (callback)

3. periodically check if   2. process next event
   worker can go ahead
                           3. speci鍖ed event occurs and
4. call returns               is put on the queue

5. worker goes ahead on    4. process goes ahead
   next check
Another difference

  Workers               Event Queue

 1 connection per     N connections per
  worker                process

 N workers per CPU    1 process (per CPU)
Regarding...
 static 鍖le serving benchmarks
  are not relevant, unless you plan to do
    heavy duty static 鍖le serving (Im not)
 hello world benchmarks
  still ignore most of what matters, e.g.
    accessing a database or other back-ends
Realistic
Real World Benchmark
 a lot of variables that have to be controlled
 more complex, likely to surface weird bugs
 face unanswerable questions
 are expensive to do
 are easy to attack, but hard to defend
My Reasoning

 I can not compare everything out there
  against everything else. But I can compare
  what I want to use in the future against what
  I am using today.
Search Case Study
 Right Panel retrieved using AJAX
 { html: <div>...</div>, css: ..., js: ..., ... }
Refresh Right Panel
1. receive a request                    JSON API

2. call a JSON API over HTTP                     2.
3. manipulate the data structure         Node.js 3.
                                                   4.
4. render it as HTML using Mustache   1.        5.
5. write back wrapped in JSON            Client
Refresh Right Panel
1. receive a request                   JSON API

2. call a JSON API over HTTP                     2.
3. manipulate the data structure             xy 3.
                                          ro 4.
                                         Node.js
                                         P
4. render it as HTML using Mustache   1.        5.
5. write back wrapped in JSON            Client
Constraints

 Network bandwidth and latency
  Gigabit and 1ms

 JSON API performance
  load-balanced cluster with cache
Implementations

 Apache + PHP

 Node.js (+ YUI)

 Manhattan + Mojito
Apache + PHP

 works, in production for decades
 initial response times are good enough
 scales, but you need $$$
 baseline to get a feeling for the numbers
Apache + PHP


 430req/s @ 60ms average latency
  99% @ 114ms
Node.js (+ YUI)

 works, but very new and untested stack
 initial response times are very low
 scales extremely well
 YUI works well, but still has pitfalls
Node.js Fun Facts
 >3100 requests per second
  100k requests in 32s
  9MByte/s network traf鍖c

 serve >2k req/s at 20ms average latency
  99% @ 47ms
Node.js
Node.js
Node.js Histogram
~1500req/s | 25 conc.
    12000


                                                                               99% @ 35ms
    10000




        8000
frequency




        6000




        4000




        2000




            0
                11.000 - 17.300 - 23.600 - 29.900 - 36.200 - 42.500 - 48.800 - 55.100 - 61.400 - 67.700 - 74.000 -
                 17.300 23.600 29.900 36.200 42.500 48.800 55.100 61.400 67.700 74.000 80.300
Node.js Histogram
            ~2900/s | 100 conc.
        9000


        8000
                                                                                99% @ 79ms
        7000


        6000
frequency




        5000


        4000


        3000


        2000


        1000


            0
                12.000 - 22.000 - 32.000 - 42.000 - 52.000 - 62.000 - 72.000 - 82.000 - 92.000 - 102.000 - 112.000 -
                 22.000 32.000 42.000 52.000 62.000 72.000 82.000 92.000 102.000 112.000 122.000
Node.js Histogram
            ~3100/s | 200 conc.
        8000



        7000
                                                                                99% @ 152ms
        6000



        5000
frequency




        4000



        3000



        2000



        1000



            0
                14.000 - 33.900 - 53.800 - 73.700 - 93.600 - 113.500 - 133.400 - 153.300 - 173.200 - 193.100 - 213.000 -
                 33.900 53.800 73.700 93.600 113.500 133.400 153.300 173.200 193.100 213.000 232.900
Manhattan + Mojito

 works, but extremely new and untested
  stack
 initial response times are low (60%
  compared to Apache/PHP)
 scales well (twice as good as Apache/PHP)
Manhattan + Mojito
Manhattan + Mojito
Findings
 Both node.js implementations scale linearly
  before CPU usage hits 100%
 Node.js scales extremely well as proxy
 Manhattan and Mojito can perform better
  than Apache and PHP (for this use case)
 Node.js applications are very sensitive to
  memory leaks or complex/blocking code
DNS in Node.js
 getaddrinfo() sys call is synchronous
  gethostbyname() is, too
 ares_gethostbyname() is asynchronous
  no cache
 node 0.6 uses a getaddrinfo() thread pool,
  but still relies on ares for other calls
Cocktails

 Manhattan

 Mojito
Manhattan?

    Yahoo!s Node.js cloud
    can run any node.js application
    allows calls to HTTP APIs (e.g.YQL)
    deployment of versioned apps
    apps can specify their environment
http://developer.yahoo.com/blogs/ydn/posts/2011/11/yahoo-announces-cocktails-%E2%80%93-shaken-not-stirred/
Mojito?
    Yahoo!s Node.js MVC framework
    provides identical similar runtime for your
         code on the client and server
    contains all server- and client-side code
    built on top of YUI
    will be open sourced
http://developer.yahoo.com/blogs/ydn/posts/2011/11/yahoo-announces-cocktails-%E2%80%93-shaken-not-stirred/
The Cocktails way
Mojito Application

Mojit
                        Assets
  Model                 Client JS   Images
           Controller

  View                    CSS         ...
Conclusion
 Node.js can serve hundreds of concurrent
  requests quickly and reliable, better than
  Apache/PHP
 It scales extremely well for I/O bound use
  cases
 It tears down the client-server language
  barrier, opening new architectural
  possibilities
Thank you!




Picture: "Esther M端ller" / www.jugendfotos.de, CC-License(by-nc)

More Related Content

Node.js Performance Case Study

  • 1. Performance Case Study @Fabian_Frank <fabian@pagefault.de> Yahoo! Search, Engineer Youthmedia.eu,Volunteer
  • 6. node v0.4.X multi-core http://developer.yahoo.com/blogs/ydn/posts/2010/07/multicore_http_server_with_nodejs/
  • 7. Time Sharing Workers Event Queue
  • 8. Event Queue does only one thing at a time events that occur are queued for processing after an event was processed the next one is fetched from the queue
  • 9. The difference Workers Event Queue 1. synchronous call 1. asynchronous call that speci鍖es event(s) that can 2. worker blocked occur (callback) 3. periodically check if 2. process next event worker can go ahead 3. speci鍖ed event occurs and 4. call returns is put on the queue 5. worker goes ahead on 4. process goes ahead next check
  • 10. Another difference Workers Event Queue 1 connection per N connections per worker process N workers per CPU 1 process (per CPU)
  • 11. Regarding... static 鍖le serving benchmarks are not relevant, unless you plan to do heavy duty static 鍖le serving (Im not) hello world benchmarks still ignore most of what matters, e.g. accessing a database or other back-ends
  • 12. Realistic Real World Benchmark a lot of variables that have to be controlled more complex, likely to surface weird bugs face unanswerable questions are expensive to do are easy to attack, but hard to defend
  • 13. My Reasoning I can not compare everything out there against everything else. But I can compare what I want to use in the future against what I am using today.
  • 14. Search Case Study Right Panel retrieved using AJAX { html: <div>...</div>, css: ..., js: ..., ... }
  • 15. Refresh Right Panel 1. receive a request JSON API 2. call a JSON API over HTTP 2. 3. manipulate the data structure Node.js 3. 4. 4. render it as HTML using Mustache 1. 5. 5. write back wrapped in JSON Client
  • 16. Refresh Right Panel 1. receive a request JSON API 2. call a JSON API over HTTP 2. 3. manipulate the data structure xy 3. ro 4. Node.js P 4. render it as HTML using Mustache 1. 5. 5. write back wrapped in JSON Client
  • 17. Constraints Network bandwidth and latency Gigabit and 1ms JSON API performance load-balanced cluster with cache
  • 18. Implementations Apache + PHP Node.js (+ YUI) Manhattan + Mojito
  • 19. Apache + PHP works, in production for decades initial response times are good enough scales, but you need $$$ baseline to get a feeling for the numbers
  • 20. Apache + PHP 430req/s @ 60ms average latency 99% @ 114ms
  • 21. Node.js (+ YUI) works, but very new and untested stack initial response times are very low scales extremely well YUI works well, but still has pitfalls
  • 22. Node.js Fun Facts >3100 requests per second 100k requests in 32s 9MByte/s network traf鍖c serve >2k req/s at 20ms average latency 99% @ 47ms
  • 25. Node.js Histogram ~1500req/s | 25 conc. 12000 99% @ 35ms 10000 8000 frequency 6000 4000 2000 0 11.000 - 17.300 - 23.600 - 29.900 - 36.200 - 42.500 - 48.800 - 55.100 - 61.400 - 67.700 - 74.000 - 17.300 23.600 29.900 36.200 42.500 48.800 55.100 61.400 67.700 74.000 80.300
  • 26. Node.js Histogram ~2900/s | 100 conc. 9000 8000 99% @ 79ms 7000 6000 frequency 5000 4000 3000 2000 1000 0 12.000 - 22.000 - 32.000 - 42.000 - 52.000 - 62.000 - 72.000 - 82.000 - 92.000 - 102.000 - 112.000 - 22.000 32.000 42.000 52.000 62.000 72.000 82.000 92.000 102.000 112.000 122.000
  • 27. Node.js Histogram ~3100/s | 200 conc. 8000 7000 99% @ 152ms 6000 5000 frequency 4000 3000 2000 1000 0 14.000 - 33.900 - 53.800 - 73.700 - 93.600 - 113.500 - 133.400 - 153.300 - 173.200 - 193.100 - 213.000 - 33.900 53.800 73.700 93.600 113.500 133.400 153.300 173.200 193.100 213.000 232.900
  • 28. Manhattan + Mojito works, but extremely new and untested stack initial response times are low (60% compared to Apache/PHP) scales well (twice as good as Apache/PHP)
  • 31. Findings Both node.js implementations scale linearly before CPU usage hits 100% Node.js scales extremely well as proxy Manhattan and Mojito can perform better than Apache and PHP (for this use case) Node.js applications are very sensitive to memory leaks or complex/blocking code
  • 32. DNS in Node.js getaddrinfo() sys call is synchronous gethostbyname() is, too ares_gethostbyname() is asynchronous no cache node 0.6 uses a getaddrinfo() thread pool, but still relies on ares for other calls
  • 34. Manhattan? Yahoo!s Node.js cloud can run any node.js application allows calls to HTTP APIs (e.g.YQL) deployment of versioned apps apps can specify their environment http://developer.yahoo.com/blogs/ydn/posts/2011/11/yahoo-announces-cocktails-%E2%80%93-shaken-not-stirred/
  • 35. Mojito? Yahoo!s Node.js MVC framework provides identical similar runtime for your code on the client and server contains all server- and client-side code built on top of YUI will be open sourced http://developer.yahoo.com/blogs/ydn/posts/2011/11/yahoo-announces-cocktails-%E2%80%93-shaken-not-stirred/
  • 36. The Cocktails way Mojito Application Mojit Assets Model Client JS Images Controller View CSS ...
  • 37. Conclusion Node.js can serve hundreds of concurrent requests quickly and reliable, better than Apache/PHP It scales extremely well for I/O bound use cases It tears down the client-server language barrier, opening new architectural possibilities
  • 38. Thank you! Picture: "Esther M端ller" / www.jugendfotos.de, CC-License(by-nc)

Editor's Notes