Top Banner
Shubhra Kar | Products & Education twitter:@shubhrakar mail:[email protected] Frameworks or a Design Pattern ?
50

Node summit workshop

Jul 15, 2015

Download

Software

Shubhra Kar
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Node summit workshop

Shubhra Kar | Products & Education twitter:@shubhrakar mail:[email protected]

Frameworks or a Design Pattern ?

Page 2: Node summit workshop

These guys sent me !

Bert Belder

Ben Noordhuis

Node Core

Raymond Feng

Ritchie Martori

LoopBack / Express Core

Sam Roberts

Miroslav Bajtos

Ryan Graham

Plus 15 other full-time open source developers working on Node.js core, modules and tools. Contributing to over 100 open source modules. Supporting banks, retail, IoT companies, startups and internet companies on Node.js

Page 3: Node summit workshop

Patterns are not created, they evolve

Right Now

— Someone on Stage

Page 4: Node summit workshop

Pattern : DIY

StrongLoop Confidential and Proprietary Information – © 2015

u  Un-opinionated u  Middleware u  Use case centric

u  Express: Web Templating u  Restify: REST API

u  Low learning curve u  Restify: Dtrace Support u  Manual CRUD/Testing/ Refactoring

Page 5: Node summit workshop

Pattern : Configuration

u  Pseudo Opinionated u  Configuration over Convention u  Granular HTTP/WebServer control u  Supported and well documented u  DIY challenges of manual CRUD/Refactor/Testing

StrongLoop Confidential and Proprietary Information – © 2015

Page 6: Node summit workshop

Pattern: ORM & Isomorphic JS

u Model Driven Development u Any data source u  Isomorphic JS

u Omni-Channel u Share Models (Client/

Server) u Loopback u Meteor

u Automatic REST API generation u Higher learning curve

StrongLoop Confidential and Proprietary Information – © 2015

Page 7: Node summit workshop

Pattern: API Economy and mobile-IoT proliferation

Explosion of channels (browsers, mobile, sensors, wearable, real-time communication)

u Sheer number of clients has increased

u Clients are increasingly sophisticated

u Node.js is the platform of choice for these API

StrongLoop Confidential and Proprietary Information – © 2015

Page 8: Node summit workshop

Latency demands are uncompromising

10

25

50

100 100

50

10 1 5

40

100

25

Web SaaS Mobile IoT

The new curve Concurrent Users Latency Adoption

StrongLoop Confidential and Proprietary Information – © 2015

Page 9: Node summit workshop

Analyze, Analyze, Analyze

Page 10: Node summit workshop

Not all APIs are built equal

The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, and then open the file again. If the red x still appears, you may have to delete the image and then insert it again.

Relational Database Clustered Database Security Gateway Cloud Firewall SOA Bus ( not sure on this one)

Laptop ( not requested but useful)

Connections

Tablet Phone IoT SDK API SERVER Items for ACL

Quick Example of Use

App Server Add On

App Server

Relational Database Clustered Database Security Gateway Cloud Firewall SOA Bus ( not sure on this one)

Laptop ( not requested but useful)

Connections

Tablet Phone IoT SDK API SERVER Items for ACL

Quick Example of Use

App Server Add On

App Server

X – Backend ?

X - Channel

X - Platform

API Neutrality

Mainframe to Mobile ?

StrongLoop Confidential and Proprietary Information – © 2015

Page 11: Node summit workshop

API “Re-Composition” is good…but not good enough

Relational Database Clustered Database Security Gateway Cloud Firewall SOA Bus ( not sure on this one)

Laptop ( not requested but useful)

Connections

Tablet Phone IoT SDK API SERVER Items for ACL

Quick Example of Use

App Server Add On

App Server

Relational Database Clustered Database Security Gateway Cloud Firewall SOA Bus ( not sure on this one)

Laptop ( not requested but useful)

Connections

Tablet Phone IoT SDK API SERVER Items for ACL

Quick Example of Use

App Server Add On

App Server

Auth Routing Rate-Limit Proxy Mediation Orchestration Analytics

StrongLoop Confidential and Proprietary Information – © 2015

