ããã¯ãHaskell Advent Calendar 2021 ã®8æ¥ç®ã®è¨äºã§ãã
Haskellã®ã³ã³ãã¤ã©ã¨ãã¦äºå®ä¸ä¸æã¨ãªã£ãGHCã«ã¯ãã軽éã¹ã¬ããããå®è£ ããã¦ãã¾ãã軽éã¹ã¬ããã¯ããã¤ãã£ãã¹ã¬ããããã軽éãªã¹ã¬ããã§ãä»ã®è¨èªã§ã¯ãã°ãªã¼ã³ã¹ã¬ãããã¨ãå¼ã°ãã¦ãã¾ããHaskellerã並è¡ããã°ã©ãã³ã°ãããã¨ãã¯ã軽éã¹ã¬ãããæ¯ãå¸ããã®ããã«ä½¿ãã¾ãã
è¤æ°ã®è»½éã¹ã¬ããã®å ¥åºåãæããã®ããIOããã¼ã¸ã£ã§ããIOããã¼ã¸ã£ãåãªã軽éã¹ã¬ããã§ãããOSããå ¥åºåã®ã¤ãã³ããåãåããããããã®è»½éã¹ã¬ããã«ã¤ãã³ããéç¥ãã¾ãã
軽éã¹ã¬ãã(ã£ã½ã)æ©è½ãæä¾ããä»ã®è¨èªã§ã¯ãGHCã®IOããã¼ã¸ã£ãåèã«ãã¦ããããã§ããåã¯IOããã¼ã¸ã£ã®éçºã«æ·±ãé¢ãã£ã¦ãã¾ãããã®è¨äºã§ã¯IOããã¼ã¸ã£ã®æ´å²ãã¾ã¨ããã¨ã¨ãã«ã主ã«macOSã§ã®å®è£ ã«é¢ããè¦æ©ãåå¿é²ã¨ãã¦æ®ãã¾ãã
第1ä¸ä»£
- è«æ "Extending the Haskell Foreign Function Interface with Concurrency" ã§è§£èª¬ããã¦ãã¾ãã
- 2005å¹´3æã«ãªãªã¼ã¹ãããGHC 6.4ã§å°å ¥ããã¾ããã
pollã·ã¹ãã ã³ã¼ã«ã使ã£ã¦å®è£ ããã¦ãã¾ããpollã¯ã¤ãã³ãã®ç»é²ã¨ç£è¦ãä¸ä½ã¨ãªã£ãã·ã¹ãã ã³ã¼ã«ã§ãããã®ããããã軽éã¹ã¬ãããæ°ãã«å ¥åºåã®ç»é²ãä¾é ¼ããå ´åã¯ããããã¯ããã¦ããIOããã¼ã¸ã£ãä¸æ¦èµ·ãããªãã¨ããã¾ãã(pollããããããªããã°ãªãã¾ãã)ã
ãããå®ç¾ããããã®ç»æçãªã¢ã¤ãã£ã¢ããwakeupãã¤ãã§ããIOããã¼ã¸ã£ã¯ãç£è¦å¯¾è±¡ã¨ãã¦wakeupãã¤ããæå®ãã¦ãpollãå¼ã³ã¾ãã軽éã¹ã¬ãããwakeupãã¤ãã«ãã¤ãåãæ¸ãè¾¼ãã°ãIOããã¼ã¸ã£ã¯pollããæãããã¨ãã§ããæ°ããªã¤ãã³ããå ãã¦å度pollãå¼ã³åºãã¾ãã
pollã·ã¹ãã ã³ã¼ã«ã®å¼±ç¹ã¯ä»¥ä¸ã®éãã§ãã
- ç»é²ã§ããã¤ãã³ãã®åæ°ã«å¶éãããã
- åãåã£ãã¤ãã³ããç·å½¢æ¢ç´¢ããå¿ è¦ãããã®ã§ãã¤ãã³ãã®åæ°ãå¤ããªãã¨ã¹ã±ã¼ã«ããªãã
第2ä¸ä»£
- è«æ "Scalable Event Handling for GHC" ã§è§£èª¬ããã¦ãã¾ãã
- 2010å¹´11æã«ãªãªã¼ã¹ãããGHC 7.0ã§å°å ¥ããã¾ããã
pollã®åé¡ç¹ãå æããããã«ãLinuxã§ã¯epollãBSDã§ã¯kqueueã使ãããã«ãªãã¾ãããepollãkqueueã¯ãpollã®ã¹ã¼ãã¼ã»ããã¨ããéå®çãªå©ç¨æ¹æ³ãç¨ãããã¦ãã¾ãã
第2ä¸ä»£ã®IOããã¼ã¸ã£ã®æ¬ ç¹ã¯ããã«ãã³ã¢ç°å¢ã§æ§è½ãåºãªããã¨ã§ãããã®çç±ã¨ãã¦ã¯ãã°ãã¼ãã«ããã¯ã使ããã¦ãããã¨ãªã©ãæãããã¾ãã
第3ä¸ä»£
- è«æ "Mio: A High-Performance Multicore IO Manager for GHC" ã§è§£èª¬ãããã¾ãã
- 2014å¹´4æã«ãªãªã¼ã¹ãããGHC 7.8ã§å°å ¥ããã¾ããã
ãã«ãã³ã¢ç°å¢ã§ã§ã¹ã±ã¼ã«ãããããã«ãã°ãã¼ãã«ããã¯ãåå²ãããã¨å ±ã«ãã³ã¢ãã¨ã«IOããã¼ã¸ã£ãèµ·åããããã¨ã«ãªãã¾ããã
ã¾ããããã©ã«ãã§ã¯wakeupãã¤ãã¯å©ç¨ãããªããªãã¾ããããããå®ç¾ã§ããã®ã¯ãepollãkqueueããã¤ãã³ãã®ç»é²ã¨ç£è¦ãç¬ç«ããã¦ããããã§ãããã¨ãã°ãepollã§ã¯ç»é²ãepoll_ctlã§ãç£è¦ã¯epoll_waitã使ãã¾ããIOããã¼ã¸ã£ãepoll_waitã§ãããã¯ããã¦ãã¦ããå¥ã®ã¹ã¬ããã¯epoll_ctlã§ã¤ãã³ããç»é²ã§ããã®ã§ããç»é²ãããã¤ãã³ãã¯åé¤ããªãã¨ããã¾ããããåé¤ã®æéãçãããã«ã使ããããåé¤ããããone shotãã¨ããã¢ã¼ããå©ç¨ããã¦ãã¾ãã
Windows
Windowsã®IOããã¼ã¸ã£ã«é¢ãã¦ã¯è©³ãããªãã®ã§ãNew Windows I/O manager in GHC 8.12ãåç §ãã¦ãã ãããGHC 8.12ã¯ãGHC 9.0ã«ç½®ãæãã¦èªãã§ãã ããã
åå¼ãmacOS
第3ä¸ä»£ã®IOããã¼ã¸ã£ã¯ãAndreas Voellmyãããepollçãéçºããåãkqueueã«ç§»æ¤ãã¾ããããã®ç§»æ¤å¾ãmacOSä¸ã§GHCã®ä¸¦åãã«ãã失æããããã«ãªãã¨ããåé¡ãçºçãã¾ãããBSDã§ã¯åé¡ãªãã®ã«ãmacOSã§ã¯åé¡ãçãã¾ãããã®åé¡ã¯çµå±è§£æ±ºã§ããã«ãmacOSä¸ã§ã¯one shotã¢ã¼ãã諦ãã¦ãwakeupãã¤ãã使ãç¶ããã¨ããæ¹æ³ã§åé¿ããã¾ããã(FreeBSDãªã©ã§ã¯ãone shotã¢ã¼ãã使ããã¦ãã¾ãã)
ãã®å¾ãkqueueã®IOããã¼ã¸ã£ã«æ¸ãè¾¼ã¿ã¤ãã³ãã®ç»é²ã失æããã¨ãããã°ãçºè¦ããã¾ããepoll_ctlã® EPOLLIN
ã EPOLLOUT
ã¯ãã©ã°(ããããã¹ã¯)ã§ãããkqueue ã® EVFILT_READ
㨠EVFILT_WRITE
ã¯ãã©ã°ã§ã¯ããã¾ãããkqueueã§èªã¿æ¸ã両æ¹ãç»é²ããã«ã¯ãèªã¿è¾¼ã¿ã¤ãã³ãã¨æ¸ãè¾¼ã¿ã¤ãã³ãã®2ã¤ãç»é²ããå¿
è¦ãããã¾ãã移æ¤ã®éã«ããã®äºå®ã«æ°ã¥ãããã°ãå
¥ãè¾¼ãã§ãã¾ãããone shotç¨ã®ã³ã¼ãã§ããwakeupãã¤ãç¨ã®ã³ã¼ãã§ãããã®ãã°ã¯ç´ããã¾ãããGHC 8.4ããæ©æµã«ããããã¾ãã
ããã§macOSã®ä¸¦åãã«ãã®åé¡ã解決ããã¨åéããã¦ãmacOSã§one shotã¢ã¼ãã使ããã¨ããææ¡ããã¾ãããããããmacOSã§one shotã使ãããã«ãªã£ãGHC 9.0.1ãmacOSã§ä½¿ã£ã¦ã¿ãã¨ããããã¯ã¼ã¯é¢ä¿ã®ã©ã¤ãã©ãªã§ãã¹ããéããªããªã£ã¦ãã¾ããã
çµå±ãmacOSã®kqueueã«ã¯ãone shotã«ãã°ãããã¨ããã®ãåã®çµè«ã§ããGHC 9.0.2ã§ã¯ãåã³wakeupãã¤ããå©ç¨ãããããã«ãªãã¾ãã