Clojureã®ããããªä¸¦è¡å¦çã®ä½¿ãåã
ãã®è¨äºã¯ãã¨ãã¨Tumblrã«æ¸ãã¦ããèªåã®ããã°è¨äºã転è¼ãããã®ã§ããæ稿æ¥æãå½æã®æ稿æ¥æãåç¾ãã¦ããã¾ãã
Clojureã«ã¯æ¨æºã§ãagentç³»ã®send, send-offã«å ããfutureé¢æ°ã¨ããã¹ã¬ããèµ·åç³»é¢æ°ãããã¾ãã
core.asyncã®ç»å ´ã§ãããã«goãã¯ãã¨threadãã¯ããå ããã¾ããã
ãããã¯ãã¹ã¦ãèå¾ã§ã¯Javaã®Executorsã使ã£ã¦ã¹ã¬ãããã¼ã«ãä½ããä¸åº¦çæããã¹ã¬ããã®åå©ç¨ãè¡ãã¾ããããããã使ã£ã¦ããã¹ã¬ãããã¼ã«ãç°ãªãã¾ããããã«é¢æ°èªä½ã®æ©è½ãç°ãªããããã©ããã¤ãã£ããããã®ãè¿·ã£ã¦ãã¾ããã¨ãããã¾ãã
èªåç¨ã«æ´çããã®ã§ãã¡ã¢ã¨ãã¦ããã¦ããã¾ãã
IOãã¦ã³ãã¨CPUãã¦ã³ã
ã¾ããClojureã®ã¹ã¬ããé¢é£é¢æ°ã®ç¨éã¯ã大ãã2種é¡ã«ããããã¾ããããããIOãã¦ã³ãã¨CPUãã¦ã³ãã§ãã
IOãã¦ã³ããªå¦çã¯ãå®è¡ä¸ã®å¦çãCPUãããIOå¦çã«å¼·ãä¾åãã¾ããDBã¢ã¯ã»ã¹ã¨ããªã¢ã¼ãéä¿¡ã¨ãã§ãããå¥ã¹ã¬ããã§ãã®å¦çãå®è¡ããå ´åãã¹ã¬ããã¯å¤§é¨åããIOå¦çå¾
ã¡ç¶æ
ã§éããã¾ãã
CPUãã¦ã³ããªå¦çã¯ãéä¸ã«IOå¾
ã¡ã®ãããªãå¾
æ©ããçºçãããCPUãã¶ãåãç¶ãããããªå¦çã§ããå
¨ãã¼ã¿ãã¡ã¢ãªã«è¼ã£ã¦ãã¦ãCPUããã«ç¨¼åã§ããããå¦çãããããªã±ã¼ã¹ã§ãã
IOãã¦ã³ããªå¦çã¯å¤§åãIOå¾ ã¡ã§éãããããCPUãå æãã¾ãããä¸æ¹CPUãã¦ã³ããªå¦çã¯ããã®åã®éããåãã¦ããéä¸ãCPUã使ãç¶ãã¾ãã
CPUã使ãç¶ãããããªå¦çã¯ãCPUï¼ã³ã¢ï¼æ°ä»¥ä¸ã®ã¹ã¬ãããèµ·åãã¦ããã¾ãæå³ãããã¾ãããããããã®CPUä¾åå¦çãèµ·åããå ´åãå ¨ã¹ã¬ãããã¿ã¹ã¯å¦çã§CPUãå æãã¦ããã®ããã£ã¨ãå¹çã®è¯ãç¶æ ã§ããã以ä¸èµ·åãã¦ããåã«ã¹ã¬ããåãæ¿ãã³ã¹ããç¡é§ã«ãªãã ãã ããã§ãã CPUãã¦ã³ããªå¦çã¯ãã¹ã¬ããæ°ãã³ã¢æ°ã«è¿ãæ°ã«ã¨ã©ããã²ã¨ã¤ã²ã¨ã¤ã®ã¿ã¹ã¯ã¯å°ãããã¦ãããããã®ã¿ã¹ã¯ãã©ãã©ãã³ã¢ã§åæ£ãã¦å¦çãã¦ããã®ãå¹çããããã¨ã«ãªãã¾ããCPUãã¦ã³ããªå¦çã¯CPUã使ããããªãã®ã ããå¹çè¯ã使ãããããã§ãã
ä¸æ¹ãIOãã¦ã³ããªå¦çã¯ããã®å¤§åã¯ãIOå¾ ã¡ãã ã£ãããã¾ãããªã¢ã¼ãAPIãå¼ã¶å¦çã¯ã大åããã¬ã¹ãã³ã¹ãè¿ã£ã¦ããã®ãå¾ ã¤ããã¨ã«è²»ããã¦ãã¾ãã
ããã§ããããã®IOãã¦ã³ããªå¦çããã³ã¢æ°åã®åºå®æ°ã¹ã¬ããã§å®è¡ãããã¨ãæ³åãã¦ãã ãããã¹ã¬ãããï¼ã¤ã ã¨ãã¦ãï¼ã¤ã®IOå¦çãèµ·åããã¨â¦ãã¹ã¦ã®ã¹ã¬ããã使ããããã以éã®å¦çã¯å¾
ã¤ããããã¾ããã
CPUãã¦ã³ããªå¦çã§ããã°ãã¹ã¬ããã¯CPUããã«ã«ä½¿ã£ã¦ä¸ææ¸å½ã«ã¿ã¹ã¯ãå®è¡ãã¦ãããã¨ã§ããããã ããå¾
ã¤ããããã¾ããããããIOãã¦ã³ããªå¦çã§ã¯ãï¼ã¤ã®ã¹ã¬ããã¯ãããããããã IOå¾
ã¡ããã¦ããã ãã§ãã
ã ãããIOãã¦ã³ããªå¦çã§ã¹ã¬ããæ°ãã³ã¢æ°è¿ãã«éå®ããã®ã¯ããã¾ãæå³ããªãã¨ãããã¨ã«ãªãã¾ããã¹ã¬ãããIOå¾ ã¡ããã¦ããéã«ãã»ãã®å¦çãåãããããããªãã®ã§ããããã ãããã³ã¢æ°ä»¥ä¸ã®ã¹ã¬ãããèµ·åãã¦ãã©ãã©ãIOå¾ ã¡ãããIOãçµãã£ãã¹ã¬ããããå¦çãè¡ãã°ããã®ã§ãã
åºå®æ°ã¹ã¬ãããã¼ã«ã¨ãã£ãã·ã¥åã¹ã¬ãããã¼ã«
Clojureã®é¢æ°ã¯ããã®ç¨éãCPUãã¦ã³ããIOãã¦ã³ããã«ãã£ã¦ã使ç¨ããã¹ã¬ãããã¼ã«ãç°ãªã£ã¦ãã¾ãã
agentå®è¡é¢æ°sendã使ãã¹ã¬ãããã¼ã«ã¯åºå®æ°ã§ãããJavaã®Executors.newFixedThreadPoolã¡ã½ããã§ä½ããã¾ãã
ä¸æ¹ãsend-offã使ãã¹ã¬ãããã¼ã«ã¯ãã£ãã·ã¥åãããéå¶éãã¼ã«ã§ãExecutors.newCachedThreadPoolã§ä½ããã¾ããéå¶éã¨ãã£ã¦ãããã£ãã·ã¥åã¹ã¬ãããã¼ã«ã¯ã使ãããªããªã£ãã¹ã¬ããã60ç§ã§ç ´æ£ããã®ã§ãããããã®ã¹ã¬ãããã´ãã¨ãã¦æ®ããã¨ã¯ããã¾ããã
å¤ãã®Clojureé¢ä¿ã®æ¬ã§ãsendã¯CPUã«ä¾åããå¦çã«ãsend-offã¯IOã«ä¾åããå¦çã«ä½¿ããã¨æ¸ããã¦ããã®ã¯ããã®ããã«ãèå¾ã§ä½¿ã£ã¦ããã¹ã¬ãããã¼ã«ããã¨ãªãããã§ãã
èå¾ã§ä½¿ããã¦ããã¹ã¬ãããã¼ã«ã®ç¨®é¡ããããã°ããã®é¢æ°ããCPUãã¦ã³ããªå¦çãæ³å®ãã¦ããã®ããIOãã¦ã³ããªå¦çãæ³å®ãã¦ããã®ãããããã¾ãã以ä¸ã¯ãClojureã®ãã«ãã¹ã¬ããé¢æ°ãã©ã®ã¹ã¬ãããã¼ã«ã使ã£ã¦ããã®ãã®ä¸è¦§ã§ãã
 | poolã®å®ç¾©å ´æ | ãã¼ã«ã®ç¨®é¡ | ã¹ã¬ãããã¼ã«çææ¹æ³ | ã¹ã¬ããæ° |
