How to scale and deploy NodeJS app

Post on 06-Sep-2014

309 views 6 download

Tags:

description

 

Transcript of 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

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 : “ yacobus.reinhart@gmail.com “yacobus.reinhart@gmail.com “ } } }}

What this share about?What this share about?

-> Improving concurency-> Improving concurency

-> Deploy with javascript-> Deploy with javascript

How does NodeJS work?How does NodeJS work?

Becarefull here !!

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

““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?

Solution 1:Solution 1:Asynchronus all Asynchronus all

taskstasks

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

Solution 2:Solution 2:Worker PoolsWorker Pools

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

Solution 3:Solution 3:ClusterCluster

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

Solution 4:Solution 4:HybridHybrid

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

Do you have Do you have QuestionQuestion ? ?

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

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

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

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

THANKTHANK YOU ;) YOU ;)