Html5 devconf nodejs_devops_shubhra

Preview:

Citation preview

Triage, Diagnose & Scale Node.js

Shubhra Kar | Director – Products

twitter:@shubhrakar mail:skar@strongloop.com

Why am I here…or rather who sent me here ?

These guys sent me !

Bert

Belder

Ben

Noordhuis

Node Core

Raymond

FengRitchie

Martori

LoopBack/Express Core

Sam

Roberts

Miroslav

Bajtos

Ryan

Graham

To do what ?

To give you a fresh pair of gloves

Let’s revisit the STORY

Let’s touch up our

SOA for

Mobile…and bring

Glass @ work

Architect Developer

The boss does have valid questions

I recommend

Node.js for our

API strategy

Architect The Boss

Node is nerdy like systems

programming !...Where are

tools ? Do we have an IDE ?

Node.js APIs actually have a life cycle

8

Compose

Deploy / Scale

Monitor

Secure / Manage

API Studio Controller StrongOps API Gateway

Development Production

Reliable API Solutions powered by Node.js

Let’s start by debugging

• Chrome debugger

• Debug Remotely on

Production

• Breakpoints &

uncaught exceptions

• Source Maps

• Unit test integration

• Display/edit variables

• Pre-loaded breaks

Known as Node-Inspector / StrongLoop-Debug

Debugging server side clustered apps

slc debug app.js

Debugging single process

slc debug app.js

http://localhost:8080/debug?port=<5858+ID-of-process>

Debugging clustered process in V11

%node debug –p <PID>

connecting…ok

debug>quit

%node-inspector

http://127.0.0.1:8080/debug?port =5858

Or

process._debugPort = 5858 + cluster.worker.id

Debugging clustered process in V10

Can Errors be stitched into a trace and recovered ?

Enter StrongLoop / Zones

But is it enough to convince him ?

Plus I can now

diagnose CPU

hotspots and Memory

Bottlenecks

Architect The Boss

Node is fast you said

!...what bottlenecks and

leaks ?

How to diagnose CPU hotspots upto line of code ?

Enter StrongLoop OSS - Node Profiler

slc runctl cpu-start/stop PID >> CPU Proc files

Can I visually see my hotspots ?

Chrome Dev Tools – For Server !

How about a fancy chart for my boss ?

Call Stack

Path and

function

CPU Cycle

times

Does Node have memory leaks ?

StrongLoop OSS - HeapSnapshots

slc runctl heap-snapshot PID

heapdump for V8 snapshots

npm install heapdump

Add to app : var heapdump = require(‘heapdump’)

Method 1 : writeSnapshot

Method 2 : SIGUSR2 (Unix only)

Make sure your directory is writable

var heapdump = require('heapdump')

...

heapdump.writeSnapshot()

kill –USR2 <pid>

process.chdir('/path/to/writeable/dir’)

Heap Snapshot strategies

Programmatic heap snapshots (timer based)

Programmatic heap snapshots (threshold based)

var heapdump = require('heapdump')

...

setInterval(function () {

heapdump.writeSnapshot()

}, 6000 * 30) <strong>(1)</strong>

var heapdump = require('heapdump')

var nextMBThreshold = 0 <strong>(1)</strong>

setInterval(function () {

var memMB = process.memoryUsage().rss / 1048576

<strong>(2)</strong>

if (memMB &gt; nextMBThreshold) { <strong>(3)</strong>

heapdump.writeSnapshot()

nextMBThreshold += 100

}

}, 6000 * 2) <strong>(4)</strong>

Another fancy chart please

We are getting there…

See we have

great Dev

Tools

Architect The Boss

Not at 3:00 a.m. in the night

!….Show me its Production

ready

Ok…here is 24x7 monitoring

On-Premises / 3rd Party monitoring ?

22

• Graphite

• Splunk

• Datadog

• Introscope

• Others

And On-Demand Dynamic Instrumentation

Agent AppMonkey

Patching

Agent AppDynamic

Instrument

• Live Edit

• Line Level

Instrumentation

• Any package, any

framework, any code

• Custom logic

• Counters, Gauges and

Timers

• HA rollback

Almost there …

Look I got

monitoring

Architect The Boss

Good…but before I promote

you, show me some scale

Vertical and pseudo-horizontal scaling

• OSS Controller

• Cluster Mgmt.

• Hot Deploy

• Rolling Restart

• Cluster State Mgmt.

• Process Mgmt.

• Deploy

MESH – All things distributed

• Distributed

Deploy

• Cross MC state

• HA

• Docker Containers

• Auto Scaling

• Process Mgmt.

Log Aggregation

• OSS Controller

• Structured Logging

• Log Aggregation

• 3rd Party Integration

That’s how we win.

The Boss

hehe…I am a Node Hipster now !

Nodies are not just silicon valley hipsters !

And most recently….#1 Retailer

First there was Node

Thank you!

JUST WIN,

BABY!