Your SlideShare is downloading. ×
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Getting Started with MongoDB and Node.js

79,204

Published on

Slides from my talk at Mongo Seattle 2010.

Slides from my talk at Mongo Seattle 2010.

Published in: Technology
2 Comments
126 Likes
Statistics
Notes
No Downloads
Views
Total Views
79,204
On Slideshare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
1,545
Comments
2
Likes
126
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

  • How many people have used Node.js? In production?

    Start with V8: http://code.google.com/p/v8/
    Chrome’s javascript engine (Fast, aggressively developed)

    Add Evented I/O, system calls, HTTP libraries

    First created by Ryan Dahl @ Joyent

    “Scalable network applications”: tens of thousands of simultaneous connections on a single box
  • High concurrency apps are likely to encounter the C10k problem:
    http://www.kegel.com/c10k.html

    Overhead per connection: An order of magnitude smaller than most libraries’ thread stack allocations.

    Builds on the approaches used by libasync, twisted, evenmachine, etc.

    Use kernel level event notification (kqueue, epoll, etc.) to notify when files, network connections etc. are ready to be used. App can do other work rather than blocking.


  • Node shares more with Twisted than Rails

  • nginx is amazing at handling static content.

    Buffers are the suggested way for handling binary data, large data, etc.

    The Buffer API is detailed here: http://nodejs.org/api.html#buffers-2

  • Mongo’s shell is javascript, can execute javascript in process

    You can actually write your entire application in javascript - front end and back!
  • In fact, there are several blog engines already. Try Wheat.


  • Of course, building your UI on top of Node.js isn’t a bad idea if the rest of your app fits as well - no need to run a Rails app next to your Node app just for a GUI. (cf. Hummingbird).

  • The current js driver supports master and slave connections, atomic operations, map/reduce...



  • Chained execution of callbacks is how most every Node program will work.
  • Recent builds of Node support udp sockets.
    Mongo’s great at storing semi-structured data quickly
  • As much fun as quadruply-nested callbacks are.
  • As much fun as quadruply-nested callbacks are.
  • Hydrating documents loaded from the db converts them into instances of our models.

    Looks almost like Rails...


  • Transcript

    • 1. Getting Started With Node.js and mongoDB Grant Goodale (@ggoodale) 7/26/2010
    • 2. What is ? “Evented I/O for V8 Javascript” – http://nodejs.org Application engine for “scalable network applications” Really freaking fast: One process, zero* threads (Almost) no blocking * actually, there is a thread pool. We’ll get to that.
    • 3. What is ? High concurrency with low overhead No thread swapping or context switching Applications must be designed from the ground up to not block on I/O, CPU-intensive work, etc.
    • 4. What Node.js Isn’t A full-stack web framework (a la Ruby on Rails) But! you can get there: ExpressJS: (http://expressjs.com/) (Web framework with MongoDB support built in - similar to Sinatra) http://github.com/senchalabs/connect (Rack-like middleware for Node and Express) haml.js: http://github.com/visionmedia/haml.js (Pure js implementation of HAML)
    • 5. What Node.js Isn’t (cont.) Great at sending large static files concurrently. (use nginx.) Buffer implementation in recent versions improves this dramatically: http://nodejs.org/jsconf2010.pdf Completely non-blocking. CPU-intensive stuff will still block you (do it in a worker process). Some system calls (executed in a thread pool)
    • 6. & http://www.flickr.com/photos/tonyjcase/2803950283/
    • 7. & Great together! Both: speak Javascript understand JSON documents are freaking fast. So, what should you build?
    • 8. & You can build: Standard n-tier web applications Great way to learn mongoDB and Node Go build a blog engine! (Everyone does.) Lots of libraries to help you get started: ExpressJS, Connect, etc.
    • 9. & You should build: Applications requiring high throughput and concurrency Applications with real-time needs Applications with long-polling connections Real-time multiuser chat Web or log analytics (e.g. Hummingbird)
    • 10. Getting Started Grab the following: mongoDB: http://www.mongodb.org/downloads Node.js: http://nodejs.org/#download npm, a package manager for Node: curl http://npmjs.org/install.sh | sh
    • 11. Getting Started Use npm to install a mongoDB driver for Node: npm install mongodb Tons of other fun stuff as well - full package list at http://npm.mape.me/
    • 12. Evented I/O: a Primer Before:
    • 13. Evented I/O: a Primer After:
    • 14. Evented I/O: a Primer After:
    • 15. Evented I/O: a Primer After:
    • 16. A simple example: Syslog
    • 17. Mongoose http://www.learnboost.com/mongoose/ Cleans up a bit of the nested callback “fun”
    • 18. Mongoose http://www.learnboost.com/mongoose/ Cleans up a bit of the nested callback “fun”
    • 19. Mongoose Adds ORM capabilities (but doesn’t mandate them)
    • 20. Other Fun Stuff: http://wiki.github.com/ry/node/modules (Need extensions? We got 'em.) Routers, file servers, frameworks, crypto... http://socket.io/: Cross-platform WebSockets Supports HTML5 websockets Falls back to Flash / AJAX in less capable browsers
    • 21. Questions? twitter: ggoodale email: grant@moreblinktag.com

    ×