Rails ãã AP4R ãµã¼ãã¸ã®æ¥ç¶ã®å¯ç¨æ§ã¨ããè² è·åæ£ã¨ã...
AP4R ã«ã¤ãã¦æ¸ãã®ã¯ããã¶ãä¹ ãã¶ããªæ°ããã¾ãã... (^^;
Rails 㧠AP4R ã使ã£ã¦ããå ´åã以ä¸ã®æµãã§ã¡ãã»ã¼ã¸ãä»ãã¦éåæãå®ç¾ããã¦ãã¾ãã
# ã¦ã¼ã¶ã¼ããã®ãªã¯ã¨ã¹ãã§ã1,2 ãåæçã«å®è¡ããã3 以éãéåæã§å®è¡ããã¾ãã
0. AP4R ã® Rails ãã©ã°ã¤ã³ã®å°å ¥
1. ã¢ã¯ã·ã§ã³ã®ãªãã§ãap4r.async_to(message, ...) ããã¨ã
2. Rails ãã AP4R ãµã¼ãä¸ã®ãã¥ã¼ã«ã¡ãã»ã¼ã¸ã PUT (dRuby ãããã³ã«)
3. AP4R ããæå®ãããå®å ã«éä¿¡ (HTTP ãªã©)
4. å®å ã§ã¡ãã»ã¼ã¸ãå¦ç (å®å ã Rails ã§ããã°ãé常ã®ãªã¯ã¨ã¹ãã¨åæ§ã«å¦çå¯è½)
å¯ç¨æ§ã®é«ãã·ã¹ãã ãèããã¨ãããã®æµãã®ãªã㧠1->2 ã®é¨åã SPoF (Single Point of Failure) ã«ãªã£ã¦ãã¾ã£ã¦ãã¾ããã
ãªãã¼ã¹ãããã·æ§æã§ããã°ãããã¯ã¨ã³ãã® Rails ã¤ã³ã¹ã¿ã³ã¹ã®ã©ãããããã¦ããããã³ãã¨ã³ãã§ãã¾ããã¨æ¯ãããããã¨ã§ã縮éãã¤ã¤ãã·ã¹ãã ã¯åãã¤ã¥ãã¾ããããããªãããã¡ãã»ã¼ã¸ã PUT ããå ã® AP4R ãµã¼ããè½ã¡ã¦ããã¨ãã¢ã¯ã·ã§ã³ã¯ã¨ã©ã¼ã¨ãªã£ã¦ãã¾ãã¾ãã
# 確å®ã«éåæå¦çãå®è¡ãããå¿ è¦ãããã°ãæ¥åãã¼ã¿ãã¼ã¹ã¸ã®ã³ããã㨠AP4R ã¸ã®ã¡ãã»ã¼ã¸ã® PUT ã¯ã¢ãããã¯ã«ããªãã¨é§ç®ã§ããã?
åã ã® Rails ã¤ã³ã¹ã¿ã³ã¹ãã¨ã« AP4R ãåå¥ã«ç¨æããã°ããã¹ã¦ã®å¦çãã¨ã¾ããã¨ã¯ãªãã§ããããããããã¨ãµã¼ããå¢ãã¦ãã¾ãããã§ã管çãèããã¨ãããæ©ã¾ããã§ãã
ã¨ããããã§ãRails ãã AP4R ãµã¼ãã¸ã®æ¥ç¶ã«å¤±æããã¨ãã«ãå¥ã® AP4R ãµã¼ãã«ãã§ã¤ã«ãªã¼ãã¼ããããã«ãã¦ã¿ã¾ããã(ã¾ã ããªãªã¼ã¹ã¯ãã¦ã¾ããã...ã)
æä½ 2ã¤ã® AP4R ãµã¼ããèµ·åãã¦è¨å®ããã¦ããã°ãä¸æ¹ã¸ã®æ¥ç¶ã«å¤±æããã¨ããä»æ¹ã«æ¥ç¶ãåãæ¿ãã¾ãã両æ¹ã¨ãè½ã¡ã¦ãã¨ãã¯ã©ããããããªãã§ãããããã§ãªããã°çãã¦ãã AP4R ãµã¼ãã«ã¡ãã»ã¼ã¸ã PUT ã§ãã¾ãã
environment.rb ã®ãªãã§ã以ä¸ã®ããã«è¨å®ãã¾ãã
uris = %w(6438 6439 6440).map {|port| "druby://localhost:#{port}"} ::Ap4r::AsyncHelper::Base.druby_uris(uris, :fail_over => true)
æåã¯ãdruby://localhost:6438 ã«æ¥ç¶ãã«ããã¾ãããããã¨ã®æ¥ç¶ãã§ããªããã°ãdruby://localhost:6439 ã¨ã®æ¥ç¶ã試ã¿ã¾ããããã¦ããããé§ç®ã 㨠druby://localhost:6440 ã«æ¥ç¶ãã«ããã¾ããã«ã¹ã±ã¼ã ãã§ã¤ã«ãªã¼ãã¼ã£ã¦ããã¿ããã§ããã
# environment.rb ã®ãªãã§ãdruby URI ã®é åã®ä¸¦ã³é ã Rails ã¤ã³ã¹ã¿ã³ã¹ãã¨ã«å¤ããããã«ãã¦ããã° (ãã¼ãã§ãããããã©ã³ãã ã«ããã?)ãActive-Standby ã®ãããæãæ§æã¿ããã«ãªãã¾ããã
ã¡ãªã¿ã«ããªãã·ã§ã³ã¯ãã 2ã¤ãç¨æãã¦ãã¾ãã
uris = %w(6438 6439 6440).map {|port| "druby://localhost:#{port}"} ::Ap4r::AsyncHelper::Base.druby_uris(uris, :rotate => true)
ãã®è¨å®ã§ã¯ãæ¥ç¶å
ã® AP4R ãè½ã¡ã¦ãªãã¦ããã¡ãã»ã¼ã¸ã PUT ãããã¨ã«ãæ¥ç¶å
ã® AP4R ãµã¼ããåãæ¿ãã¦ããã¾ãããã¼ããã©ã³ãµã®ã©ã¦ã³ãããã³çãªåãã§ãã:fail_over ãªãã·ã§ã³ãè¨å®ãã¦ãªããã°ããã§ã¤ã«ãªã¼ãã¼ã¯ãã¾ãããéã«ã:fail_over ãªãã·ã§ã³ã¨çµã¿åãããã°ãæ£å¸¸æã§ãæ¥ç¶å
ã® AP4R ãµã¼ããåãæ¿ããç°å¸¸æã§ããã§ã¤ã«ãªã¼ãã¼ã㦠AP4R ãµã¼ããåãæ¿ãããã¨ã«ãªãã¾ãã
æ¥ç¶ã§ããªãã£ã AP4R ãµã¼ãã¯ãæ¥ç¶å
URI ã®ãªã¹ãããåããã¾ãããªã®ã§ããã£ããæ¥ç¶ã§ããªãã£ã AP4R ãµã¼ãã¯ãRails ã¤ã³ã¹ã¿ã³ã¹ãåèµ·åããã¾ã§å©ç¨ããã¾ããããããå«ãªå ´åããããããªã®ã§...
uris = %w(6438 6439 6440).map {|port| "druby://localhost:#{port}"} ::Ap4r::AsyncHelper::Base.druby_uris(uris, :fail_over => true, :fail_reuse => true)
ã¨ãã¦ããã¨ããã£ããæ¥ç¶ã§ããªãã£ã AP4R ãµã¼ãã«ãã(ãã¼ãã¼ã·ã§ã³ããã§ã¤ã«ãªã¼ãã¼ãç¹°ãè¿ãã¦ãããªãã§) æ¥ç¶ãã«ããã¾ããã»ãã¨ã¯ keep alive çãªä»çµã¿ãå
¥ãã¦ãçãè¿ã£ã¦ããæ¥ç¶å
ã® URI ãªã¹ãã«æ»ãã»ããããã®ããããã¾ããããä»åã¯ãããªé¢¨ã«ãã¦ã¿ã¾ããã
# è½ã¡ãã¾ã¾ã®ãµã¼ãã«æ¥ç¶ãä½åº¦ãç¹°ãè¿ãã®ã¯ã¾ããã®ã§ãURI ãªã¹ããã¹ã¦ã«æ¥ç¶ã試ã¿ã¦é§ç®ã§ããã°ã¨ã©ã¼ã¨ãªãã¾ãã
ããããèãã¦ã¯ã¿ããã§ããããã®ãããã®å¯ç¨æ§ãè² è·åæ£ã®åãã£ã¦ã®ã¯ãã±ã¼ã¹ãã¤ã±ã¼ã¹ãªãã ãããªãã¨æãè³ãã¾ããããã®åå¥ã®åãã DSL ã©ã¤ã¯ã«è¨å® (å®è£ ) ã§ããããã«ããããã¨ãæã£ãã®ã§ããããªãã ãä½è¨ã«è¤éã«ãªã£ã¦ãã¾ãããã ã£ãã®ã§ãã·ã³ãã«ãªåãã®ã¿ãæä¾ããã ãã«ã¨ã©ãã¦ã¿ã¾ããã