observable node.js applications - enterprisejs

72
Observable Node.js Applications at Scale Yunong Xiao, Senior Node.js Engineer, UI Platform, Netflix @yunongx, yunong@netflix.com July 2015 EnterpriseJS

Upload: yunong-xiao

Post on 15-Aug-2015

265 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Observable Node.js Applications - EnterpriseJS

Observable Node.js Applications at Scale

Yunong Xiao, Senior Node.js Engineer, UI Platform, Netflix

@yunongx, [email protected]

July 2015EnterpriseJS

Page 2: Observable Node.js Applications - EnterpriseJS

Node.js @ Netflix

Page 3: Observable Node.js Applications - EnterpriseJS
Page 4: Observable Node.js Applications - EnterpriseJS
Page 5: Observable Node.js Applications - EnterpriseJS
Page 6: Observable Node.js Applications - EnterpriseJS
Page 7: Observable Node.js Applications - EnterpriseJS
Page 8: Observable Node.js Applications - EnterpriseJS
Page 9: Observable Node.js Applications - EnterpriseJS

Production is War

Page 10: Observable Node.js Applications - EnterpriseJS

What’s Wrong?

Increased Errors Increased Latency

Memory Leak

Page 11: Observable Node.js Applications - EnterpriseJS

Software is Complex

Page 12: Observable Node.js Applications - EnterpriseJS

Drunk Man Anti-Method

Page 13: Observable Node.js Applications - EnterpriseJS
Page 14: Observable Node.js Applications - EnterpriseJS

DATA

“It is a capital mistake to theorize before one has DATA. Insensibly one begins to twist facts to suit theories, instead of theories to suit facts.”

Sherlock Holmes

-A Scandal in Bohemia

Page 15: Observable Node.js Applications - EnterpriseJS

Observability From the Ground Up

Page 16: Observable Node.js Applications - EnterpriseJS
Page 17: Observable Node.js Applications - EnterpriseJS

Hard Harder Insane

Development ProductionProduction w/

Direct Customer Impact

Page 18: Observable Node.js Applications - EnterpriseJS

Dev === Prod

Page 19: Observable Node.js Applications - EnterpriseJS
Page 20: Observable Node.js Applications - EnterpriseJS

node-bunyan

https://github.com/trentm/node-bunyan

Page 21: Observable Node.js Applications - EnterpriseJS

node-bunyan

Streaming JSON logging format

Page 22: Observable Node.js Applications - EnterpriseJS

Streaming JSON

Page 23: Observable Node.js Applications - EnterpriseJS

Unix Philosophy

grep(1), cut(1), wc(1), awk(1), perl(1), jq(1), json(1), daggr(1)

Page 24: Observable Node.js Applications - EnterpriseJS

Query Logs in Real Time

$ cat http.log | grep audit| bunyan -0 --strict -c 'this.res.statusCode === 200' | json -ga

‘req.timers["fetch-api"]' req.url | awk '{print $1 " " substr($2,0,7)}' | daggr -k 2 -v 1 quantize

Page 25: Observable Node.js Applications - EnterpriseJS

Illegible!

Page 26: Observable Node.js Applications - EnterpriseJS

bunyan(1) CLI

Page 27: Observable Node.js Applications - EnterpriseJS
Page 28: Observable Node.js Applications - EnterpriseJS

{ "name": "demo", "hostname": "Yunongs-MacBook-Pro.local", "pid": 35919, "level": 30, "authInfo": { "username": "yunong", "password": "xxxxxx" }, "msg": "got request", "time": "2015-07-07T21:46:01.317Z", "v": 0 }

Page 29: Observable Node.js Applications - EnterpriseJS
Page 30: Observable Node.js Applications - EnterpriseJS
Page 31: Observable Node.js Applications - EnterpriseJS

Features

• Lightweight API

• Log levels: trace, debug, info, warn, error, fatal

• Extensible Streams interface.

• Custom object rendering with serializers.

Page 32: Observable Node.js Applications - EnterpriseJS

HTTP Request

• Make API requests

• Persist state to file system

• Query database

• Update caches

Page 33: Observable Node.js Applications - EnterpriseJS

Async HTTP Request

• Make API requests

• Persist state to file system

• Query database

• Update caches

Page 34: Observable Node.js Applications - EnterpriseJS
Page 35: Observable Node.js Applications - EnterpriseJS
Page 36: Observable Node.js Applications - EnterpriseJS
Page 37: Observable Node.js Applications - EnterpriseJS

node-vasync

• Observable Async workflow

• https://github.com/davepacheco/node-vasync

Page 38: Observable Node.js Applications - EnterpriseJS

async f() state

failed f()

successful f()

pending f()

