how to scale and deploy nodejs app

29
How to scale and How to scale and deploy deploy NodeJS application” NodeJS application” JakartaJS, May 2014 JakartaJS, May 2014

Upload: yacobus-reinhart

Post on 06-Sep-2014

308 views

Category:

Technology


6 download

DESCRIPTION

 

TRANSCRIPT

Page 1: How to scale and deploy NodeJS app

““How to scale and How to scale and deploy deploy

NodeJS application”NodeJS application”JakartaJS, May 2014 JakartaJS, May 2014

Page 2: How to scale and deploy NodeJS app

aboutMe: {aboutMe: {

fullName : “ Yacobus Reinhart “,fullName : “ Yacobus Reinhart “,

nickName : “ Jack “,nickName : “ Jack “,

work : “ Domikado ”,work : “ Domikado ”,

living : “ South Jakarta ” ,living : “ South Jakarta ” ,

online : {online : {

github : “ github.com/jackbit “,github : “ github.com/jackbit “,

linkedin : “ linkedin : “ id.linkedin.com/in/yreinhart “,id.linkedin.com/in/yreinhart “,

email : “ email : “ [email protected][email protected] “ } } }}

Page 3: How to scale and deploy NodeJS app

What this share about?What this share about?

-> Improving concurency-> Improving concurency

-> Deploy with javascript-> Deploy with javascript

Page 4: How to scale and deploy NodeJS app

How does NodeJS work?How does NodeJS work?

Becarefull here !!

Page 5: How to scale and deploy NodeJS app

Never run blocking or Never run blocking or complex callback herecomplex callback here

Page 6: How to scale and deploy NodeJS app

““Because Node relies on an event loop to do its Because Node relies on an event loop to do its work, there is the danger that the callback of an work, there is the danger that the callback of an

event in the loop could run for a long time. event in the loop could run for a long time.

This means that This means that other users of the process are not other users of the process are not going to get their requests met until that long-going to get their requests met until that long-

running event’s callback has concluded.”running event’s callback has concluded.”

Is Single-Threaded evil?Is Single-Threaded evil?

Page 7: How to scale and deploy NodeJS app
Page 8: How to scale and deploy NodeJS app

Solution 1:Solution 1:Asynchronus all Asynchronus all

taskstasks

Page 9: How to scale and deploy NodeJS app
Page 10: How to scale and deploy NodeJS app

process.nextTick(callback)process.nextTick(callback)NextTick will run the process on next time of event loop start

Page 11: How to scale and deploy NodeJS app

Solution 2:Solution 2:Worker PoolsWorker Pools

Page 12: How to scale and deploy NodeJS app
Page 13: How to scale and deploy NodeJS app
Page 14: How to scale and deploy NodeJS app

When worker pool is used?When worker pool is used?If you want task runs in even operation,

isolate it from parent thread and parallize request. It is not real parallel process, but enqueued.

Disadvantages of worker Disadvantages of worker pools:pools:An excessive number of threads will also waste

memory, and context-switching between the runnable threads also damages performance

If the number of tasks is very large, then creating a thread for each one may be impractical

Page 15: How to scale and deploy NodeJS app

Solution 3:Solution 3:ClusterCluster

Page 16: How to scale and deploy NodeJS app
Page 17: How to scale and deploy NodeJS app
Page 18: How to scale and deploy NodeJS app
Page 19: How to scale and deploy NodeJS app
Page 20: How to scale and deploy NodeJS app

When cluster is used?When cluster is used?If you want use multiple processes to handle IO depending on the availability of cores and share the same IO handle

(or queue)

Disadvantages of cluster:Disadvantages of cluster:Clustered processes are limited to V8’s maximum memory

per process restrictions

Provides better uptime for the applications. When one of the running Node.JS instances crash, host process creates

another one

Tools:Tools:https://github.com/gosquared/clutch

https://github.com/jackbit/node-clustrap/tree/v1

Page 21: How to scale and deploy NodeJS app

Solution 4:Solution 4:HybridHybrid

Page 22: How to scale and deploy NodeJS app
Page 23: How to scale and deploy NodeJS app

When hybrid is used?When hybrid is used?If you want share the same logic from server to run in client

or browser. It will reduce time computation in server.

Disadvantages of hybrid:Disadvantages of hybrid:Huge computation will blow up your browser

Not all cpu task in server can be done from browser

Tools:Tools:https://github.com/substack/node-browserify

https://github.com/azer/onejs

Page 24: How to scale and deploy NodeJS app

Do you have Do you have QuestionQuestion ? ?

Page 25: How to scale and deploy NodeJS app

Process to release your application into server and start itProcess to release your application into server and start itD E P L O Y M E N TD E P L O Y M E N T

Part #2Part #2

Page 26: How to scale and deploy NodeJS app

DEPLOYMENT ALTERNATIVEDEPLOYMENT ALTERNATIVE CapistranoCapistrano

speak: rubyspeak: ruby

source: github.com/capistrano/capistranosource: github.com/capistrano/capistrano MinaMina

speak: rubyspeak: ruby

source: github.com/mina-deploy/minasource: github.com/mina-deploy/mina MincoMinco

speak: nodejsspeak: nodejs

source: github.com/dsmatter/minco source: github.com/dsmatter/minco Mina JSMina JS

speak: nodejsspeak: nodejs

source: github.com/CenturyUna/mina source: github.com/CenturyUna/mina

Page 27: How to scale and deploy NodeJS app

we speak JS,we speak JS,so so deploydeploy in JS in JS

Page 28: How to scale and deploy NodeJS app

Sharing ExperienceSharing Experience Install mina from nodejsInstall mina from nodejs Setup deploy configurationSetup deploy configuration Setup Load Balancer (nginx)Setup Load Balancer (nginx)

For more detail please open:https://coderwall.com/p/lk21mw

Page 29: How to scale and deploy NodeJS app

THANKTHANK YOU ;) YOU ;)