èè ã«ã€ããŠïŒSaç°æµ©äžã¯Herokuã§åããNobuãšMatzãã«ããŒã®ã³ã¢ã«ããŠããŸãã YARV ãRuby 2.1çšã®äžä»£å¥ã¬ããŒãžã³ã¬ã¯ã¿ãŒïŒRgenGCïŒãããã³ruby 2.2çšã®ã€ã³ã¯ãªã¡ã³ã¿ã«GCãšãã®èšäºãå·çããŸããã
åæ
Rubyã¯GCã䜿çšããŠæªäœ¿çšã®ãªããžã§ã¯ããèªåçã«åéããŸãã ã¬ããŒãžã³ã¬ã¯ã¿ãŒã®ãããã§ãRubyããã°ã©ããŒã¯ãªããžã§ã¯ããæåã§åé€ããå¿ èŠããªãããã®ãããªåé€ã®ãã°ãå¿é ããå¿ èŠããããŸããã
Rubyã®æåã®ããŒãžã§ã³ã§ã¯ããã§ã«ããŒã¯ã¢ã³ãã¹ã€ãŒãïŒMïŒSïŒã¢ã«ãŽãªãºã ã䜿çšãããŠããŸããã MïŒSã¯æãåçŽãªGCã¢ã«ãŽãªãºã ã®1ã€ã§ããã2ã€ã®æ®µéã§æ§æãããŠããŸãã
1.ããŒã¯ïŒãã¹ãŠã®çããŠãããªããžã§ã¯ãã調ã¹ãŠããããããçããŠãããªããžã§ã¯ãããšããŠããŒã¯ããŸã
2.ã¹ã€ãŒãïŒã©ãã«ãä»ããŠããªããªããžã§ã¯ãã¯äœ¿çšãããªããªã£ãããããã¹ãŠå»æ£ããŸãã
MïŒSã¯ãçããŠãããªããžã§ã¯ãã®äžããèŠã€ãã£ããã¹ãŠã®ãªããžã§ã¯ããçããŠãããªããžã§ã¯ãã§ãããšããç¥èã«åºã¥ããŠããŸãã MïŒSã¢ã«ãŽãªãºã ã¯éåžžã«åçŽã§ãããããéåžžã«ããŸãæ©èœããŸãã
ããŒã¯ïŒã¹ã€ãŒãGCã¢ã«ãŽãªãºã
ãã®åçŽã§å¹ççãªã¢ã«ãŽãªãºã ïŒããã³ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã®ä¿å®çãªæ¹æ³ïŒã«ãããCã§ã®æ¡åŒµæ©èœã®èšè¿°ãéåžžã«ç°¡åã«ãªããŸãã ãã®çµæãRubyã«ã¯å€ãã®äŸ¿å©ãªæ¡åŒµæ©èœããããŸãã ãã ãããã®ã¢ã«ãŽãªãºã ã®ãããå§çž®ãã³ããŒãªã©ã®ç§»åGCã¢ã«ãŽãªãºã ãé©çšããããšã¯å°é£ã§ãã
Cæ¡åŒµãèšè¿°ããããšã¯ãFFIïŒå€éšé¢æ°ã€ã³ã¿ãŒãã§ã€ã¹ïŒã䜿çšã§ãããããçŸæç¹ã§ã¯ããã»ã©éèŠã§ã¯ãããŸããã ããããæåã¯ãå€æ°ã®æ¡åŒµæ©èœãæã¡ãCæ¡åŒµæ©èœãä»ããŠå€ãã®æ©èœãæäŸããããšã¯å€§ããªå©ç¹ã§ãããRubyã€ã³ã¿ãŒããªã¿ãŒã®äººæ°ãé«ãŸããŸããã
MïŒSã¢ã«ãŽãªãºã ã¯ã·ã³ãã«ã§åªããåäœããããšããäºå®ã«ãããããããããã€ãã®åé¡ããããŸãã æãéèŠãªæœåšçãªåé¡ã¯ãã¹ã«ãŒããããšäžæåæ¢æéã§ãã GCã¯ãã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã®ãªãŒããŒãããã®ããã«Rubyããã°ã©ã ãé ãããŸãã ã€ãŸããGCã®ããã©ãŒãã³ã¹ãäœããšãã¢ããªã±ãŒã·ã§ã³ã®åèšå®è¡æéãé·ããªããŸãã åã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã¯ã¢ããªã±ãŒã·ã§ã³ãäžæåæ¢ããŸãã é·ãäžæåæ¢ã¯ãUI / UX Webã¢ããªã±ãŒã·ã§ã³ã«åœ±é¿ããŸãã
ããã©ãŒãã³ã¹ã®åé¡ã解決ããããã«ãRuby 2.1ã§ã¯äžä»£å¥GCã¬ããŒãžã³ã¬ã¯ã¿ãŒãå°å ¥ãããŸããã äžä»£å¥GCã¯ãããŒãã¹ããŒã¹ãããã€ãã®äžä»£ã®ããã€ãã®éšåã«åå²ããŸãïŒRubyã§ã¯ãããŒãã¹ããŒã¹ãè¥ãã¹ããŒã¹ãšå€ãã¹ããŒã¹ã«åå²ããŸãïŒã æ°ããäœæããããªããžã§ã¯ãã¯ãè¥ãã¹ããŒã¹ãã«é 眮ãããããã«å¿ããŠãè¥ããªããžã§ã¯ãããšããŠããŒã¯ãããŸãã è¥ããªããžã§ã¯ããããã€ãã®ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ïŒRuby 2.2ã§ã¯3ã€ïŒãçãæ®ã£ãåŸããããã¯ãå€ããªããžã§ã¯ããã®ã«ããŽãªã«å ¥ãããå€ãã¹ããŒã¹ãã«çœ®ãããŸãã ãªããžã§ã¯ãæåããã°ã©ãã³ã°ã§ã¯ãã»ãšãã©ã®ãªããžã§ã¯ããè¥ãããŠæ»ã¬ããšãç¥ã£ãŠããŸãã ãããã£ãŠãã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãéå§ããå¿ èŠãããã®ã¯ãè¥ãã¹ããŒã¹ãã®ã¿ã§ãã è¥ãã¹ããŒã¹ã«ãªããžã§ã¯ããäœæããã®ã«ååãªã¹ããŒã¹ããªãå Žåããå€ãã¹ããŒã¹ãã®ã¬ããŒãžã³ã¬ã¯ã¿ãŒãèµ·åããŸãã ã¬ããŒãžã³ã¬ã¯ã¿ãŒãè¥ãã¹ããŒã¹ã§åäœããå Žåã¯ããã€ããŒGCãããã¹ãŠã®ãŠãŒã¶ãŒïŒè¥ãã¹ããŒã¹ãšå€ãã¹ããŒã¹ã®äž¡æ¹ïŒã«å¯ŸããŠã¯ãã¡ãžã£ãŒGCããšåŒã³ãŸãã äžä»£å¥GCã¢ã«ãŽãªãºã ã«ããã€ãã®ä¿®æ£ãå ããŠå®è£ ããã¢ã«ãŽãªãºã ãšã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã®å®è£ ããRGenGCããšåä»ããŸããã EuRuKoã§ã®ãã¬ãŒã³ããŒã·ã§ã³ãšã¹ã©ã€ããèŠãŠã詳现ã確èªã§ããŸãã
RGenGCã¯ãéåžžã«é«éãªãã€ããŒGCã«ãããã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã®ããã©ãŒãã³ã¹ãå€§å¹ ã«åäžãããŸãã Major GCã¯ããã°ã©ã ãé·æéäžæåæ¢ããŸããããã®æéã¯Ruby 2.0以åã®ããŒãžã§ã³ã®äžæåæ¢ã®é·ããšåãã§ãã ã»ãšãã©ã®ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã¯ããã€ããŒGCã«ãã£ãŠå®è¡ãããŸãã
ã¡ãžã£ãŒGCããã³ãã€ããŒGCã§ã®äžæåæ¢
é·ãäžæåæ¢ã®åé¡ã解決ããã«ã¯ãå¢åã¬ããŒãžã³ã¬ã¯ã¿ãŒãæé©ã§ãã
å¢åã¬ããŒãžã³ã¬ã¯ã·ã§ã³
ã€ã³ã¯ãªã¡ã³ã¿ã«ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã¢ã«ãŽãªãºã ã¯ããã«ãããã»ã¹èªäœãããã€ãã®å°ããªããã»ã¹ã«åå²ããGCããã»ã¹ãšRubyããã»ã¹ã亀äºã«åãæ¿ããŸãã å¢åã¬ããŒãžã³ã¬ã¯ã¿ãŒã¯ãé·ãäžæåæ¢ã®ä»£ããã«ãå€ãã®çãäžæåæ¢ãçæããŸãã äžæåæ¢ã®åèšæéã¯åããŸãŸã§ããïŒå¢åã¬ããŒãžã³ã¬ã¯ã¿ãŒã䜿çšããå Žåã®ãªãŒããŒãããã®ããã«å°ãé·ããªããŸãïŒãåã ã®äžæåæ¢ã¯çããªããŸãã ããã«ãããããã©ãŒãã³ã¹ãããå®å®ããŸãã
Ruby 1.9.3ã¯ããé 延ã¹ã€ãŒããGCãå°å ¥ããŸãããããã¯ãã¹ã€ãŒããã§ãŒãºã§ã®äžæåæ¢æéãççž®ããŸãã ã¬ã€ãºã¹ã€ãŒãã®æå³ã¯ãã¹ã€ãŒããã§ãŒãºãããã«ã§ã¯ãªãã段éçã«éå§ããããšã§ãã ã¬ã€ãžãŒã¹ã€ãŒãã¯ãåã ã®äžæåæ¢ã®æéãççž®ããã€ã³ã¯ãªã¡ã³ã¿ã«GCã¢ã«ãŽãªãºã ã®ååã§ãã 次ã«ãã¡ãžã£ãŒGCã®äœæ¥æ®µéãã€ã³ã¯ãªã¡ã³ã¿ã«ã«ããå¿ èŠããããŸãã
ãªããžã§ã¯ãã®ã€ã³ã¯ãªã¡ã³ã¿ã«ããŒãã³ã°ã®ããã»ã¹ã説æãã3ã€ã®æŠå¿µã玹ä»ããŸãããçœããªããžã§ã¯ãã-ã©ãã«ã®ãªããªããžã§ã¯ãããç°è²ã®ãªããžã§ã¯ãã-ã©ãã«ãä»ããŠããŸãããçœããªããžã§ã¯ãããé»ããªããžã§ã¯ãããåç §ã§ããŸã-ããŒã¯ãããŠããŸãããçœããªããžã§ã¯ãã瀺ããŠããŸããã
ãããã®3è²ã䜿çšããŠããããŒã¯ã¢ã³ãã¹ã€ãŒããã¢ã«ãŽãªãºã ã次ã®ããã«èª¬æã§ããŸãã
1.ãã¹ãŠã®æ¢åã®ãªããžã§ã¯ãã¯çœãšããŠããŒã¯ãããŸã
2.ã¹ã¿ãã¯äžã®ãªããžã§ã¯ããªã©ã®æ瀺çãªã©ã€ããªããžã§ã¯ãã¯ãç°è²ã§ããŒã¯ãããŸãã
3.ç°è²ã®ãªããžã§ã¯ããéžæãããããåç §ãããªããžã§ã¯ããç°è²ã«ããŒã¯ããŸãã å ã®ãªããžã§ã¯ãã®è²ãé»ã«å€æŽããŸãã ç°è²ã®ãªããžã§ã¯ãããªããªããŸã§ç¹°ãè¿ããŸãããçœé»ã®ãªããžã§ã¯ãã®ã¿ã§ãã
4.ãã¹ãŠã®çããŠãããªããžã§ã¯ãã¯é»ãå¡ãããŠãããããçœããªããžã§ã¯ããåéããŸãã
ããã»ã¹å šäœãã€ã³ã¯ãªã¡ã³ã¿ã«ã«ããã«ã¯ãã¹ãããïŒ3ïŒãã€ã³ã¯ãªã¡ã³ã¿ã«ã«ããå¿ èŠããããŸãã èšç»ã¯æ¬¡ã®ãšããã§ããç°è²ã®ãªããžã§ã¯ããéžæããããããåç §ãããªããžã§ã¯ããã°ã¬ãŒã¢ãŠãããŠãããRubyã³ãŒãã®å®è¡ã«åãæ¿ããã¿ã°ä»ãããã»ã¹ãªã©ã«æ»ããŸãã
éåžžã®ããŒãã³ã°ããã»ã¹ïŒSTWïŒäžçãæ¢ããïŒå¯Ÿå¢å
ãªããžã§ã¯ãã®å¢åããŒãã³ã°ããã»ã¹ã«ã¯1ã€ã®åé¡ããããŸãã é»ã®ãªããžã§ã¯ãã¯ãã«ããŒã³ãŒãã®å®è¡äžã«çœãæãããšãã§ããŸãã å®çŸ©äžãé»ããªããžã§ã¯ãã¯çœããªããžã§ã¯ããåç §ã§ããªããããããã¯åé¡ã§ãã ãããé²ãããã«ããæžã蟌ã¿ããªã¢ãã䜿çšããŠãé»ã®ãªããžã§ã¯ãããçœãžã®ãªã³ã¯ã®äœæãæ€åºããŸãã
ããšãã°ãé åãªããžã§ã¯ããaryãã¯ãã§ã«é»ãšããŠããŒã¯ãããŠããŸãã
ary = [] # GC
ãã®ã³ãŒããå®è¡ãããšããªããžã§ã¯ããobj = Object.newãã¯çœã«ãªããŸãã
ary << obj # obj GC
ããã§ãé»ããªããžã§ã¯ãã¯çœããªããžã§ã¯ããåç §ããŸãã ãobjããåç §ããç°è²ã®ãªããžã§ã¯ãããªãå Žåããobjãã¯ãªããžã§ã¯ããããŒã¯ãã段éã®æåŸã§çœã«ãªãããããã£ãŠèª€ã£ãŠå»æ£ãããŸãã ãã¹ãŠã®çããŠãããªããžã§ã¯ããåéããããšã¯é倧ãªééãã§ãããé¿ããå¿ èŠããããŸãã
ãªããžã§ã¯ããæ°ãããªããžã§ã¯ãã®åç §ãéå§ãããã³ã«ãæžã蟌ã¿ããªã¢ãåŒã³åºãããŸãã èšé²ããªã¢ã¯ãé»ããªããžã§ã¯ãããçœãžã®ãªã³ã¯ããã€äœæããããã決å®ããŸãã ãããçºçãããšãé»ã®ãªããžã§ã¯ãã®è²ãã°ã¬ãŒïŒãŸãã¯çœã®ãªããžã§ã¯ããžã®ãã€ã³ã¿ãŒãå«ãã°ã¬ãŒïŒã«å€ãããŸãã èšé²éå£ã¯ããã¹ãŠã®çãç©ãåéããåé¡ãå®å šã«è§£æ±ºããŸãã
ãããã€ã³ã¯ãªã¡ã³ã¿ã«ã¢ã«ãŽãªãºã ã®äž»ãªæå³ã§ãã ã芧ã®ãšãããããã¯ããã»ã©é£ãããããŸããã ããªãã¯è³ªåããããããããŸããïŒããªãRubyã¯ãŸã ãã®åçŽãªGCã¢ã«ãŽãªãºã ã䜿çšããŠããªãã®ã§ããïŒã
Ruby 2.2ã®ã€ã³ã¯ãªã¡ã³ã¿ã«ã¬ããŒãžã³ã¬ã¯ã¿ãŒ
Rubyã€ã³ã¿ãŒããªã¿ãŒïŒCRubyïŒã§ã€ã³ã¯ãªã¡ã³ã¿ã«ã¿ã°ä»ãããã»ã¹ãå®è£ ãããšãæ·±å»ãªåé¡ãçºçããŸã-æžã蟌ã¿ããªã¢ã®æ¬ åŠã
Ruby 2.1ã§å®è£ ãããäžä»£å¥GCã«ã¯ãæžã蟌ã¿ããªã¢ãå¿ èŠã§ããã äžä»£å¥GCãå®è£ ããããã«ããæžã蟌ã¿ããªã¢ãä¿è·ãããŠããªããªããžã§ã¯ãããšããæ°ããã¡ãœãããçºæããŸããã ããã¯ããã¹ãŠã®ãªããžã§ã¯ããä¿è·å¯Ÿè±¡ãšéä¿è·å¯Ÿè±¡ã«åå²ããããšãæå³ããŸãã ãã®ããã«ããŠãåç §ãããŠãããã¹ãŠã®ä¿è·ãªããžã§ã¯ããå¶åŸ¡äžã«ããããšãä¿èšŒã§ããŸãã å®å šã§ãªããªããžã§ã¯ããããªã³ã¯ãå¶åŸ¡ããããšã¯ã§ããŸããã ä¿è·ãããŠããªããªããžã§ã¯ãã®æŠå¿µã®å°å ¥ã«ãããRuby 2.1ã§äžä»£å¥GCãå®è£ ã§ããŸãã
å®å šã§ãªããªããžã§ã¯ãã䜿çšããŠã€ã³ã¯ãªã¡ã³ã¿ã«GCãé©åã«å®è£ ããããšãã§ããŸãã
1.æ¢åã®ãã¹ãŠã®ãªããžã§ã¯ããçœã§è²ä»ããã
2.ã¹ã¿ãã¯äžã®ãªããžã§ã¯ããå«ãããã¹ãŠã®æ確ã«çããŠãããªããžã§ã¯ããã°ã¬ãŒã§è²ä»ãããŸã
3. 1ã€ã®ç°è²ã®ãªããžã§ã¯ããååŸãããããåç §ãããã¹ãŠã®ãªããžã§ã¯ããç°è²ã§ãã€ã³ãããŸãã è²ãé»ã«å€æŽããŸãã ç°è²ã®ãªããžã§ã¯ãããªããªããŸã§ç¹°ãè¿ããŸãã çœé»ã®ã¿ã ãã®ãã§ãŒãºã¯æ®µéçã«å®è¡ãããŸãã
4.çœããªããžã§ã¯ããåéããŸãã ãã¹ãŠã®çãç©ã¯é»ã§ã
ãã®ãããçœãçãç©ããªãããšãä¿èšŒã§ããŸãã
ä¿è·ãããŠããªããªããžã§ã¯ãã®æžã蟌ã¿ããªã¢ããã®åã¹ãã£ã³ïŒWB unpãïŒã¿ã°ä»ãããã»ã¹ã®çµäºæ
æ®å¿µãªããã第4段éã§ã¯é·ãäŒæ¢ãçºçããå¯èœæ§ããããããåé¿ããããšèããŠããŸãã ãã ããåèšäžæåæ¢æéã¯ãä¿è·ãããŠããªãã©ã€ããªããžã§ã¯ãã®èšé²ããªã¢ã®æ°ã«é¢é£ä»ããããŠããŸãã Rubyã®ã»ãšãã©ã®ãªããžã§ã¯ãã¯ãæååãé åãããã·ã¥ããŸãã¯ããã°ã©ããŒã«ãã£ãŠäœæãããåçŽãªïŒçŽç²ãªïŒãªããžã§ã¯ãã§ãã ãããã¯ä¿è·ããããªããžã§ã¯ãã§ãã å®éã«ã¯ãã»ãšãã©ã®å Žåãä¿è·ãããŠããªããªããžã§ã¯ãã®èšé²ã«å¯Ÿããéå£ã®äžæåæ¢ã¯åé¡ãåŒãèµ·ãããŸããã
次ã®ããã«ãã¡ãžã£ãŒGCã«å¯ŸããŠã®ã¿å¢åã¿ã°ä»ãããã»ã¹ãè¡ããŸããã ãã€ããŒGCã®äžæåæ¢ã«ã€ããŠæå¥ãèšã人ã¯ããŸããã ã€ã³ã¯ãªã¡ã³ã¿ã«GCã®æ倧äŒæ¢æéã¯ããã€ããŒGCãããçããªããŸãã ãã€ããŒGCã®ãã¬ãŒã¯ã¿ã€ã ã«æºè¶³ããŠããå Žåãã¡ãžã£ãŒGCã®ãã¬ãŒã¯ã¿ã€ã ã«ã€ããŠå¿é ããå¿ èŠã¯ãããŸããã
ãŸããRubyã§ã€ã³ã¯ãªã¡ã³ã¿ã«GCãå®è£ ããããã®ããªãã¯ãé©çšããŸããã ãé»ããŠå®å šã§ãªãããªããžã§ã¯ãã®ã»ããããããŸãã ã¬ããŒãžã³ã¬ã¯ã¿ãŒãè¿ éã«åäœãããããã«ãä¿è·ãããŠããªããªããžã§ã¯ãã§ãããå®å šã§ãªãããããããããšãããŒã¯ããããªããžã§ã¯ãã瀺ãå¥ã®ãã¿ã°ä»ãããããããããäœæããŸããã è«çç©ã䜿çšãããšããé»ããŠå®å šã§ãªãããªããžã§ã¯ããèŠã€ããããšãã§ããŸãã
GCã®äžæåæ¢æéã®å¢åæšå®
ã¬ããŒãžã³ã¬ã¯ã·ã§ã³äžã®äžæåæ¢ã®æéã枬å®ããããã«ã gc_tracerã䜿çšããŸã ã Gc_tracerã«ã¯GCïŒTracerã¢ãžã¥ãŒã«ããããã¬ããŒãžã³ã¬ã¯ã·ã§ã³ããã»ã¹ã«é¢é£ãããã©ã¡ãŒã¿ãŒã远跡ã§ããŸãã gc_tracerã¯ããã®ãããªåãã©ã¡ãŒã¿ãŒããã¡ã€ã«ã«åºåããŸãã
ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã«ã¯ã次ã®ã€ãã³ããå«ãŸããŸãã
å§ãã
end_mark
end_sweep
newobj
freeobj
å ¥ã
åºã
åè¿°ããããã«ãRubyã®GCã«ã¯ãããŒã¯ããšãã¹ã€ãŒããã®2ã€ã®ãã§ãŒãºããããŸãã ãéå§ãã€ãã³ãã¯ããŒã¯ãã§ãŒãºã®éå§ãæå³ãããend_markãã¯ãã®å®äºãæå³ããŸãã end_markã€ãã³ãã¯ãã¹ã€ãŒããã§ãŒãºã®éå§ãããŒã¯ããŸãã æããã«ããend_sweepãã¯ã¹ã€ãŒããã§ãŒãºã®çµäºã瀺ããã¬ããŒãžã³ã¬ã¯ã·ã§ã³ããã»ã¹ã®å®äºãæå³ããŸãã
ãNewobjããšãfreeobjãã¯ããªããžã§ã¯ãã«ã¡ã¢ãªãå²ãåœãŠãŠè§£æŸãããšãã®ã€ãã³ãã§ãã
ãenterãã€ãã³ããšãexitãã€ãã³ãã䜿çšããŠãäžæåæ¢ã®æéã枬å®ããŸãã ã€ã³ã¯ãªã¡ã³ã¿ã«GCïŒã€ã³ã¯ãªã¡ã³ã¿ã«ããŒãã³ã°ãšã¬ã€ãžãŒã¹ã€ãŒãïŒã¯ãããŒã¯ãã§ãŒãºãšã¹ã€ãŒããã§ãŒãºã®äžæã䜿çšããŸãã ãEnterãã¯ãGCé¢é£ã€ãã³ãã®å ¥åããæå³ããŸãã æåŸã«ããçµäºãã¯ãGCé¢é£ã€ãã³ããçµäºãããããšãæå³ããŸã
次ã®å³ã¯ãçŸåšã®ã€ã³ã¯ãªã¡ã³ã¿ã«GCã§ã®ã€ãã³ãã®çµæçãªååžã瀺ããŠããŸãã
åã€ãã³ãã®çŸåšã®æéã枬å®ã§ããŸãïŒLinuxã§ã¯ãçŸåšã®æéã¯gettimeofdayïŒïŒãåŒã³åºããçµæã§ãïŒã ãããã£ãŠãã€ãã³ããenterãããã³ãexitãã䜿çšããŠãGCã§äžæåæ¢ã®æéã枬å®ã§ããŸãã
ko1-test-appã䜿çšããŠããã©ãŒãã³ã¹ãæ¯èŒããŸãã ko1-test-appã¯ãAaron Pattersonã«ãã£ãŠæžãããã·ã³ãã«ãªRailsã¢ããªã±ãŒã·ã§ã³ã§ãã
gc_tracerãžã£ã ã䜿çšããããã«ãã¬ãŒãã«ãŒã«ãtest_gc_tracerããè¿œå ããŸããã
diff --git a/perf.rake b/perf.rake index f336e33..7f4f1bd 100644 --- a/perf.rake +++ b/perf.rake @@ -54,7 +54,7 @@ def do_test_task app body.close end -task :test do +def test_run app = Ko1TestApp::Application.instance app.app @@ -67,6 +67,22 @@ task :test do } end +task :test do + test_run +end + +task :test_gc_tracer do + require 'gc_tracer' + require 'pp' + pp GC.stat + file = "log.#{Process.pid}" + GC::Tracer.start_logging(file, events: %i(enter exit), gc_stat: false) do + test_run + end + pp GC.stat + puts "GC tracer log: #{file}" +end + task :once do app = Ko1TestApp::Application.instance app.app
ãããŠã ãã³ãã«exec rake test_gc_tracer KO1TEST_CNT = 30000ãå®è¡ããŸãã ã 30000ã®å€ã¯ã30,000ã®ãªã¯ãšã¹ããã·ãã¥ã¬ãŒãããããšãæå³ããŸãã çµæã¯log.xxxxãã¡ã€ã«ã«æžã蟌ãŸããŸããããã§ãxxxxã¯ã¢ããªã±ãŒã·ã§ã³ããã»ã¹ã®IDã§ãã ãã¡ã€ã«ã¯æ¬¡ã®ããã«ãªããŸãã
type tick major_by gc_by have_finalizer immediate_sweep state enter 1419489706840147 0 newobj 0 0 sweeping exit 1419489706840157 0 newobj 0 0 sweeping enter 1419489706840184 0 newobj 0 0 sweeping exit 1419489706840195 0 newobj 0 0 sweeping enter 1419489706840306 0 newobj 0 0 sweeping exit 1419489706840313 0 newobj 0 0 sweeping enter 1419489706840612 0 newobj 0 0 sweeping ...
ç§ã®ãã¡ã€ã«ã«ã¯1,142,907è¡ãããŸãã
ãã¿ã€ããåã«ã¯ãã€ãã³ãã®ååããã£ãã¯ããå«ãŸããŠããŸã-çŸåšã®æå»ïŒgettimeofdayïŒïŒçµæãå å·ããã®ãã€ã¯ãç§æ°ïŒã ãã®æ å ±ã䜿çšããŠãäžæåæ¢ã®é·ãã確èªã§ããŸãã äžèšã®æåã®2è¡ã䜿çšããŠãäžæåæ¢ã®é·ãã枬å®ã§ããŸãïŒ10ÎŒsïŒ1419489706840157-1419489706840147ïŒã
次ã®å°ããªã¹ã¯ãªããã¯ãåäžæåæ¢ã®æéã瀺ããŠããŸãã
enter_tick = 0 open(ARGV.shift){|f| f.each_line{|line| e, tick, * = line.split(/\s/) case e when 'enter' enter_tick = tick.to_i when 'exit' st = tick.to_i - enter_tick puts st if st > 100 # over 100 ÎŒs else # puts line end } }
ãã®ã¹ã¯ãªããã¯100ÎŒsããšã«äžæåæ¢æéãåºåããããããã°ãã¡ã€ã«ã«ã¯å€ãã®è¡ããããŸãã
次ã®å³ã¯ã枬å®çµæã瀺ããŠããŸãã
äžä»£å¥GCã«ã¯7ã€ã®å€§ããªäŒæ¢ãããããšãããããŸãã ããã¯ãã¡ãžã£ãŒGCã®èµ·åã«ããäžæåæ¢ã§ãã æ倧äŒæ¢æéã¯çŽ15msïŒ15KÎŒsïŒã§ãã ãã ããã€ã³ã¯ãªã¡ã³ã¿ã«GCã§ã¯ãæ倧äŒæ¢æéã2ããªç§ïŒ2KÎŒsïŒã«ççž®ãããŸãã çŽ æŽãããã
ãããã«
Ruby 2.2ã¯ãå¢åã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã¢ã«ãŽãªãºã ã䜿çšããŠãã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã®äžæåæ¢æéãççž®ããŸãã
ã€ã³ã¯ãªã¡ã³ã¿ã«GCã¯ãç¹å¹è¬ãã§ã¯ãªãããšã«çæããŠãã ããã ãã§ã«èª¬æããããã«ãã€ã³ã¯ãªã¡ã³ã¿ã«GCã¯ããã©ãŒãã³ã¹ã«åœ±é¿ããŸããã èŠæ±ãé·ãããŠã¡ãžã£ãŒGCãæ°ååŒã³åºãå Žåãããã¯å¿çæéã«åœ±é¿ããŸããã ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã®åèšæéã¯ãã€ã³ã¯ãªã¡ã³ã¿ã«GCã®ããã«ççž®ãããŸããã