30
Shubhra Kar | Products & Education twitter:@shubhrakar Build, deploy & scale node

Best Practices for Running Node.js in Production

Embed Size (px)

Citation preview

Page 1: Best Practices for Running Node.js in Production

Shubhra Kar | Products & Educationtwitter:@shubhrakar

Build, deploy & scale node

Page 2: Best Practices for Running Node.js in Production

About me

J2EE and SOA architect

Performance architect

Node, mBaaS & APIs

Page 3: Best Practices for Running Node.js in Production

These guys sent me !

Bert Belder

Ben Noordhuis

Node/io Core

RaymondFeng

Ritchie Martori

LoopBack & Express Core

SamRoberts

Miroslav Bajtos

Ryan Graham

Page 4: Best Practices for Running Node.js in Production

For a mature runtime; lets start with Process

Managers

Page 5: Best Practices for Running Node.js in Production

What is a Process Manager

AppApp

App

Secure DeploymentLifecycle ManagerHA, Hot DeploysLog AggregationVertical scalingHooks for monitoring & profilingTraditionally Open Source

Page 6: Best Practices for Running Node.js in Production

StrongLoop open source Process Manager

Page 7: Best Practices for Running Node.js in Production

StrongLoop open source Process Manager in Docker

$ curl -ssl https://strong-pm.io/docker.sh | sudo /bin/sh

Page 8: Best Practices for Running Node.js in Production

Dockerized the App for removing flab (trimming)

Node.js App

Process Manager

Containers

$ sudo sl-pm-install –driver docker

Orchestrate

Page 9: Best Practices for Running Node.js in Production

Build

Page 10: Best Practices for Running Node.js in Production

Building a node.js app

• Install:  install dependencies, run custom build steps, and prune development dependencies. Avoids issues with npm shrinkwrap

• Bundle:  modify the package.json and .npmignore configuration files so dependencies will be packed.  

• Create deployable package, either:  create a deployable .tgz package file.  commit the build onto a Git branch.

Page 11: Best Practices for Running Node.js in Production

Install Dependencies

$ slc build --install Automates below• npm install -- ignore-scripts Install Node dependencies without running scripts to build binary add-ons.   

• npm run build Specify custom build steps such as grunt build or bower in the package’s scripts.build property

• npm prune -- production Remove development only tools

and runs npm rebuild (system addons), npm install (any install scripts)

Page 12: Best Practices for Running Node.js in Production

Bundling Dependencies

$ slc build --bundle Automates below

• configure package.json

• configure .npmignore, backup is .gitignore

Page 13: Best Practices for Running Node.js in Production

Creating Archive or Pushing to Git

$ slc build –pack• uses npm pack• creates .tgz outside workspace with version control $ slc build –commit

• commits to a deployment branch• shows merge changes

$ slc build --onto deploy –install --commit (deploy branch is default)

Page 14: Best Practices for Running Node.js in Production

Build using StrongLoop Arc

Page 15: Best Practices for Running Node.js in Production

Deploy

Page 16: Best Practices for Running Node.js in Production

Deploy to Process Manager (standalone or dockerized)

$ slc deploy [ [ -s | --service] <service> ] http://<server>:<port> [ package | branch ]

Example : $ slc deploy http://myserver.myco.com:8701

Multi-App Deploy

$ slc deploy -s appone http://prod.foo.com:7777 ../app1-1.0.0.tgzDeployed `../app1-1.0.0.tgz` to `http://prod.foo.com:7777`

$ slc deploy -s apptwo http://prod.foo.com:7777 ../app2-1.0.0.tgzDeployed `../app2-1.0.0.tgz` to `http://prod.foo.com:7777`

Page 17: Best Practices for Running Node.js in Production

Multi-App on Process Manager (standalone or dockerized)

$ slc ctl -C http://prod.foo.com:7777Service ID: 1Service Name: apponeEnvironment variables:  No environment variables definedInstances:    Version  Agent version  Cluster size     4.0.30      1.4.15           4Processes:        ID      PID   WID  Listening Ports  Tracking objects?  CPU profiling?    1.1.22555  22555   0    1.1.22741  22741   5     prod.foo.com:3001    1.1.22748  22748   6     prod.foo.com:3001    1.1.22773  22773   7     prod.foo.com:3001    1.1.22793  22793   8     prod.foo.com:3001 Service ID: 2Service Name: apptwoEnvironment variables:  No environment variables definedInstances:    Version  Agent version  Cluster size     4.0.30      1.4.15           4Processes:        ID      PID   WID  Listening Ports  Tracking objects?  CPU profiling?    2.1.22984  22984   0    2.1.22985  22985   1     prod.foo.com:3002    2.1.22986  22986   2     prod.foo.com:3002    2.1.22987  22987   3     prod.foo.com:3002    2.1.22988  22988   4     prod.foo.com:3002

Page 18: Best Practices for Running Node.js in Production

Deploy Dockerized Apps

Linux Only

$ sudo sl-pm-install --driver docker

$ slc pm --driver docker

Page 19: Best Practices for Running Node.js in Production

Deploy using StrongLoop Arc to Process Managers

Page 20: Best Practices for Running Node.js in Production

Scale

Page 21: Best Practices for Running Node.js in Production

Vertical Scaling

21

Page 22: Best Practices for Running Node.js in Production

Vertical Clustering

$ slc ctl set-size my-app 4

$ slc ctlService ID: 1Service Name: my-appEnvironment variables:  No environment variables defined Instances:    Version  Agent version  Cluster size     4.1.0       1.5.1           10Processes:        ID      PID   WID  Listening Ports  Tracking objects?  CPU profiling?    1.1.50320  50320   0    1.1.50321  50321   1     0.0.0.0:3001    1.1.50322  50322   2     0.0.0.0:3001    1.1.50323  50323   3     0.0.0.0:3001    1.1.50324  50324   4     0.0.0.0:3001

Page 23: Best Practices for Running Node.js in Production

Vertical Clustering at deploy time with Arc

Page 24: Best Practices for Running Node.js in Production

Cluster Control

Page 25: Best Practices for Running Node.js in Production

Horizontal and Vertical Scaling with Process Manager

Page 26: Best Practices for Running Node.js in Production

Horizontal Scaling using Arc

Page 27: Best Practices for Running Node.js in Production

Auto-Configure Nginx

$ npm install -g strong-nginx-controller

$ sl-nginx-ctl-install to install as a service

Example

sl-nginx-ctl  -x /usr/local/bin/nginx  -l http://:8081

Page 28: Best Practices for Running Node.js in Production

Micro services scaling

28

Page 29: Best Practices for Running Node.js in Production

Hyper-scale & Micro-services Deployment

Page 30: Best Practices for Running Node.js in Production

StrongLoop – node.js Development to Production

Build and Deploy

Automate Lifecycle

Performance MetricsReal-time production monitoring

ProfilerRoot cause

CPU & Memory

API ComposerVisual modeling

StrongLoop Arc

Process Manager

Scale applications

Q2201

5Mesh

Deploy containerize

d

ORM, mBaaS, Realtime