AppEngine/Jã®spin-upãåçã«æ¹åããæ¹æ³
AppEngineã¯ãã¢ã¯ã»ã¹ããã£ãã¨ãã«ã¢ããªã±ã¼ã·ã§ã³ãèµ·åãããã°ããã¢ã¯ã»ã¹ãç¡ããã°ã¢ããªã±ã¼ã·ã§ã³ãçµäºãããã¾ã次ã®ãªã¯ã¨ã¹ãã§åèµ·åããã¨ããä»çµã¿ãå°å
¥ãã¦ãã¾ãã
ãã®ãããã¢ããªã±ã¼ã·ã§ã³ãèµ·å(spin-up)ããæéãã¨ã¦ãéè¦ã«ãªã£ã¦ãã¾ãããã®spin-upã®æéã¯python(webapp)ã§60cpu_ms以ä¸ã(cpu_msã¯cpuã使ãä»®æ³çãªæéã§ããmsã¨åãæãã§æãã¦ããã£ã¦ãã¨ããããã¯å¤§ä¸å¤«ã§ã)Javaã®Servletã ã¨600cpu_msãããã§ããPythonã§ãDjangoãããªå¤§ããªãã¬ã¼ã ã¯ã¼ã¯ã ã¨1000cpu_msããã(ã¢ããªã«ãã)ãããã¾ããã許容ç¯å²å
ãJavaã ã¨Slim3ã§1300cpu_msãSpringã ã¨æ©ãã¦7000cpu_msã¨ããæãã§ãSlim3ãã®ãªã®ãªè¨±å®¹ç¯å²å
ã§ãããããã»ãã¨ãã¯ã1000cpu_msã¯åãããã¨ããã§ãã
AppEngine for Javaã¯spin-upã¨ã®æ¦ãã ã¨è¨ã£ã¦ãè¨ãéãã§ã¯ããã¾ããããããããããéå»ã®è©±ã«ãªãã¾ããã
ãµã¼ãã¼ãµã¤ããã³ãã¬ã¼ãã¨ã³ã¸ã³(JSPã¨ã)ã使ãã®ããããæåã«ãã©ã¦ã¶ã«ã¯HTMLã®ã¢ãã¯ãè¿ããHTMLã®ä¸ã§åçã«å¤æ´ããé¨åã ããAjaxã使ã£ã¦ãµã¼ãã¼ããå¼ã£å¼µã£ã¦ããã®ã§ãã
ãããä»®ã«ãHTML centric pull architecture with Ajaxã¨å¼ãã§ããã¾ããæ¢ã«ç¥ãããå¼ã³æ¹ãããã°å³å¹ã§å¤ããã®ã§èª°ãææãã¦ãã ããã
ä¾ãã°ãæåã«ãã©ã¦ã¶ã¯æ¬¡ã®ãããªindex.htmlã«ã¢ã¯ã»ã¹ãã¾ãã
<body> <span id="ready"></span><br /> <span id="message"></span><br /> <input type="button" value="hello" onclick="$('#message').load('hello');"/> <script src="http://code.jquery.com/jquery-1.4.2.min.js"></script> <script type="text/javascript"> $(function() { $('#ready').load('ready'); }); </script> </body>
scriptã¿ã°ãbodyã®æå¾ã«æã£ã¦ãã¦ããã®ã¯ãJavaScriptã®ãã¼ãã§æç»ãä¸æããªãããã«ããããã§ããããã§(Mockã¨ãªã)HTMLãæåã«æç»ãããã¦ã¼ã¶ã¯ç´ãã«ç»é¢ãè¦ããã¨ãã§ãã¾ãã
åçã«å¤ããé¨åã¯readyã¤ãã³ããclickã¤ãã³ãã§æ¸ãæãã¦ãã¾ãã
readyã¨helloã®URLã«å¯¾å¿ããSlim3ã®Controllerã¯æ¬¡ã®ããã«ãªãã¾ãã
public class ReadyController extends Controller { @Override public Navigation run() throws Exception { response.getWriter().write("Ready"); return null; } }
public class HelloController extends Controller { @Override public Navigation run() throws Exception { response.getWriter().write("Hello"); return null; } }
Viewã§ãµã¼ãã¼ãããã¼ã¿ãå¼ã£å¼µã£ã¦ããã®ã§ãpull architectureã¨å¼ãã§ãã¾ããpullã¨ããè¨ãæ¹ã¯ç¢ºãWebWorkã使ã£ã¦ããæ°ããã¾ãã
AppEngineã§ã¯ãHTMLãstaticãã¡ã¤ã«ã¨ãã¦ç»é²ãã¦ããã¨ãApp Serverã¾ã§å¦çãããããæåã®å°ç¨ã®staticãã¡ã¤ã«ãµã¼ãã¼ã§å¦çãããã®ã§é«éã§ãã(JSPã ã¨staticãã¡ã¤ã«ã¨ãã¦ç»é²ã§ããªã)
å®ã¯ãApp Serverã«å¦çãããããªãã¨spin-upãèµ·ããªãã®ã§ãæåã®HTMLã®æç»ã¯spin-upãªãã§è¡ããã¾ãããããã¡ãã£ã¨ããããªãã¯ã
å®éã®spin-upã¯ãªã¯ã¨ã¹ããReadyControllerã«æ¸¡ã£ãã¨ãã«èµ·ãã¾ãããJSPã使ã£ã¦ããªãã®ã§ãJasperã®åæå(5,600cpu_ms)ãé¿ãããã¨ãã§ãããããHTMLã®æ å ±ãå«ãã§ããªãç´ç²ã«å¿ è¦ãªãã¼ã¿ã®ã¿ãããåããã¦ããã®ã§ãspin-upæéã¯é常ã«çããã®ã«ãªãã¾ãã
AppEngineã®ãã°ã«ããã¨index.htmlã¯0cps_msãReadyControllerã¯spin-upããæã§ã630cpu_ms(ã»ã¼ç´ ã®Servletã¨åæ§)ãããã§å¦çåºæ¥ã¦ãã¾ããèªåã試ããæãã§ã¯ãspin-upããæã¨ãã¦ãªãæã®å·®ã¯å®æãããã¨ãã§ãã¾ãããã»ã¼åãæããããã¯ãããã«æç»ãçµãããéåæã§ãµã¼ãã¼ã«ã¢ã¯ã»ã¹ãã¦ããããã ã¨æãã¾ãã
次ã®URLã§å®éã«è©¦ããã¨ãåºæ¥ã¾ãã
http://test.latest.higayasuo.appspot.com/ajax/index.html
HTMLãæç»ããã¦ããReadyã®æåãåºãã¾ã§è¥å¹²éãããã¾ãããHTMLã¯æ¢ã«æç»æ¸ã¿ãªããã»ã¨ãã©æ°ã«ãªããªãã§ãããã
ããã§å®å ¨ã«AppEngine for Javaã«åã£ãæ°ãããv(o^_^o)v ã¶ãã£
ãã ããã®æ¹æ³ã¯ãèªåããã¹ã¦èããããã§ã¯ãªããå¾æ¥ãããã£ãã®ãã¾ã¨ããã ãã§ããç´ ã®HTML使ã£ã¦Ajax使ãããæ¹ã¯ãappengine ja nightã§å°å·ããããã£ã¦ããã¨æãã¾ããå¾ãã¬ã©ã±ã¼ã§ã¯åºæ¬ä½¿ãã¾ããã