SC5 Meetup: Node.js night with Jaakko Manninen
Upcoming SlideShare
Loading in...5
×
 

SC5 Meetup: Node.js night with Jaakko Manninen

on

  • 2,624 views

Jaakko Manninen's presentation on Node.js Lesson Learned at SC5 Meetup

Jaakko Manninen's presentation on Node.js Lesson Learned at SC5 Meetup

Statistics

Views

Total Views
2,624
Slideshare-icon Views on SlideShare
2,618
Embed Views
6

Actions

Likes
0
Downloads
1
Comments
0

1 Embed 6

https://twitter.com 6

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    SC5 Meetup: Node.js night with Jaakko Manninen SC5 Meetup: Node.js night with Jaakko Manninen Presentation Transcript

    • Node.js at Rocket PackLessons learned; Patterns to know and loveJaakko ManninenRocket Pack / Disney InteractiveWednesday, May 15, 13
    • Rocket Pack• Makes awesome HTML5 games and the tools tobuild them• Engine,Tool chain, Services 100% JS• Acquired by Disney in 2011• Started using Node.js in 2010, version 0.1• Full stack, cloud hosted setup• Very early days for HTML5 games: first toolchainWednesday, May 15, 13
    • What is Node.js• JavaScript engine with IO library & APIs• Google’sV8 + libuv + core APIs• V8 is Chrome’s very fast JS engine• One thread of execution• Asynch, non-blocking, event driven IO• Great for servers, real-time messaging, butalso for web and standalone appsWednesday, May 15, 13
    • Road to Node• First as HTTP front end for Scala backend• Parse request, deliver to AMQP message broker• Games ran engine code in Rhino/JVM• Ran it in Node and soon ported everythingto Node• V8 is very fast :)• Most packages we have used, we have had to patch :(• Today package quality improving but still poor :/Wednesday, May 15, 13
    • Rocket Pack version 1• Cloud: Scalable, stateless, modular• Top to bottom JavaScript, all the way fromMongoDB to the client side runtime engine• Messaging to tie the elements together• First RabbitMQ & node-amqp• Then wrote our own Messaging APIWednesday, May 15, 13
    • Messaging• Wrote load-balancing, p2p messaging APIusing github.com/einaros/ws• Careful about fanout style exchanges, where processing capability islimited to one core only• Central discovery: if you have a multicast group, think about node-mdns• Socket.IO messages quickly routed toservices by FE• Sticky lb; no Store yet; no engine.io yet• Use engine.io with eg. a Redis StoreWednesday, May 15, 13
    • Processing woes• An evolving platform needs to run data migrations• Memory limited to 1.2GB (fixed only in 2012)• Use cluster to task workers on other cores• Or discover nodes in cluster (mdns, roll-your-own)Wednesday, May 15, 13
    • Lessons part 1• One-thread-only is your friend in scaling• Many packages are buggy and you will haveto patch them (but submit a pull request!)• Use domain to capture out-of-stack errors• Where did that socket hang up come from? domain will tell you• Domain itself is experimental• Never throw - just return errors• Never use uncaughtExceptionWednesday, May 15, 13
    • Part 2 - Local Tools• Brought dev tools to the dev’s machine• Windows support; offline support• Plugins: declare and depend on namedinterfaces• Excellent testability, modularity, composability• CommonJS, npm, package.json everywhereWednesday, May 15, 13
    • • npm is an awesome package manager• Large dependency trees may cause rare issues• It doesn’t have to be JavaScript• Tens of thousands of packages• Private repository recommended• Our repo mirrors npm; has our private packages• Not trivial to set up, but worth itWednesday, May 15, 13
    • Wednesday, May 15, 13
    • browserify• github.com/substack/node-browserifywraps your CommonJS modules in abundle loadable in the browser• connect + browserify = JIT compilation• Manage your site/app’s dependencies vianpm• Most Node APIs available• Even our UI is a browserified npm pluginWednesday, May 15, 13
    • when.js• github.com/cujojs/when is a lightweight CommonJSPromises/A+ library with other async goodies(iterators etc)• We now use Promises everywhere• used to use github.com/caolan/async• Bubbling up errors: handle errors in one place• Also wraps Node functions in Promises• nodefn.call(fs.readFile,‘/etc/passwd’).then()Wednesday, May 15, 13
    • return longTask().then(function(result) {// do stuff with result}).otherwise(function(error) {})longTask(function(err, result) {if (err) return err;// do stuff with result})Without Promises:Bubble up Promises:Wednesday, May 15, 13
    • vfs• github.com/c9/vfs is aVirtual File Systemabstraction that works over WS (with msgpack),HTTP and locally in Node• brings the same FS API to the whole stack; lets usaccess the fs the same way everywhere; browserto server• uses github.com/c9/smith, an RPC agent systemthat gives us streams and processes in the browser• output logs from long-running processes• EMFILE: file watching by interval not by fd; github.com/isaacs/graceful-fsWednesday, May 15, 13
    • Lessons part 2• Always use jshint in your editor• Forget callbacks, use and return Promises• Use browserify and npm to assemble yoursoftware• Design around one thread per process andpartition around ~3500m/s type of issues• Build with grunt; test with mocha andjsdom• jsdom is fully fledged DOM implementationWednesday, May 15, 13
    • Native applications• github.com/rogerwang/node-webkit letsyou build native apps with Node.js andWebKit• Linux, Mac,Windows all supported• Even WebGL is supported• TPOLM demo time! (wrapped in node-webkit)• http://tpolm.com/demos/inedible_candyWednesday, May 15, 13
    • Thanks!jaakko@rocketpack.fijaakko.manninen@gmail.comgithub.com/rocketpack@kschztWednesday, May 15, 13