0
淺談Ruby	  Process	  Fork應用	                    大貓	  	        (YC	  Ling,	  @miaout17)
Applica@on	  Concurrency•  Event-­‐Driven	  I/O	  (Ex.	  Eventmachine,	  goliath)	         –  Everything	  need	  to	  be	...
Worker	  Processes	                 Memory	  Usage80MBProcess	     1
Worker	  Processes	                               Memory	  Usage80MB         80MB          80MB        80MB         80MB  ...
Forked	  Worker	  Processes	  (Ex.	  Unicorn)	       Memory	  Usage:	  Copy	  on	  WriteGod	  MonitMaster	                ...
Worker	  Processes	                                 Startup	  TimeProcess	  1Process	  2Process	  3Process	  4Process	  5P...
Forked	  Worker	  Processes	  (Ex.	  Unicorn)	                     Startup	  TimeMaster	  Process                       Lo...
Resque•    The	  master	  process	  loads	  the	  environment.	  	  •    Whenever	  get	  a	  new	  job,	  fork	  a	  work...
50	  resque	  workers?•  Don’t	  do	  this:	      –  COUNT=50	  QUEUE=*	  rake	  resque:workers	  •  80MB*50	  =	  4GB    ...
resque-­‐pool•  hgps://github.com/nevans/resque-­‐pool	                         Worker	                         Worker	   ...
Summary•  Process	  forking	  in	  Ruby	      –  For	  isola@on	          •  Prevent	  process	  status	  corrup@on	      ...
Upcoming SlideShare
Loading in...5
×

淺談Ruby process fork應用

514

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
514
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
9
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "淺談Ruby process fork應用"

  1. 1. 淺談Ruby  Process  Fork應用   大貓     (YC  Ling,  @miaout17)
  2. 2. 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    
  3. 3. Worker  Processes   Memory  Usage80MBProcess   1
  4. 4. 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
  5. 5. 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
  6. 6. 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.  
  7. 7. 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  
  8. 8. 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
  9. 9. 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
  10. 10. 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
  11. 11. Summary•  Process  forking  in  Ruby   –  For  isola@on   •  Prevent  process  status  corrup@on   •  See  also:  spork-­‐rails   –  For  concurrency   •  Faster  startup   •  Smaller  memory  footprint  
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×