1. Rails + Node.js
Michał Łomnicki
http://mlomnicki.com
http://starware.com.pl
2. Node.js
server-side JS
asynchronous processing
events, reactor pattern, eventmachine
http, tcp, dns are first class protocols
built on top of Google's V8 JavaScript engine
uses epoll, kqueue, /dev/poll or select
3. Show me some code
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");
console.log('Server running at http://127.0.0.1:8124/');
4. Why JavaScript?
first class events support
people know it already!
easy to start
don't have to learn new language
5. Why to Node?
handle lots of concurrent requests
speed
...but concurency is more important IMO
streaming data
authentication layer between client and storage
WebSockets
Chunked requests/responses
small memory footprint
6. Why NOT to Node?
it's not a web framework
... so it's not a rails replacement
use Node to handle sepcialized, performance criticial tasks
eventmachine, async_sinatra, erlang, etc are good too!
... but Node.js libraries are proven to be asynchronus
we are used to think in synchronous way
Fibers, Goliath server
7. My use-case - tracer
trace user's behaviour
clicked links
inputs
"hot" areas
sth like GoogleAnalytics but very customized
8. My use-case - tracer
a lot of requests
simple logic - get data, write it do DB, return
want to plug it into more apps