finished f() # of errors

Page 39: Observable Node.js Applications - EnterpriseJS

Example

cb() not invoked

Page 40: Observable Node.js Applications - EnterpriseJS
Page 41: Observable Node.js Applications - EnterpriseJS

Results

function three pending

Page 42: Observable Node.js Applications - EnterpriseJS

How Do I See this in Prod?

• Logs

• Core Dumps

• REPL

• HTTP API

Page 43: Observable Node.js Applications - EnterpriseJS

Observable Node.js HTTP

Page 44: Observable Node.js Applications - EnterpriseJS

• Observability

• Metrics

• Bunyan integration

Page 45: Observable Node.js Applications - EnterpriseJS

restify http://restify.com

http://github.com/restify/node-restify

Page 46: Observable Node.js Applications - EnterpriseJS

Audit Logs

Page 47: Observable Node.js Applications - EnterpriseJS

Audit Logsstatus code request ID (UUID)URL

request headers

response headers

individual handler timers

req latency

Page 48: Observable Node.js Applications - EnterpriseJS
Page 49: Observable Node.js Applications - EnterpriseJS

Too many logs!

Page 50: Observable Node.js Applications - EnterpriseJS

Request Capture Stream

• Captures all log statements at trace level in memory.

• Dump all logs for a particular request only on error.

Page 51: Observable Node.js Applications - EnterpriseJS
Page 52: Observable Node.js Applications - EnterpriseJS
Page 53: Observable Node.js Applications - EnterpriseJS

Scoped Child Loggers

Page 54: Observable Node.js Applications - EnterpriseJS
Page 55: Observable Node.js Applications - EnterpriseJS
Page 56: Observable Node.js Applications - EnterpriseJS
Page 57: Observable Node.js Applications - EnterpriseJS
Page 58: Observable Node.js Applications - EnterpriseJS

Logging

• Native Bunyan integration

• Request capture stream

• Audit logs

• Scoped child loggers

Page 59: Observable Node.js Applications - EnterpriseJS

What about Data Processing?

Page 60: Observable Node.js Applications - EnterpriseJS

Examples

Find all logs for a specific request.

$ grep $uuid restify.log

Page 61: Observable Node.js Applications - EnterpriseJS

Examples

Count the # of non-200 responses.

$ grep restify-audit restify.log | bunyan -c ‘this.res.statusCode !== 200` -0 | wc -l

Page 62: Observable Node.js Applications - EnterpriseJS

Examples

Show all requests that took longer than 200ms.

$ grep restify-audit restify.log | bunyan -c ‘this.latency > 200` -0 | wc -l

Page 63: Observable Node.js Applications - EnterpriseJS

Advanced ExampleRequest latency distribution by URL

Page 64: Observable Node.js Applications - EnterpriseJS

restify + Bunyan• Streaming JSON.

• Processing using Unix tools is easy.

• Helpful tools:

• Unix: cut(1), wc(1), grep(1), awk(1), perl(1), json(1), jq(1)…

• JSON: https://github.com/trentm/json (npm install -g json)

• daggr: https://github.com/joyent/daggr (npm install -g daggr)

Page 65: Observable Node.js Applications - EnterpriseJS

Increased Errors Increased Latency

Page 66: Observable Node.js Applications - EnterpriseJS

restifyCore Contributors at Netflix

@stinkydofu, @mjr578, @yunongx

Page 67: Observable Node.js Applications - EnterpriseJS

restifyInterested? Contribute to restify!

restify.com github.com/restify/node-restify

Page 68: Observable Node.js Applications - EnterpriseJS

distributed processing

• elasticsearch • spark • hive

bunyanrestify

audit logs

req id req headers

req latency

handler latenciesURL

res codeErrors

res headers

Processing w/ Unix tools

• grep(1) • awk(1) • cut(1) • wc(1) • sort(1) • json(1) • bunyan(1) • …

req scoped logs application specific

context

req capture stream dumps all logs on error

DTrace*req latencyhandler

latencies

* Where available

Production Observability

Page 69: Observable Node.js Applications - EnterpriseJS

Observable Toolkit• vasync: https://github.com/davepacheco/node-vasync

• Observable async operations

• bunyan: https://github.com/trentm/node-bunyan

• Streaming JSON logs

• restify: restify.com

• Observable REST applications

• Unix Tools

• Easily process JSON logs

Page 70: Observable Node.js Applications - EnterpriseJS

One more thing…

Page 71: Observable Node.js Applications - EnterpriseJS

DTrace

Page 72: Observable Node.js Applications - EnterpriseJS

Thanks

• Questions? We’re hiring!

[email protected]

• @yunongx

• http://restify.com

July 2015EnterprisJS