Page 12: Node summit workshop

The need is “DE-COMPOSITION”

SaaS Mobile IoT Web

App Server API Server

HTML JSON

{JSON} {JSON}

{JSON}

<SOAP/XML>

<TABLE>

StrongLoop Confidential and Proprietary Information – © 2015

Page 13: Node summit workshop

Micro-services has arrived

StrongLoop Confidential and Proprietary Information – © 2015

Page 14: Node summit workshop

Now I know !!!

Page 15: Node summit workshop
Page 16: Node summit workshop

StrongLoop Open source iPaaS (Arc)

StrongLoop Confidential and Proprietary Information – © 2015

Page 17: Node summit workshop
Page 18: Node summit workshop

REST API

PUSH

GEO OFF SYNC

DEVICE

USER FILE

Relational Database Clustered Database Security Gateway Cloud Firewall SOA Bus ( not sure on this one)

Laptop ( not requested but useful)

Connections

Tablet Phone IoT SDK API SERVER Items for ACL

Quick Example of Use

App Server Add On

App Server

Storage

Relational Database Clustered Database Security Gateway Cloud Firewall SOA Bus ( not sure on this one)

Laptop ( not requested but useful)

Connections

Tablet Phone IoT SDK API SERVER Items for ACL

Quick Example of Use

App Server Add On

App Server

REST

API GATEWAY

Channel SDKs

API ENGINE

CONNECTORs

API

SDKs

Loopback open source Enterprise ORM framework

REST API

Relational Database Clustered Database Security Gateway Cloud Firewall SOA Bus ( not sure on this one)

Laptop ( not requested but useful)

Connections

Tablet Phone IoT SDK API SERVER Items for ACL

Quick Example of Use

App Server Add On

App Server

API Explorer

Page 19: Node summit workshop

Marquee Features

u  Discovery

u Migration / Replication

u  Relationship Mapping

u Mixins - Aggregation

u  Access Control

u  User Management

u  Isomorphic JS / Remoting u  Routing

StrongLoop Confidential and Proprietary Information – © 2014

Page 20: Node summit workshop

{“..”} JSON is the new first class citizen

StrongLoop Confidential and Proprietary Information – © 2014

Page 21: Node summit workshop

Data & Services Integration

Services

Relational Database Clustered Database Security Gateway Cloud Firewall SOA Bus ( not sure on this one)

Laptop ( not requested but useful)

Connections

Tablet Phone IoT SDK API SERVER Items for ACL

Quick Example of Use

App Server Add On

App Server

Storage

Relational Database Clustered Database Security Gateway Cloud Firewall SOA Bus ( not sure on this one)

Laptop ( not requested but useful)

Connections

Tablet Phone IoT SDK API SERVER Items for ACL

Quick Example of Use

App Server Add On

App Server

REST

Messaging

Database

NoSQL

Marquee - Discovery & Migration !

StrongLoop Confidential and Proprietary Information – © 2014

Page 22: Node summit workshop

User Experience

  Arc UI – architect view –  Widget driven –  Visual composition,

management & operations –  Marquee featured, evolving

platform

  StrongLoop Console (slc) - developer view –  Command Line Interface –  Full featured –  Greater customization support

StrongLoop Confidential and Proprietary Information – © 2014

Page 23: Node summit workshop

API Explorer (Swagger) – Iterative build and test w/o frontend

StrongLoop Confidential and Proprietary Information – © 2014

Page 24: Node summit workshop

API Gateway *

Security & Social Logins

* Evolving. Please do not share without written consent from StrongLoop

Marquee – Auth, Routing, Throttling, Proxy, Mediation, Aggregation, Virtualization

StrongLoop Confidential and Proprietary Information – © 2014

Page 25: Node summit workshop

Developer SDKs

Omni-channel Client SDKs

JS client

JS Server

Remoting

JS client

Marquee – Isomorphic JS, Mobile Integration

StrongLoop Confidential and Proprietary Information – © 2014

Page 26: Node summit workshop

Mobile Services: Offline Sync

StrongLoop Confidential and Proprietary Information – © 2014

Page 27: Node summit workshop

