Raemon

1,109 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,109
On SlideShare
0
From Embeds
0
Number of Embeds
20
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Raemon

  1. 1. . . Raemon @yinhm June 7, 2010 . . @yinhm Raemon 1/8
  2. 2. . Daemon libs . • daemons • servolux • daemon kit . . @yinhm Raemon 2/8
  3. 3. . Raemon . • base on unicorn • master -> multi-work(preforked) model . . @yinhm Raemon 3/8
  4. 4. . Unicorn . • it is UNIX • fork • IO::pipe, selfpipe • socket • tmpio . . @yinhm Raemon 4/8
  5. 5. . example: consume queue . #!/ u s r / b i n / env ruby r e q u i r e ' rubygems ' r e q u i r e ' raemon ' r e q u i r e ' b e a n s t a l k−c l i e n t ' ENV[ " RAILS_ENV " ] ||= " development " r e q u i r e F i l e . dirname (__FILE__) + " / . . / . . / c o n f i g / environment " A c t i o n C o n t r o l l e r : : Base . perform_caching = f a l s e c l a s s FooJobWorker TIMEOUT = 10 i n c l u d e Raemon : : Worker def before_start @ b e a n s t a l k = B e a n s t a l k : : Pool . new ( [ ' l o c a l h o s t : 1 1 3 0 0 ' ] , ' foo ' ) end d e f before_shutdown @beanstalk . c l o s e end def execute ... end end Raemon : : Master . s t a r t u p ( 2 , FooJobWorker , { : detach = true , > : logger = Logger . new (RAILS_ROOT + '/ l o g / foo_queue . log ' ) , > : p i d _ f i l e = RAILS_ROOT + '/tmp/ p i d s / foo_queue . pid ' , > : timeout = 120 > }). join . . @yinhm Raemon 5/8
  6. 6. . example: execute . c l a s s FooJobWorker ... def execute begin j o b = @ b e a n s t a l k . r e s e r v e (TIMEOUT) i f job l o g g e r . i n f o "(#{ P r o c e s s . pp id }:#{ P r o c e s s . p i d }) got j o b : #{j o b . i n s p e c t }" A c t i v e R e c o r d : : Base . c o n n e c t i o n . uncached do f o o = Foo . f i n d ( j o b . ybody ) i f foo . process job . d e l e t e else j o b . r e l e a s e ( j o b . p r i , 60) end end end r e s c u e B e a n s t a l k : : TimedOut rescue StandardError l o g g e r . e r r o r " Got e x c e p t i o n : #{$ ! . i n s p e c t }" i f job job . d e l e t e job = n i l end end . end @yinhm end Raemon . 6/8
  7. 7. . References . • Raemon • Unicorn • I like Unicorn because it's Unix . . @yinhm Raemon 7/8
  8. 8. . About . Created in A E using the beamer class, TeX Live and Emacs. L X T Published under the Creative Commons Attribution 3.0 License http://creativecommons.org/licenses/by/3.0/ by @yinhm http://yinhm.appspot.com Document version June 7, 2010 . . @yinhm Raemon 8/8

×