• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Node.js and ruby

on

  • 6,592 views

The idea is to give an introduction to evented development using node.js and then focus on how to accomplish this using ruby....

The idea is to give an introduction to evented development using node.js and then focus on how to accomplish this using ruby.

The outline would look like this

Contrast and Compare evented development against thread based development
Introduce node.js and why it’s causing a stir
Introduce eventmachine
Talk about a practical stack to deploy a rails app and how the parts hook together
Round out the presentation with Pro’s and Con’s

Statistics

Views

Total Views
6,592
Views on SlideShare
6,484
Embed Views
108

Actions

Likes
10
Downloads
65
Comments
0

4 Embeds 108

http://francescoagati.wordpress.com 87
http://us-w1.rockmelt.com 17
https://si0.twimg.com 3
https://twimg0-a.akamaihd.net 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

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
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Node.js and ruby Node.js and ruby Presentation Transcript

  • Node.js and Ruby
  • Who am I Team lead for Xing Spain Interested in the hard stuff github:http://www.github.com/christkv twitter:christkv blog: http://www.christiankvalheim.com
  • What’s for dinner Threads and Events Some Code and Results State of Ruby/NodeJS Pros/Cons Questions and probably Answers
  • Primer L1 Cache L2 Cache RAM DISK NETWORK Processors are Fast 250,000 Cache is fast 187,500 Thousands Memory is slower 125,000 240000000 Disk is just WRONG 62,500 41000000 0 3 14 250 Cycles
  • Primer Most web applications are IO bound DB Access Cache access File access
  • Thread driven server 1 3 2 1 1 needs some db 2 4 3 2 Return 1 Process 2 1
  • Thread driven server Multiple threads to process requests Synchronous, Wait for I/O Locks, semaphore and stuff Simpler code, synchronous
  • Event driven server 1 3 2 1 1 needs some db 2 Pause 1 4 3 2 and do 2 1 3 5 4 3 Return 1 1 Pause 2 2
  • Event driven server Single thread (1:n processes for scale) Don’t wait on I/O keep executing Callback when I/O is ready CPU Bound
  • Google V8 Javacript Engine LibEIO/LibEV for event loop All I/O is async if written in pure JS Growing in popularity Simplifies async development
  • State of Stable core platform libraries v0.3 coming out soon Starting to be used in production environments Maturing libraries
  • example var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(8124, "127.0.0.1");
  • Ruby/Eventmachine File Processes descriptors Reactor = Your code
  • Async Sinatra Using ruby 1.9.X and Fibers No magic so you’ll have to handle everything yourself Good way to learn about async and experiment with performance and code
  • asinatra require 'sinatra/async' require 'em-mysqlplus' class AsyncTest < Sinatra::Base register Sinatra::Async aget '/widgets' do conn = EventMachine::MySQL.new(:host => 'localhost', :database => 'widgets') query = conn.query("select * from test") query.callback do |res| body { res.to_s } end end end run AsyncTest.new
  • Async Rails Using ruby 1.9.X and Fibers Fibers are “lightweight threads” minus context switching and scheduler All magic hidden from view with async stack by Ilya Grigorik
  • Async Rails Stack Ruby 1.9.2 Thin/Event Async Rails is a Machine set of gems Rack Fiber Pool Rails 3.0 Fiber pools for em-activerecord db and rack em-mysqlplus Adjust pool em-synchrony settings for em-http-request scaling
  • Core problems Async Rails lulls you into a sense of security. Sold as a “simple” way of making rails async but!! Only covers db, http calls and rails itself A lot of abstractions and layers of code
  • Some Numbers
  • Some results http://github.com/christkv/conferenciarails.org-2010-presentation A-Sinatra Async Rails Pass Rails NodeJS. JS Db Pool of 60 NodeJS. Na 300.0 Simple db sleep 225.0 query of 0.2 150.0 A look at 75.0 concurrency 0 Requests/Second
  • Thread starvation Some results Immature mysql drivers for nodeJS ? http://github.com/christkv/conferenciarails.org-2010-presentation decently Ruby doing GC might be problem A-Sinatra Async Rails A-Sinatra Async Rails Pass Rails NodeJS. JS Pass Rails NodeJS. JS NodeJS. Na NodeJS. Na 8,000.0 100.0% 6,000.0 75.0% 4,000.0 50.0% 2,000.0 25.0% 0 0% Time pr request Error Rate
  • Motivation
  • NodeJS + MongoDB Peaks at 50 000 req/m 1 server Live sales monitoring for Gilt Group Open source at http://projects.nuttnet.net/hummingbird/
  • HTML5 Concurrency will happen even to small apps. Lot’s of open connections Webapps will be “thicker” Servers will be hammered
  • Be Greener Use less hardware to power your site Better usage of hardware resources
  • Pros & Cons
  • Evented Pros CPU bound application Lower memory usage Control resource usage (run 2 processes on a quad-core) Allows for lots of open socket connections
  • Evented Cons Harder application design No “long running blocking code” in your event loop or you die Need to plan “code” interactions for long running processes Mentality change and lots of callbacks
  • Let’s Summarize opinion included
  • Concurrency is increasing with such things as HTML5 Websockets even for small apps
  • Evented programming gives you a possibility of scaling
  • Learn the limits of evented before applying it to all
  • is ready but you need to up your skillset
  • is ready and easy to use
  • Don’t apply it everywhere split your app and pick a spot. REST API maybe
  • Mess around with code on http://github.com/christkv/ conferenciarails.org-2010- presentation
  • We are Hirin g Interested Talk to me
  • Q &A