the crazy cool things you can do with node js
play

The Crazy-Cool Things you can do with Node.js Nuno Job, Nodejitsu - PowerPoint PPT Presentation

The Crazy-Cool Things you can do with Node.js Nuno Job, Nodejitsu @dscape 2+2 17x24 Fast calculations Slow IO Should we scale them the same way? Apache flickr.com/photos/s4xton Event loop flickr.com/photos/liberato Sample Program


  1. The Crazy-Cool Things you can do with Node.js Nuno Job, Nodejitsu @dscape

  2. 2+2

  3. 17x24

  4. Fast calculations Slow IO Should we scale them the same way?

  5. Apache

  6. flickr.com/photos/s4xton

  7. Event loop

  8. flickr.com/photos/liberato

  9. Sample Program • parse auth params, � asynchronously authenticate , � when you get a response execute this callback function • auth callback executed, � asynchronously query the db, � when you get a response execute this callback function • db callback executed, � prepare html to render with info from db, � send to user

  10. Synchronous vs. Asynchronous try { auth.authenticate(creds, var auth = auth.authenticate(creds) function auth_cb(error, auth) { // wait for io if(error) { var user = sql.execute( return response.send(“auth”) “select * from users where id=”+ } auth.id) sql.execute( // wait for io “select * from users where id=”+ response.send(render.user(user)) auth.id, } catch (e) { function (error, user) { response.send(“failed”) if(error) { } response.send(“query”) } response.send(null, user) }) })

  11. Does it matter?

  12. Concurrency http://blog.webfaction.com/a-little-holiday-present

  13. Memory Usage http://blog.webfaction.com/a-little-holiday-present

  14. Yes

  15. libuv �

  16. Node Core • Programmable interface to network protocols and some helpers • TCP • UDP • HTTP • DNS

  17. A non-black box approach var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, '127.0.0.1'); console.log('Server running');

  18. Node Standard Idioms var foo = fs.readFile('foo.txt', 'utf8', fs.createReadStream('fot.txt'); function (err, data) { if (err) { foo.on('data', function (chunk) { return console.log(err.message); process.stdout.write(chunk); } }); console.log(data); }); foo.on('error', function (err) { console.log(err.message); });

  19. Streams are to time as arrays are to space @JedSchmidt

  20. A simple reverse proxy var http = require('http'); var request = require('request'); http.createServer(function (req, res) { console.log(req.url); req.pipe(request('http://nodestack.org' + req.url)).pipe(res); }).listen(1337);

  21. Pros and cons • Architecture for scaling io based applications, e.g. networking • Plays very well with V8 • “Fire and Forget” forces developers to save meaningful state as stack trace is lost • Developers must learn a new event driven programming paradigm

  22. Evolution

  23. Growth 18000 16000 14000 12000 10000 Projects 8000 Authors 6000 4000 2000 0

  24. How big is big? RubyForge Python � Nodejs (npm) Ruby � Gems �

  25. npm secrets • Super easy to publish • State of the art package management software • Adoption of standard idioms makes module creators and users know what interfaces to expect

  26. flickr.com/photos/31246066@N04

  27. Growth

  28. CQS � DNS � State � foo.iriscouch.com Workhorse 1 � Database A � A Client � Proxy A � Database B � Workhorse 2 � B Proxy B � Workhorse 3 � Database C � C

  29. Black boxes var named = require('named'); named.createServer(function(req, res) { res.end('1.2.3.4'); }).listen(5353, '127.0.0.1'); console.log('Server running')

  30. CQS � DNS � State � foo.iriscouch.com Workhorse 1 � Database A � A Client � Proxy A � Database B � Workhorse 2 � B Proxy B � Workhorse 3 � Database C � C

  31. In other words, I am now in control of a flying web server. @FelixGe

  32. Summary • Extremely efficient networking applications • Fast javascript runtime (V8) • Rapid growth in both packages and community • No black boxes • Robots

  33. Thank you @dscape

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend