淺談Ruby process fork應用
Upcoming SlideShare
Loading in...5
×
 

淺談Ruby process fork應用

on

  • 893 views

 

Statistics

Views

Total Views
893
Views on SlideShare
893
Embed Views
0

Actions

Likes
1
Downloads
8
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

淺談Ruby process fork應用 淺談Ruby process fork應用 Presentation Transcript

  • 淺談Ruby  Process  Fork應用   大貓     (YC  Ling,  @miaout17)
  • Applica@on  Concurrency•  Event-­‐Driven  I/O  (Ex.  Eventmachine,  goliath)   –  Everything  need  to  be  non-­‐blocking.    •  Worker  Threads  (Ex.  Rainbows  with  proper  config)   –  Everything  need  to  be  thread-­‐safe.    •  Worker  Processes  (Ex.  unicorn)   –  OS  process  is  expensive   –  Reality:  You  are  using  a  lot  of  3rd  party  libraries,  some   of  them  are  blocking  and  not  thread-­‐safe   –  S@ll  mainstream  today   –  I  don’t  like  it  very  much,  but  it  just  works    
  • Worker  Processes   Memory  Usage80MBProcess   1
  • Worker  Processes   Memory  Usage80MB 80MB 80MB 80MB 80MB 80MB 80MB 80MBProcess   Process   Process   Process   Process   Process   Process   Process   1 2 3 4 5 6 7 8
  • Forked  Worker  Processes  (Ex.  Unicorn)   Memory  Usage:  Copy  on  WriteGod  MonitMaster   Process   Process   Process   Process   Process   Process   Process   Process  Process 1 2 3 4 5 6 7 8 Normal  Memory  Page (CoW)Read-­‐Only  Page
  • Worker  Processes   Startup  TimeProcess  1Process  2Process  3Process  4Process  5Process  6Process  7Process  8 Time •  Assuming  2  cores   •  The  8  processes  could  be  started  simultaneously  and  the   startup  will  be  execute  concurrently  with  content  switching.  
  • Forked  Worker  Processes  (Ex.  Unicorn)   Startup  TimeMaster  Process Loading  environment Process  1 Process  2 Process  3 Process  4 Forking Process  5 Process  6 Process  7 Process  8 Time •  Load  the  applica@on  ONCE   •  Fork  is  FAST  
  • Resque•  The  master  process  loads  the  environment.    •  Whenever  get  a  new  job,  fork  a  worker  process.    •  Whenever  the  job  is  done,  the  worker  process  exits.    •  For  isola@on:  Resque  assumes  chaos Worker   Got  a  job! Process Job  done   Fork  Process Worker  process  terminates   Master   Process
  • 50  resque  workers?•  Don’t  do  this:   –  COUNT=50  QUEUE=*  rake  resque:workers  •  80MB*50  =  4GB Worker   Worker   Worker   Process Process Process Master   Master   Master   Master   Master   Master   …   Process Process Process Process Process Process 80  MB 80  MB 80  MB 80  MB 80  MB 80  MB
  • resque-­‐pool•  hgps://github.com/nevans/resque-­‐pool   Worker   Worker   Worker   Process Process Process Fork Master   Master   Master   Master   Master   Master   Process Process Process Process Process Process Fork Pool   Manager
  • Summary•  Process  forking  in  Ruby   –  For  isola@on   •  Prevent  process  status  corrup@on   •  See  also:  spork-­‐rails   –  For  concurrency   •  Faster  startup   •  Smaller  memory  footprint