29
Triage, Diagnose & Scale Node.js Shubhra Kar | Director Products twitter:@shubhrakar mail:[email protected]

Html5 devconf nodejs_devops_shubhra

Embed Size (px)

Citation preview

Page 1: Html5 devconf nodejs_devops_shubhra

Triage, Diagnose & Scale Node.js

Shubhra Kar | Director – Products

twitter:@shubhrakar mail:[email protected]

Page 2: Html5 devconf nodejs_devops_shubhra

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

Page 3: Html5 devconf nodejs_devops_shubhra

These guys sent me !

Bert

Belder

Ben

Noordhuis

Node Core

Raymond

FengRitchie

Martori

LoopBack/Express Core

Sam

Roberts

Miroslav

Bajtos

Ryan

Graham

Page 4: Html5 devconf nodejs_devops_shubhra

To do what ?

To give you a fresh pair of gloves

Page 5: Html5 devconf nodejs_devops_shubhra

Let’s revisit the STORY

Let’s touch up our

SOA for

Mobile…and bring

Glass @ work

Architect Developer

Page 6: Html5 devconf nodejs_devops_shubhra

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 ?

Page 7: Html5 devconf nodejs_devops_shubhra

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

Page 8: Html5 devconf nodejs_devops_shubhra

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

Page 9: Html5 devconf nodejs_devops_shubhra

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

Page 10: Html5 devconf nodejs_devops_shubhra

Can Errors be stitched into a trace and recovered ?

Enter StrongLoop / Zones

Page 11: Html5 devconf nodejs_devops_shubhra

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 ?

Page 12: Html5 devconf nodejs_devops_shubhra

How to diagnose CPU hotspots upto line of code ?

Enter StrongLoop OSS - Node Profiler

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

Page 13: Html5 devconf nodejs_devops_shubhra

Can I visually see my hotspots ?

Chrome Dev Tools – For Server !

Page 14: Html5 devconf nodejs_devops_shubhra

How about a fancy chart for my boss ?

Call Stack

Path and

function

CPU Cycle

times

Page 15: Html5 devconf nodejs_devops_shubhra

Does Node have memory leaks ?

StrongLoop OSS - HeapSnapshots

slc runctl heap-snapshot PID

Page 16: Html5 devconf nodejs_devops_shubhra

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’)

Page 17: Html5 devconf nodejs_devops_shubhra

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>

Page 18: Html5 devconf nodejs_devops_shubhra

Another fancy chart please

Page 19: Html5 devconf nodejs_devops_shubhra

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

Page 20: Html5 devconf nodejs_devops_shubhra

Ok…here is 24x7 monitoring

Page 21: Html5 devconf nodejs_devops_shubhra

On-Premises / 3rd Party monitoring ?

22

• Graphite

• Splunk

• Datadog

• Introscope

• Others

Page 22: Html5 devconf nodejs_devops_shubhra

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

Page 23: Html5 devconf nodejs_devops_shubhra

Almost there …

Look I got

monitoring

Architect The Boss

Good…but before I promote

you, show me some scale

Page 24: Html5 devconf nodejs_devops_shubhra

Vertical and pseudo-horizontal scaling

• OSS Controller

• Cluster Mgmt.

• Hot Deploy

• Rolling Restart

• Cluster State Mgmt.

• Process Mgmt.

• Deploy

Page 25: Html5 devconf nodejs_devops_shubhra

MESH – All things distributed

• Distributed

Deploy

• Cross MC state

• HA

• Docker Containers

• Auto Scaling

• Process Mgmt.

Page 26: Html5 devconf nodejs_devops_shubhra

Log Aggregation

• OSS Controller

• Structured Logging

• Log Aggregation

• 3rd Party Integration

Page 27: Html5 devconf nodejs_devops_shubhra

That’s how we win.

The Boss

hehe…I am a Node Hipster now !

Page 28: Html5 devconf nodejs_devops_shubhra

Nodies are not just silicon valley hipsters !

And most recently….#1 Retailer

Page 29: Html5 devconf nodejs_devops_shubhra

First there was Node

Thank you!

JUST WIN,

BABY!