å æãheroku ã®æ¨ããµã¼ãã unicorn ãã puma ã«å¤ãã£ãã¨ããçºè¡¨ãããã¾ãããunicorn ã ã¨ã¹ãã¼ã¯ã©ã¤ã¢ã³ãã®å½±é¿ãåããããã¨ããã®ãçç±ãªããã§ãã
ããå°ã詳ãã調ã¹ã¦ã¿ã¾ãããã
ããããã¹ãã¼ã¯ã©ã¤ã¢ã³ãã£ã¦ãªã«
ãã®åã®éãé ãåç·ã®ã¯ã©ã¤ã¢ã³ãã§ãã3Gç°å¢ã®ã¢ãã¤ã«ç«¯æ«ãªã©ã該å½ãã¾ãã
ãunicorn ã ã¨ã¹ãã¼ã¯ã©ã¤ã¢ã³ãã®å½±é¿ãåãããããã¨ã¯
unicorn ã¯ããã»ã¹ã¢ãã«ã®ãµã¼ãã§ãããblocking I/O ã¢ãã«ãæ¡ç¨ãã¦ãã¾ããã¤ã¾ããã¯ã©ã¤ã¢ã³ãã¨ã®éä¿¡ä¸ããã»ã¹ãå°æãããã¨ãããã¨ã§ãã
ä¾ãã° unicorn ãã¯ã¼ã«ããã»ã¹ã3ã¤ç«ã¡ä¸ãã¦ãã¦ãããã¸éä¿¡å®äºã«10åããããããªã¹ãã¼ã¯ã©ã¤ã¢ã³ãã3ã¤æ¥ç¶ããããâ¦ãç¶ãã¯ã©ã¤ã¢ã³ãã¯ã¹ãã¼ã¯ã©ã¤ã¢ã³ãã®éä¿¡ãå®äºããã¾ã§å®è¡ãå¾ ããªããã°ãªããªããªãã¾ããããã»ã¹ã®æ°ããã£ã¨å¢ããã°å¯¾å¿ã§ãã¾ãããããã¯ãã®åã¡ã¢ãªããµã¼ãå°æ°ãæçµçã«ã¯æé¡ã®ãµã¼ãè²»ç¨ã«å½±é¿ãä¸ãã¾ãã
unicorn ã¯ãªããããªè¨è¨ã«ãªã£ã¦ããã®ã
unicorn ã¯ããã²ã¨ã¤ã®ãã¨ããã¾ããããunixå²å¦ã«åã£ã¦ããããã®ä¸ã§ "ããã¯ã¨ã³ãã®" ã¢ããªã±ã¼ã·ã§ã³ãµã¼ãã¨ãã¦ä½ããã¦ãã¾ãã
ã¤ã¾ããnginx ãªã©ã®ãªãã¼ã¹ãããã·ãåé¢ã«ãã¦ãã®ãåæã¨ããä½ãã«ãªã£ã¦ããããã§ãã
ãªãã¼ã¹ãããã·ã使ãã¨ãunicorn ã¯ã¬ã¹ãã³ã¹ããªãã¼ã¹ãããã·ã¾ã§å±ããã°ãããªãã¾ãããªãã¼ã¹ãããã·ã¯ããã¦ãåä¸ãããã¯ã¼ã¯å ã«ããã®ã§ãã¨ã¦ãæ©ãéä¿¡ã§ãã¾ããã¹ãã¼ã¯ã©ã¤ã¢ã³ããéä¿¡ããã®ã¯ãªãã¼ã¹ãããã·ã§ããããã«ãããã¹ãã¼ã¯ã©ã¤ã¢ã³ãã unicorn ã®ããã»ã¹ãé·æéå°æããã®ãé²ããã¨ãã§ãã¾ãã
nginx & unicorn ã¯ãheroku 以å¤ã® Rails ã¢ããªã±ã¼ã·ã§ã³ç°å¢ã§ã¯ç¾æç¹ã§ä¸çªå¤ãæ§æãªã®ã§ã¯ãªãã§ããããã
heroku ã«ã¯ãªãã¼ã¹ãããã·ã¯ãªãã®ã
ãªãããã§ãããã ãheroku ã® HTTP Routing ã®ããã¥ã¡ã³ããè¦ãã¨ã1MB ã¾ã§ã¯ã¬ã¹ãã³ã¹ããããã¡ãã¦ãããããã§ããã
HTTP Routing | Heroku Dev Center
puma ã«å¤æ´ãããå ¨ã¦è§£æ±ºããã®ã
ãã®çºè¡¨ ã ãã®ã¸ãã®æç« ãè¦ãã¨ãpuma ã«ããããªã¼ã«ãªãã±ã¼ãªããã«èªãã¦ãã¾ãã¾ããããããªãã¨ã¯ããã¾ããã
ãã®è¨äº ã® Multi-threaded blocking I/O ã®ç®æãèªãã¨åããã®ã§ããã確ãã«ã¹ã¬ãããã¼ã¹ã®ãµã¼ããæ¡ç¨ããã¨ã1ã¹ã¬ãããã¹ãã¼ã¯ã©ã¤ã¢ã³ãã§å°æããã¦ãå¥ã®ã¹ã¬ãããå¦çãåãæã¤ãã¨ãã§ãã¾ãããã ããå ¨ã¦ã®ã¹ã¬ãããã¹ãã¼ã¯ã©ã¤ã¢ã³ãã¨éä¿¡ããããçµå±åããã¨ã§ãã
åãã¡ã¢ãªéã§ããããã»ã¹ãã¼ã¹ã®ãµã¼ããããã¹ã¬ãããã¼ã¹ã®ãµã¼ãã®æ¹ãä½æã§ããã¹ã¬ããæ°ãå¤ãã®ã§ãã¹ã¬ãããã¼ã¹ã®ã»ããã¹ãã¼ã¯ã©ã¤ã¢ã³ãã«å¼·ãã¨ãããã¨ã¯è¨ããã¨æãã¾ãã
puma ã«ãããã¨ã«ãããªã¹ã¯
puma ã¯ã¹ã¬ãããã¼ã¹ã®ãµã¼ãã§ããã¨ãããã¨ã¯ãã¢ããªã±ã¼ã·ã§ã³ã®æ¸ãæ¹ã«ãã£ã¦ã¯ race condition ãå¼ãèµ·ããå¯è½æ§ãããã¾ããæ®éã« Rails ã¢ããªã±ã¼ã·ã§ã³ãæ¸ãã°ã¹ã¬ããã»ã¼ãã«ãªãã¯ãã§ããããã®è¾ºããããããã£ã¦ããªãåå¿è ãå®æã«æãåºãã®ã¯å±éºãªã®ããªã¨æãã¾ãã
ããããããªã人㯠Working With Ruby Threads ãèªã¿ã¾ãããã
unicorn ã®æ¹ãåªã£ã¦ãããã¨ãããã¾ãããã®é ginza.rb 㧠unicorn ã puma ãªã©ã® Rack ãµã¼ãã®ãã³ããã¼ã¯çµæãæ¯è¼ããã¾ãããçµæã¨ãã¦ã¯ã大éã¢ã¯ã»ã¹æã®å¦çã¨ãã¦ã¯ unicorn ã®æ¹ã puma ãããå®å®ãã¦ããå°è±¡ã§ããã
ãpuma ãä¸å®å®ã ãã¨ã¯æããªãã®ã§ãããå®æã«ãherokuãæ¨å¥¨ãã¦ããããããã㯠puma ã ï¼ unicorn ã¯ãªã¯ã³ã³ï¼ãã¨ãªããªãããã«ãªã¹ã¯ã«ã¤ãã¦ãæ¸ãã¦ã¿ã¾ããã
ã¾ã¨ãã¨éæ
åºæ¬çã«ããªãã¼ã¹ãããã·ã®ãªã heroku ã使ãã®ã§ããã°ãç¾æç¹ã§ã¯ puma ãé©ãã¦ããã¨æãã¾ããããããã®å ´åã¯ã¹ã¬ããã»ã¼ããªã³ã¼ããæ¸ãããæ°ãã¤ããªããã°ãªãã¾ããã
ã¾ããheroku 以å¤ã®ç°å¢ã§ã¯ãªãã¼ã¹ãããã·ã使ãããããpuma ã«ãããã¨ã®ã¡ãªããã¯(heroku ã»ã©ã«ã¯)ãªãã¨è¨ãã¾ããã¾ã ã¾ã nginx & unicorn ã®å¤©ä¸ãç¶ãã®ã§ã¯ãªãã§ããããã
ãªãã¼ã¹ãããã·å èµã®ããã»ã¹ãã¼ã¹(ã¹ã¬ãããã¼ã¹ã«ãã§ãã)ã®ãµã¼ãã§ãã raptor (passenger 5) æ£å¼çãããããããªãªã¼ã¹ããã¾ãã以åã® ginza.rb ã§ãã³ããã¼ã¯ãã¨ã£ãæ㯠beta2 ã ã£ãã®ã§ã¾ã ã¾ã ä¸å®å®ãªå°è±¡ã§ããããæ£å¼çã«ãªã£ã¦å®å®ããããheroku ç°å¢ã§ã®éæ¿ãµã¼ãã«ãªãããããã¾ããã
åãæ¥ããã®ããã°(heroku & lokka)ã passenger 5.0.0.rc2 ã«ãã¦ã¿ã¾ãã(注: ã¯ã¦ãªã§ã¯ãªãã以å使ã£ã¦ããããã°ã®æã®è©±ã§ãï¼)ããã®ããã°ã¯ç¹ã«ã¢ã¯ã»ã¹æ°ãå¤ãããã§ã¯ãªãã®ã§é«è² è·æã®å®å®æ§ãªã©ã¯ãããã¾ããããã¨ããããæ®éã«åãã¾ããã