---|---|---|---|---|
send | clojure.lang.Agent/pooledExecutor | åºå®æ° | Executors.newFixedThreadPool | 2+ã³ã¢æ° |
send-off | clojure.lang.Agent/soloExecutor | ãã£ãã·ã¥å | Executors.newCachedThreadPool | å¶éãªã |
future / future-call / pmap / pcalls | clojure.lang.Agent/soloExecutor | ãã£ãã·ã¥ | Executors.newCachedThreadPool | å¶éãªã |
go | clojure.core.async.impl.exec.threadpool/the-executor | åºå®æ° | Executors.newFixedThreadPool | ã³ã¢æ° * 2 + 42 |
thread / thread-call | clojure.core.async/thread-macro-executor | ãã£ãã·ã¥ | Executors/newCachedThreadPool | å¶éãªã |
reducers | clojure.core.reducers/pool | ForkJoinPool | new java.util.concurrent.ForkJoinPool | èªåå¶å¾¡ |
futureã®ã¨ããã«ã¯pmapã¨pcallsãæ¸ãã¦ãã¾ãããpcallsã¯pmapããpmapã¯futureãå¼ã³åºãã®ã§ããã¹ã¦futureã¨åãæ±ãã§ãã
ã¾ã¨ãã¦ã¿ãã¨ãcore.asyncã®è§£èª¬ã§å¿ ãåãä¸ããããgoãã¯ãã¯ãåºå®æ°ã®ã¹ã¬ãããã¼ã«ã使ã£ã¦ãããã¨ããããã¾ããã¤ã¾ããgoãã¯ãã¯CPUãã¦ã³ããªå¦çãåæã¨ãã¦ããããã§ãã
goãã¯ãããã³ã¢æ° * 2 + 42ãã¨ããããããããªãã¹ã¬ããæ°ã使ã£ã¦ãããã¨ã«ã¤ãã¦ãç¹ã«42ã¨ããè¬ã®æ°å¤ãæå®ãã¦ãããã¨ã«ã¤ãã¦ã¯ã¯ã£ããããªãã®ã§ããã+42ã¯å¾ããä»ãå ããããããããã¡ã¼ãªã³ã°ãªã¹ãã®ãã¹ããªã©ã追跡ããã¨ãåè¿°ãããIOãã¦ã³ããªå¦çã«åºå®æ°ã¹ã¬ãããã¼ã«ã使ã£ãå ´åã®ãããªãIOå¾ ã¡ã§å ¨ã¹ã¬ãããåæ¢ãã¦ä¸¦è¡å¦çãã¹ã¿ãã¯ãã¦ãã¾ããã¨ãããç¨åº¦ææ¢ããããã¨ããã®ãæå³ã®ããã§ããgoãã¯ãã¯ããã¾ã§CPUãã¦ã³ããªå¦çãæ±ããã®ã§ãããã¨ã¯å¤ãããªãããã§ãã
42ã¨ããæ°å¤ã«ã¤ãã¦ã¯ããã¹ã¦ã®çããããåã£ãã®ã§ã¯ãã¨ãã説ãããã¾ããããã¾ã è¬ã§ããããã¹ã¦ã®çãããã¿ãç¥ããªã人ã¯ã°ã°ã£ã¦ãã ããã
goãCPUãã¦ã³ãã§ãããããã«threadãã¯ããç¨æããã¦ãã¾ãã
threadãã¯ãã¯goãã¯ãã¨ã»ã¼åã使ãåæã§ä½¿ãã¾ããããã£ãã·ã¥åã¹ã¬ãããã¼ã«ã使ããããIOãã¦ã³ããªå¦çã«åãã¦ãã¾ããgoãã¯ãã¨ç°ãªãã¨ããã¯ä¸ç¹ã ãã§ããã£ãã«ã®æä½ã« <! 㨠>! ã¯ä½¿ããããããã¯åã®ãã£ãã«æä½é¢æ° <!! 㨠>!! ã使ããã¨ãããã¨ã§ãã<!!, >!! ã§ã¯å¼ã³åºãã段éã§ã¹ã¬ããããããã¯ãã¾ãããããããthreadã使ã£ãå ´åã¯ãã¤ãã£ãã¹ã¬ããã«å¦çãå²ãå½ã¦ããã¦ãã¦ããã®ã¹ã¬ããããããã¯ããã ããªã®ã§ãã¡ã¤ã³ã¹ã¬ããã¯æ¢ã¾ãããåé¡ããã¾ããã
goãã¯ãã§èµ·åãã並è¡å¦çã¯ãåç´ã«ã²ã¨ã¤ã®ã¹ã¬ããã«ä¸¸ãã¨æ¸¡ãããããã§ã¯ãªããã³ã³ãã¤ã«æ®µéã§å
¨å¦çãå¼åä½ã«å解ãããã¹ãã¼ããã·ã³ã«å¤æããã¾ããSå¼ãªãã§ã¯ã§ããããã¦<!, >!ã§ãã£ãã«ã¸ã®ã¢ã¯ã»ã¹ãã¨ã«ã¹ã¬ãããåãæ¿ãããã¨ãã£ãåããããããã§ãã<!!, >!! ãgoãããã¯ã§ä½¿ãã¨ããã®ã¹ã¬ããåãæ¿ãããã¾ãåããªããªãã®ã§ã>! ã !< ã使ãã¾ãã
å½¼ãã¯ãããIoC Threadã¨èªãã§ãã¾ãããããããããã¯IoCã¨ããããããæã®å調åãã«ãã¿ã¹ã¯ã¨ä¼¼ããã®ã ãããå調åã¹ã¬ãããã¨å¼ã¶ã¹ãã ã¨ããæè¦ãããã¾ããç§ã強調åã ã£ã¦æè¦ã«è³æã§ããããã¶ãIoCã®ã»ãããã£ãããã£ã¦ãã¨ãªãã ã¨æãã¾ãï¼
reducersã ãã¯ç¹æ®ã§ãreducersã¯å é¨ã§ã¯ä¸¦è¡å¦çãJava 7以éã®Fork/Join APIã«å¦çã丸æããã¦ãã¾ãï¼JVMãJava7æªæºã®å ´åã¯äºæã©ã¤ãã©ãªã使ã£ã¦ããããã§ãï¼ãFork/Joinã¯Javaã§ã¯ã¨ã¦ã使ãã«ããAPIã§ãJava 8ã§ã©ã ãå¼ã¨ãã©ã¬ã«ã¹ããªã¼ã ãå°å ¥ããã¦ãã£ã¨æ¬æ°åºããããã«ãªã£ãã®ã§ãããClojureã§ã¯Java 8ããããã£ã¨åã«ãæ©ã ã«å¯¾å¿ãã¦ããããã§ãããã£ã¦æ§è³ªã¨ãã¦ã¯Fork/Joinã¨åçã§ãã¦ãFork/Joinã®ããã¥ã¡ã³ãã«ããã¨ãCPUãã¦ã³ããªå¦çãåæã«ã¹ã¬ããæ°ãèªåå¶å¾¡ããIOãã¦ã³ããªå¦çãæ··ããã¨ãã¾ãèªåå¶å¾¡ã§ããªãããã§ãã
ã¹ã¬ãããã¼ã«ããJava 7ã§Fork/Joinã¨ã¨ãã«å°å
¥ããããForkJoinPoolã使ã£ã¦ãã¾ãããã®ãã¼ã«ã¯ãåæå¤ã¯CPUã³ã¢ã¨åæ°ã®ã¹ã¬ãããç¨æãããã¤ãããã¯ã«ã¯ã¼ã«ã¼ã¹ã¬ããã追å ãããåæ¢ããããã¾ãã
ã¤ã¾ããreducersã¯Fork/Joinã«ãã¹ã¦ãã¾ãããã¨ãããã¨ã§ãã
ããããFork/Joinã¯ãè¦ç´ æ°ãã¨ã¦ãå¤ããã¼ã¿ï¼10ä¸ã¨ã100ä¸ã¨ãï¼ãé«é並åå¦çããããã®APIãªã®ã§ã並ååãç®çãªããæ°åç¨åº¦ã®ä¸¦ååã§ã¯reducersã§ã¯ãªãå¥ã®æ©æ§ãã¤ãã£ãã»ããããã§ããreducersã®æ©è½ã¯ä¸¦ååã ãã§ã¯ãªãã®ã§ããã£ã¡ç®å½ã¦ãªãããã§ããã
ãã¼ã«ã®éã
表ãããè¦ãã¨ãããã¾ãããåãã¹ã¬ããåãã¼ã«ã使ã£ã¦ããé¢æ°ã§ããthreadãã¯ãã ãã¯ããã¼ã«ãç°ãªãã¾ããsend-offã¨futureã¯ãã¨ãã«Clojureæ¨æºé¢æ°ãªã ãã¯ãã£ã¦ã両æ¹ãåãã¹ã¬ãããã¼ã«ã使ã£ã¦ãã¾ããããã¯ã¤ã¾ããsend-offã§çæãããã¹ã¬ããã¯ãfutureã§ãåå©ç¨ã§ãããã¨ãæå³ãã¾ãã
core.async/thread ã¯ãããããcore.asyncèªä½ãClojureã®ãå¤é¨ã©ã¤ãã©ãªããªä½ç½®ã¥ãã§ããããç¬èªã«å®ç¾©ããã¹ã¬ãããã¼ã«ã使ã£ã¦ãã¾ãããã£ã¦ãfutureã¨threadã¨ã¯ãäºãã«çææ¸ã¿ã¹ã¬ãããåå©ç¨ã§ãã¾ãããã¡ãã£ã¨ããå·®ã§ã¯ããã¾ãããå¹ççã§ã¯ãªããã¨ã¯ç¥ã£ã¦ããã¦æã¯ãªãã§ãããã
core.asyncã使ã人ã¯ããããããã¹ã¬ããå¦çã¯core.asyncã°ãã使ãå¾åãããã®ã§ãä»å¾ã¯futureã®ä»£ããã«threadã使ããã¨ã«ããã°è½çãã¨è¡ãããã§ããã両è ã¯æ©è½ã«ãéããããã®ã§ãªããªãããã¯è¡ãã¾ããã
æ©è½ã®éã
- send, send-off (agentç³»ï¼
- future
- go, thread ï¼core.asyncç³»ï¼
ãã®3種é¡ã¯ç¨éããã³ä½¿ãæ¹ãéãã¾ãã
sendã¨send-offãgoã¨threadã¯ãç¨éã¯åãã§ããCPUãã¦ã³ããIOãã¦ã³ãããç°ãªãã¾ãã
futureã¯ã©ã¡ãã«ãå±ãã¾ããã
sendã¨send-offã¯ã©ã¡ãããagentæä½é¢æ°ã§ãããç®çã¯ããã¾ã§agentã®å®è¡ã¨æ´æ°ã§ããããããagentã¯ãæ±ç¨çãªä¸¦è¡å¦çèµ·åã®ããã«ãããã®ã§ã¯ãªããããªãç¹æ®ãªç¨éã§ã¤ãããã®ãªã®ã§ãããã ã¹ã¬ãããèµ·åããããã ãã§ã¯ä½¿ããªãã»ããããã§ãã
agentã®ç¹å¾´ã¯ãåãagentã§èµ·åããå¦çã¯ãé次å®è¡ããããç¹ã§ããåãagentã«ä½åãsend, send-offãã¦ããããããå¹³è¡ã§å¦çãããããã§ã¯ããã¾ãããsendãsend-offã¯agentã®ã¢ã¯ã·ã§ã³å®è¡ãã¥ã¼ã«ã¢ã¯ã·ã§ã³ãç©ãã ãã§ãï¼ãã¡ãããè¤æ°ã®agentãåå¨ããã°ããããã¯å¹³è¡ã«åãã¾ãï¼ãããããagentã¯ãå¤ããæã£ã¦ãã¦ãsendãsend-offã§ç©ãã ã¢ã¯ã·ã§ã³ã«ãã£ã¦ãagentã®çµæå¤ãé çªã«å¤ãã£ã¦ãããã¨ãããã®ã ããã§ãã
goã¨threadã¯agentã«æ¯ã¹ã¦ããæ±ç¨çãªä¸¦è¡å¦çæ©æ§ã§ãgoãthreadãããã¯ã®å¦çã¯ãã¹ã¬ãããã¼ã«ã®éãã¯ãããããã«ã¹ã¬ããã«å²ãå½ã¦ããã¦å¹³è¡ã«åãã¾ãããããã®ãã¯ãããå¦çå®äºæã®çµæå¤ãåãåºãããã£ãã«ãè¿ãã¾ããã¨ããã ãæ¸ãã¨ãthreadã¯futureã¨ä¼¼ã¦ããããã«æãã¾ããã¨ãã«IOãã¦ã³ããªå¦çç¨ã§ãçµæå¤ãåå¾ã§ãããªãã¸ã§ã¯ããè¿ãã¾ããfutureãåæ¥ãã¦ãcore.asyncã«ã移è¡ããã¹ãã§ããããï¼
futureã¯ãå¦çããã£ãã·ã¥åã¹ã¬ãããã¼ã«ã«æ¸¡ãã¦ãããç¹ã§threadã¨åãã§ãããfutureã¯delayãªãã¸ã§ã¯ãã§ãããç¹ã大ããç°ãªãã¾ãã
(let [result1 (future (my-remote-func1 ...)) result2 (future (my-remote-func2 ...))] (my-long-processing-fn) {:age (-> (:base @result1) (+ 20)) :address (str (:address @result1) " " (:address @result2)) :name (:name @result2)})
futureã¯derefï¼ã®çç¥è¨å·ã¢ãããã¼ã¯ï¼ã«ãã£ã¦éåæå¦çã®å®è¡çµæãåå¾ã§ãã¾ãããderefã¯ä½åã§ã使ãã¾ããæåã®derefæã«ã¾ã å¦çãçµãã£ã¦ãªãå ´åã¯å¦çå®äºãå¾ æ©ãã¾ããã以éã¯ããã£ãã·ã¥ããçµæå¤ãè¿ãç¶ãã¾ãã
ä¸è¨ä¾ã§ã¯ãmy-remote-func1ã¨my-remote-func2ã¨ãããªã¢ã¼ãå¼ã³åºããå¹³è¡åããããã«futureã使ããããã«my-long-processing-fnã¨ããé·ãå¦çãè¡ãé¢æ°ãå¼ã³ã¾ãããmy-long-processing-fnå®è¡ä¸ããå¥ã¹ã¬ããã§ãªã¢ã¼ãã³ã¼ã«ã¯å®è¡ããã¦ãã¾ãã
æå¾ã«ããããä½ãã¨ãã«ãfutureã®çµæå¤ãåç
§ãã¦ãã¾ãããresult1ãresult2ãã2ååç
§ãã¦ããç¹ã«æ³¨ç®ãã¦ãã ããã
threadãã¯ãã¯delayãªãã¸ã§ã¯ãã§ã¯ãªãããã£ãã«ãè¿ãã¾ãã(<!! ch) ã«ãã£ã¦çµæå¤ãåãåºãã¾ãããderefã¨éã£ã¦ã<!!ãç¹°ãè¿ãèªãã§ãåãçµæãè¿ã£ã¦ããããã§ã¯ããã¾ããããã£ãã«ã¯ãã¥ã¼ã®ä¸ç¨®ã§ããã£ãã«ã¸ã® <!! ã¯å¼ã¶ãã³ã«æ°ããå¤ãè¿ããå¤ããªããªãã¨nilãè¿ãã®ã§ããã£ãã«ããdelayã®ããã«ç¹°ãè¿ãåç §ãã¹ãã§ã¯ããã¾ããã
(let [ch1 (thread (my-remote-func1 ...)) ch2 (thread (my-remote-func2 ...))] (my-long-processing-fn) (let [result1 (<!! ch1) result2 (<!! ch2)] {:age (-> (:base result1) (+ 20)) :address (str (:address result1) " " (:address result2)) :name (:name result2)}))
ãã£ãã«ãã¼ã¹ã®threadããfutureã®ä»£ç¨ã¨ãã¦ä½¿ãå ´åã¯ãletã使ã£ã¦ãã£ãã«ãããã£ããå¤ãåãåºããªããã°ãããªãç¹ã§ã使ãåæãç°ãªã£ã¦ãã¾ãã
ãã¡ãããããå
ããªå·®ã§ãããgo/threadã«ã¯ãè¤æ°ã®go/threadãããã¯ãå
±éã®ï¼ãããããããã®ï¼ãã£ãã«ãä»ãã¦å¤ãããåããã¤ã¤ä¸¦è¡å¦çãå®è¡ããã¨ããæ¬æ¥ã®ç®çãããã¾ãããã価å¤ã¯ãããããæ¸ãã¾ãããããã§è¨ãããã®ã¯ãthreadã¯goã®IOãã¦ã³ãçã§ãã£ã¦ãå
¨ä¸¦è¡å¦çãcore.asyncåãããã¨ãã¦ãfutureã®ãããã«threadã使ããã¨ããã®ã¯ãã¢ãªã§ã¯ããã¾ãããè¥å¹²ç絡çã§ãã
core.asyncã®ãã¯ã¼ã¯ãgoãããã¯threadãããã¯ãè¤æ°åèµ·åãã¦ãã¦ãäºãã«ï¼ãã£ãã«ãä»ãã¦ï¼éä¿¡ãããæã«çºæ®ããã¾ãããã¡ããã常ã«çµæãã£ãã«ãè¿ãç¹ã§æ±ç¨çãªã¹ã¬ããèµ·åã®ä»çµã¿ã¨ãã¦ä½¿ããã¨ãé
æ
®ããã¦ãã¾ãããä¸è¨ã®ãããªéããæèãã¦ãããã»ããããã§ãããããã®ä¾ã®ããã«ãè¤æ°ã®futureã§ããã¤ãã®ä¸¦åå¦çãèµ·åãã¦ããã¨ã§ãã®çµæå¤ã使ãå ´åãthreadã®å ´åã¯ãé·ãletå¼ã§ãã£ãããã£ãã«ããªã¼ãããå¿
è¦ãããããããã¾ããã
ä¸æ¹ã§ãfutureã¨threadã¯ä½¿ç¨ããã¹ã¬ãããã¼ã«ãç°ãªãã®ã§ãä½µç¨ããã¨ãäºãã«ã¹ã¬ãããå ±æãã¦ããã¾ãããfutureå士ã¯ã¹ã¬ãããå ±æãã¾ãããthreadå士ãå ±æãã¾ãããfutureã¨threadã¯å ±æãã¾ãããããã«è¥å¹²ã®ãã¹ãåå¨ãã¾ãã
ãã£ã¦ãç¨éã«åããã¦futureã¨threadã¨ä½¿ãåãããããããã¯ã¹ã¬ãããã¼ã«ã®å¹çæ§ãèãã¦çæ¹ã«å¯ãããï¼ãã¯ã¼ãèããã¨threadã®æ¹ãå¼·åãªã®ã§ããµã¤ãã¯threadã«å¯ããã§ãããï¼ã¯ãæ£ç´ã好ã¿ã®æ¬¡ç¬¬ã§ããå®ãè¨ãã¨ãç§ã¯futureã使ãã·ã¼ã³ã§ãthreadã使ããã¨ãã»ã¨ãã©ã§ãã好ã¿ã®åé¡ã§ãã
ã¾ã¨ã
- agentã¯åãªã並åå¦çèµ·åç¨ã®æ©è½ã§ã¯ãªãã®ã§ãã¡ãã£ã¨èãã¦ä½¿ã
- reducersã¯ãããéã®ãã¼ã¿ãå¦çã§ãããªãéãã並ååæ©æ§ã ã¨æããªã
- ãã¾ããããå¦çãCPUãã¦ã³ããIOãã¦ã³ããã¯ã¡ããã¨èãã
- futureã«ã¯ã¡ããã¨futureã«åããå¦çãããããã©ããã¦threadã§ä»£ç¨ãåºæ¥ãããã®å ´åãä»ã®ä¸¦åå¦çããªãã¹ãcore.asyncã使ãããã«ããã°ãã¹ã¬ãããã¼ã«ã®ãã£ãã·ã¥å¹çã¯è¥å¹²è¯ãã