Elapsed

00m

Node at uber

@Raynos (jakev)

What is node

  • v8 (javascript engine)
  • libuv (IO event loop in c)
  • A small networking stdlib
  • npm (node package manager)

Why use node

Why use node


var http = require('http');

http.createServer(function handleReq(req, res) {
    res.end('hello world');
}).listen(8080);
      

Why use node


var TChannel = require('tchannel');

TChannel()
    .register('hello', function handleReq(res, res) {
        res.sendOk(null, 'hello world');
    })
    .listen(8080, '127.0.0.1')
      

Why use node

  • Great for networking glue
  • Great for distributed stateful programs
  • Pretty damn fast
  • First class support for monitoring+debugging

Node at uber

  • git clone <project>
  • npm install
  • npm test
  • vim .


Works on EC2 and locally

Node services at uber

  • Use `uber-standard` for linting
  • Use `npm run shrinkwrap` to update deps
  • Use `node server.js` to start services
  • Use `node test/index.js` to run tests

Node services at uber


Use `zero-config` to load config files


var ZeroConfig = require('zero-config');

var config = ZeroConfig(__dirname, {
    dc: '/etc/uber/datacenter'
});

config.get('clients.ringpop.bootstrapFile')
config.get('port')
      

Node services at uber


Use `uber-statsd-client` for monitoring


var Statsd = require('uber-statsd-client');

var statsd = Statsd({ host: 'localhost', port: 5555 });

statsd.increment('my-app.database-connection-died');
statsd.increment('my-app.no-drivers-available');
      

Node services at uber


Use `*-logtron` for logging


var Logtron = require('logtron');

var logger = Logtron({ meta: {
    team: 'my-team',
    project: 'my-app'
} });

logger.error('unexpected failure in fetching city', {
    err: err,
    cityId: cityId,
    cityName: cityName
});

logger.warn('Got a bad response for city request', {
    response: buffer.toString().slice(0, 50),
    cityId: cityId,
    cityName: cityName
});
      

Cool shit you can do in node

Ringpop


  • Consistent hash ring for a cluster
  • Trivial leader election
  • In memory queues
  • In memory locks

TChannel


  • Supports structure RPC with thrift
  • Can do bidirectional p2p communication
  • Supports multiplexing streaming

node-stap and mdb


  • Deep system level debugging
  • Insight into actual production performance
  • See exactly what went wrong in production

Questions and answers



Bring it

Workshop time



local: `sudo npm i -g learnyounode`

ec2: `sudo npm0.10 i -g learnyounode`

run `learnyounode`