Node.js Performance Case Study

19,219 views

Published on

This talk was recorded:
http://v.youku.com/v_show/id_XMzQ5ODQ2Mjky.html

Published in: Technology
0 Comments
22 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
19,219
On SlideShare
0
From Embeds
0
Number of Embeds
141
Actions
Shares
0
Downloads
155
Comments
0
Likes
22
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • JSON\n
  • \n
  • JSON\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Node.js Performance Case Study

    1. 1. Performance Case Study @Fabian_Frank <fabian@pagefault.de> Yahoo! Search, Engineer Youthmedia.eu,Volunteer
    2. 2. A Dynamic Website
    3. 3. self-contained App
    4. 4. self-contained App
    5. 5. self-contained App
    6. 6. node v0.4.X multi-corehttp://developer.yahoo.com/blogs/ydn/posts/2010/07/multicore_http_server_with_nodejs/
    7. 7. Time Sharing• Workers• Event Queue
    8. 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. 9. The difference Workers Event Queue1. synchronous call 1. asynchronous call that specifies event(s) that can2. worker blocked occur (callback)3. periodically check if 2. process next event worker can go ahead 3. specified event occurs and4. call returns is put on the queue5. worker goes ahead on 4. process goes ahead next check
    10. 10. Another difference Workers Event Queue• 1 connection per • N connections per worker process• N workers per CPU • 1 process (per CPU)
    11. 11. Regarding...• static file serving benchmarks • are not relevant, unless you plan to do heavy duty static file serving (I’m not)• hello world benchmarks • still ignore most of what matters, e.g. accessing a database or other back-ends
    12. 12. RealisticReal 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. 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. 14. Search Case Study• Right Panel retrieved using AJAX• { ‘html’: ‘<div>...</div>’, ‘css’: ‘...’, ‘js:’ ‘...’, ... }
    15. 15. Refresh Right Panel1. receive a request JSON API2. 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. 16. Refresh Right Panel1. receive a request JSON API2. call a JSON API over HTTP 2.3. manipulate the data structure xy 3. ro 4. Node.js P4. render it as HTML using Mustache 1. 5.5. write back wrapped in JSON Client
    17. 17. Constraints• Network bandwidth and latency • Gigabit and 1ms• JSON API performance • load-balanced cluster with cache
    18. 18. Implementations• Apache + PHP• Node.js (+ YUI)• Manhattan + Mojito
    19. 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. 20. Apache + PHP• 430req/s @ 60ms average latency • 99% @ 114ms
    21. 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. 22. Node.js Fun Facts• >3100 requests per second • 100k requests in 32s • 9MByte/s network traffic• serve >2k req/s at 20ms average latency • 99% @ 47ms
    23. 23. Node.js
    24. 24. Node.js
    25. 25. Node.js Histogram~1500req/s | 25 conc. 12000 99% @ 35ms 10000 8000frequency 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. 26. Node.js Histogram ~2900/s | 100 conc. 9000 8000 99% @ 79ms 7000 6000frequency 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. 27. Node.js Histogram ~3100/s | 200 conc. 8000 7000 99% @ 152ms 6000 5000frequency 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. 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)
    29. 29. Manhattan + Mojito
    30. 30. Manhattan + Mojito
    31. 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. 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
    33. 33. Cocktails• Manhattan• Mojito
    34. 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 environmenthttp://developer.yahoo.com/blogs/ydn/posts/2011/11/yahoo-announces-cocktails-%E2%80%93-shaken-not-stirred/
    35. 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 sourcedhttp://developer.yahoo.com/blogs/ydn/posts/2011/11/yahoo-announces-cocktails-%E2%80%93-shaken-not-stirred/
    36. 36. The Cocktails wayMojito ApplicationMojit Assets Model Client JS Images Controller View CSS ...
    37. 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. 38. Thank you!Picture: "Esther Müller" / www.jugendfotos.de, CC-License(by-nc)

    ×