performance case study -...
TRANSCRIPT
![Page 1: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/1.jpg)
Performance Case Study
@Fabian_Frank<[email protected]>
Yahoo! Search, EngineerYouthmedia.eu, Volunteer
![Page 2: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/2.jpg)
A Dynamic Website
![Page 3: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/3.jpg)
self-contained App
![Page 4: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/4.jpg)
self-contained App
![Page 5: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/5.jpg)
self-contained App
![Page 6: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/6.jpg)
node v0.4.Xmulti-core
http://developer.yahoo.com/blogs/ydn/posts/2010/07/multicore_http_server_with_nodejs/
![Page 7: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/7.jpg)
Time Sharing
• Workers
• Event Queue
![Page 8: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/8.jpg)
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
![Page 9: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/9.jpg)
The difference
Workers
1. synchronous call
2. worker blocked
3. periodically check if worker can go ahead
4. call returns
5. worker goes ahead on next check
Event Queue
1. asynchronous call that specifies event(s) that can occur (callback)
2. process next event
3. specified event occurs and is put on the queue
4. process goes ahead
![Page 10: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/10.jpg)
Another difference
Workers
• 1 connection per worker
• N workers per CPU
Event Queue
• N connections per process
• 1 process (per CPU)
![Page 11: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/11.jpg)
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
![Page 12: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/12.jpg)
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
![Page 13: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/13.jpg)
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.”
![Page 14: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/14.jpg)
Search Case Study
• Right Panel retrieved using AJAX
• { ‘html’: ‘<div>...</div>’, ‘css’: ‘...’, ‘js:’ ‘...’, ... }
![Page 15: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/15.jpg)
Refresh Right Panel
1. receive a request
2. call a JSON API over HTTP
3. manipulate the data structure
4. render it as HTML using Mustache
5. write back wrapped in JSON Client
Node.js
JSON API
Proxy2.
1.
3.4.
5.
![Page 16: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/16.jpg)
Constraints
• Network bandwidth and latency
• Gigabit and 1ms
• JSON API performance
• load-balanced cluster with cache
![Page 17: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/17.jpg)
Implementations
• Apache + PHP
• Node.js (+ YUI)
• Manhattan + Mojito
![Page 18: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/18.jpg)
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
![Page 19: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/19.jpg)
Apache + PHP
• 430req/s @ 60ms average latency
• 99% @ 114ms
![Page 20: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/20.jpg)
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
![Page 21: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/21.jpg)
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
![Page 22: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/22.jpg)
Node.js
![Page 23: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/23.jpg)
Node.js
![Page 24: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/24.jpg)
Node.js Histogram~1500req/s | 25 conc.
0
2000
4000
6000
8000
10000
12000
11.000 - 17.300
17.300 - 23.600
23.600 - 29.900
29.900 - 36.200
36.200 - 42.500
42.500 - 48.800
48.800 - 55.100
55.100 - 61.400
61.400 - 67.700
67.700 - 74.000
74.000 - 80.300
freq
uenc
y
99% @ 35ms
![Page 25: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/25.jpg)
Node.js Histogram~2900/s | 100 conc.
0
1000
2000
3000
4000
5000
6000
7000
8000
9000
12.000 - 22.000
22.000 - 32.000
32.000 - 42.000
42.000 - 52.000
52.000 - 62.000
62.000 - 72.000
72.000 - 82.000
82.000 - 92.000
92.000 - 102.000
102.000 - 112.000
112.000 - 122.000
freq
uenc
y
99% @ 79ms
![Page 26: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/26.jpg)
Node.js Histogram~3100/s | 200 conc.
0
1000
2000
3000
4000
5000
6000
7000
8000
14.000 - 33.900
33.900 - 53.800
53.800 - 73.700
73.700 - 93.600
93.600 - 113.500
113.500 - 133.400
133.400 - 153.300
153.300 - 173.200
173.200 - 193.100
193.100 - 213.000
213.000 - 232.900
freq
uenc
y
99% @ 152ms
![Page 27: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/27.jpg)
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)
![Page 28: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/28.jpg)
Manhattan + Mojito
![Page 29: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/29.jpg)
Manhattan + Mojito
![Page 30: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/30.jpg)
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
![Page 31: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/31.jpg)
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
![Page 32: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/32.jpg)
Cocktails
• Manhattan
• Mojito
![Page 33: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/33.jpg)
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/
![Page 34: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/34.jpg)
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/
![Page 35: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/35.jpg)
The Cocktails wayMojito Application
Model
View
Controller
Mojit
Client JS
CSS
Assets
Images
...
![Page 36: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/36.jpg)
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
![Page 37: Performance Case Study - velocity.oreilly.com.cnvelocity.oreilly.com.cn/2011/ppts/fabian_frank_nodejs_velocity.pdf · • Both node.js implementations scale linearly before CPU usage](https://reader033.vdocument.in/reader033/viewer/2022050516/5fa0843a8d2a34296d0d0c45/html5/thumbnails/37.jpg)
Thank you!
Picture: "Esther Müller" / www.jugendfotos.de, CC-License(by-nc)