Mobile Services: Push Notification

StrongLoop Confidential and Proprietary Information – © 2014

Page 28: Node summit workshop

Mobile Services: GeoLocation

Page 29: Node summit workshop

Coding Time

Page 30: Node summit workshop

StrongLoop Confidential and Proprietary Information – © 2015

Page 31: Node summit workshop

Debugging Marquee – Chrome Dev Tools, Remote

StrongLoop Confidential and Proprietary Information – © 2014

Page 32: Node summit workshop

Memory Leaks ?

StrongLoop Confidential and Proprietary Information – © 2015

Page 33: Node summit workshop

heapdump for V8 snapshots by @bnoordhuis

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

StrongLoop Confidential and Proprietary Information – © 2015

Page 34: Node summit workshop

heapdump for V8 snapshots by @bnoordhuis   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>

StrongLoop Confidential and Proprietary Information – © 2015

Page 35: Node summit workshop

We have made it simpler in Arc – Remote heaps

StrongLoop OSS - HeapSnapshots slc runctl heap-snapshot ID

Page 36: Node summit workshop

CPU’s smoke too !

StrongLoop Confidential and Proprietary Information – © 2015

Page 37: Node summit workshop

CPU profiler : slc cpu-start/stop or just slc arc

StrongLoop Confidential and Proprietary Information – © 2015

Page 38: Node summit workshop

How we fixed a real production problem

Page 39: Node summit workshop

Don’t Block the EventLoop

StrongLoop Confidential and Proprietary Information – © 2015

Page 40: Node summit workshop

Blocked event loop in Meteor atmosphere

  node-fibers implements co-routines. Meteor uses this to hack local thread storage allowing V8 to run multiple execution contexts each mapped to a co-routine.

FindOrAllocatePerThreadDataForThisThread() used in switching context between co-routines

  Co-routines are cooperative; the current coroutine has to yield control before another one can

run and that is what Meteor does in its process.nextTick() callback; it essentially builds concurrent (but not parallel) green threads on a round-robin scheduler

  Too many tiny tasks and not one long running one was blocking the event loop

process.nextTick() has a failsafe mechanism where it will process “x” tick callbacks before deferring the remaining ones to the next event loop tick.

  Native MongoDB driver disabled the failsafe to silence a warning message in node v0.10 about

maxtickDepth being reached

ticks parent name 2274 7.3% v8::internal::Isolate::FindOrAllocatePerThreadDataForThisThread() 1325 58.3% LazyCompile: ~<anonymous> packages/meteor.js:683 1325 100.0% LazyCompile: _tickCallback node.js:399

Page 41: Node summit workshop

The solution

  The workaround: switch fromprocess.nextTick() to setImmediate()

Page 42: Node summit workshop

Performance Monitoring

StrongLoop Confidential and Proprietary Information – © 2015

Page 43: Node summit workshop

Production Monitoring & 3rd Party integration

•  Local / Hosted •  Graphite •  Splunk •  Datadog •  CA Introscope

StrongLoop Confidential and Proprietary Information – © 2014

Page 44: Node summit workshop

Dynamic Instrumentation

Agent App Monkey Patching

Agent App Dynamic Instrument

•  Live Edit •  Line Level

Instrumentation •  Any package, any

framework, any code

•  Custom logic •  HA rollback

StrongLoop Confidential and Proprietary Information – © 2015

Page 45: Node summit workshop

Process Management & HyperScaling

StrongLoop Confidential and Proprietary Information – © 2015

Page 46: Node summit workshop

Private Registry & Build

StrongLoop Confidential and Proprietary Information – © 2015

Page 47: Node summit workshop

Build & Deploy

StrongLoop Confidential and Proprietary Information – © 2014

Page 48: Node summit workshop

Cluster and runtime scaling Marquee – HA, Auto-scale, Hot Deploy

StrongLoop Confidential and Proprietary Information – © 2014

Page 49: Node summit workshop

MESH – Micro-services Deploy on Scale

StrongLoop Confidential and Proprietary Information – © 2014

Page 50: Node summit workshop

First there was Node

Thank you!

JUST WIN,BABY!