Home >Technology >Run Node Run

Run Node Run

Date post:13-Jan-2015
Category:
View:780 times
Download:7 times
Share this document with a friend
Description:
A brief overview of profiling Node.js and writing code for the V8 runtime.
Transcript:

2. Agenda Benchmarking V8 JavaScript Tips and Tricks Inside Crankshaft Profiling Node 3. From 365 to 5,000 requests per second. 4. This shit works. Swears it. 5. Note: This is complex, but youll sleepbetter at night. 6. If you can sleep at all. 7. This is about speed. 8. Speed is addictive. 9. Benchmarking 10. HTTP 11. $ ab -n1000 c100 k http://127.0.0.1/ 12. $ siege r100 c100 -b http://127.0.0.1/ 13. JMeter 14. ab outputConcurrency Level:100Time taken for tests: 8.680 secondsRequests per second:11521.27 [#/sec] (mean)Time per request: 8.680 [ms] (mean)Time per request: 0.087 [ms] (mean,across all concurrent requests) 15. Non-HTTP 16. var maxRuns = 1000;var start = Date.now();for (var i = 0; i < maxRuns; i++) {// do stuff...}var end = Date.now();var elapsed = end start;var timePerRun = elapsed / maxRuns;console.log(elapsed + ms);console.log(timePerRun + ms/run 17. Faster! 18. Hidden Classesfunction Point(x, y) {this.x = x;this.y = y;}var p1 = new Point(1, 2);var p2 = new Point(3, 4); 19. Hidden Classesfunction Point(x, y) {this.x = x;this.y = y;}var p1 = new Point(1, 2);var p2 = new Point(3, 4);p2.z = 9; // ohnoes!! 20. Dictionary Modefunction takeOrder(row) {var order = { food: row.get(food), quantity: row.get(qty);};process(order);} 21. Dictionary Modefunction takeOrder(row) {var order = { food: row.get(food), quantity: row.get(qty);};process(order);}// ohnoes!!!for(var i = 0; i < db.length; i++) {takeOrder(db[i]);} 22. Try-Catchtry {// hot code} catch(e) {console.log(e);} 23. Try-Catchtry {process();} catch(e) {console.log(e);}function process() {// hot code} 24. Hot Code Dont monkey-patch. Dont mix types for the same property. Avoid dictionary mode. Set all properties in the constructor. Move high-performance code out of try-catch. If array.length < 65000, specify the size. 25. V8s Crankshaft is Awesome 26. Base Compiler 27. Runtime Profiler 28. Optimizing Compiler 29. Deoptimization Support 30. JavaScript ->Hydrogen ->Lithium ->(Native) 31. Profiling Node 32. $ node --prof server.js 33. Note: Your benchmark will be slower. 34. $ lsserver.jsv8.log$ export D8_PATH=~/node/src/deps/v8$ ~/nvm/src/node-v0.8.18/deps/v8/tools/mac-tick-processor > profile.log 35. [JavaScript]: ticks total nonlibname2510.5%0.5% LazyCompile:*Socket.write net.js:465[C++]: ticks total nonlib name4862594.4%94.4% ___psynch_rw_unlock[GC]: ticks total nonlib name263 0.5% 36. c4milo/node-webkit-agent 37. $ cat server.jsvar agent = require(webkit-devtools-agent);// create serverconsole.log(process.pid)$ node server.js22341$ kill SIGUSR2 22341$ open http://c4milo.github.com/node-webkit-agent/21.0.1180.57/inspector.html?host=localhost:1337&page=0 38. More Profiling Options 39. --trace_opt Shows code optimizations. Good for spotting hot code. 40. --trace_deopt Shows code de-optimizations. Good for spotting type information changes inhot code. 41. If you aint first, youre last! 42. The plumbing should work like greasedlightning. 43. You cant control everything. 44. Fail with grace. 45. Benchmark regularly. 46. Additional Resources Understanding V8 Breaking the JavaScript Speed Limit V8 Internals Profiling Node Programs on Mac OS X Node Webkit Agent 47. [email protected]@gmail.com

Popular Tags:
of 47/47
Run Node Run Fine-tuning JavaScript for the V8 Runtime @kevinswiber [email protected]
Embed Size (px)
Recommended