How to scale and deploy NodeJS app

1,294 views

Published on

Published in: Technology, Business
1 Comment
4 Likes
Statistics
Notes
No Downloads
Views
Total views
1,294
On SlideShare
0
From Embeds
0
Number of Embeds
40
Actions
Shares
0
Downloads
30
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

How to scale and deploy NodeJS app

  1. 1. ““How to scale and deployHow to scale and deploy NodeJS application”NodeJS application” JakartaJS, May 2014JakartaJS, May 2014
  2. 2. 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 : “ id.linkedin.com/in/yreinhart “,linkedin : “ id.linkedin.com/in/yreinhart “, email : “ yacobus.reinhart@gmail.com “email : “ yacobus.reinhart@gmail.com “ }} }}
  3. 3. What this share about?What this share about? -> Improving concurency-> Improving concurency -> Deploy with javascript-> Deploy with javascript
  4. 4. How does NodeJS work?How does NodeJS work? Becarefull here !!
  5. 5. Never run blocking or complexNever run blocking or complex callback herecallback here
  6. 6. ““Because Node relies on an event loop to do its work,Because Node relies on an event loop to do its work, there is the danger that the callback of an event in thethere is the danger that the callback of an event in the loop could run for a long time.loop could run for a long time. This means thatThis means that other users of the process are not goingother users of the process are not going to get their requests met until that long-running event’sto get their requests met until that long-running event’s callback has concluded.”callback has concluded.” Is Single-Threaded evil?Is Single-Threaded evil?
  7. 7. Solution 1:Solution 1: Asynchronus all tasksAsynchronus all tasks
  8. 8. process.nextTick(callback)process.nextTick(callback) NextTick will run the process on next time of event loop start
  9. 9. Solution 2:Solution 2: Worker PoolsWorker Pools
  10. 10. 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 pools:Disadvantages of worker 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
  11. 11. Solution 3:Solution 3: ClusterCluster
  12. 12. 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
  13. 13. Solution 4:Solution 4: HybridHybrid
  14. 14. 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
  15. 15. Do you haveDo you have QuestionQuestion ??
  16. 16. Process to release your application into server and start itProcess to release your application into server and start it D E P L O Y M E N TD E P L O Y M E N T Part #2Part #2
  17. 17. 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/mincosource: github.com/dsmatter/minco  Mina JSMina JS − speak: nodejsspeak: nodejs − source: github.com/CenturyUna/minasource: github.com/CenturyUna/mina
  18. 18. we speak JS,we speak JS, soso deploydeploy in JSin JS
  19. 19. 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
  20. 20. THANKTHANK YOU ;)YOU ;)

×