Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
Performance Case Study
@Fabian_Frank<[email protected]>
Yahoo! Search, EngineerYouthmedia.eu, Volunteer
A Dynamic Website
self-contained App
self-contained App
self-contained App
node v0.4.Xmulti-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
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
Another difference
Workers
• 1 connection per worker
• N workers per CPU
Event Queue
• N connections per process
• 1 process (per CPU)
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
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
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
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.
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 traffic
• serve >2k req/s at 20ms average latency
• 99% @ 47ms
Node.js
Node.js
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
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
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
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 wayMojito Application
Model
View
Controller
Mojit
Client JS
CSS
Assets
Images
...
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)