Rustãé ãããï¼ãããã¡ã¤ãªã³ã°ã§æ§è½åä¸ï¼
ãéçºããã»ã¹ã«ãããã¡ã¤ãªã³ã°ãçµã¿è¾¼ãã®ã¯ã©ãã ããï¼ã
ãã¼ãã£ã³ã°ã§ããããã¡ã¤ãªã³ã°ã®éè¦æ§ãçºè¨ããã ãã§ãã¿ããªãããªãã®æ·±ãç¥è¦ãæèã®é«ãã«é©ããã¨ã§ãããããã¡ãããããªãã¯ããããã¡ã¤ãªã³ã°ã®ããæ¹ãç¥ã£ã¦ããå¿ è¦ã¯ããã¾ãããéçºã®çµç¤ã«ãæ§è½ç®æ¨ãéæãããã解æãå®æ½ãããé ã«ã¯ã誰ãããªãã®çºè¨ã¯è¦ãã¦ãã¾ãããããããä¸ãä¸ãããªãã®æè¦ãæ¡ç¨ããã¦ãå°ããªãããã«ããã®è¨äºãåèã«ãã¦ãã ããã
Goã¯ãCPUãã¡ã¢ãªãblockãmutexãªã©ã使ãããªããªãã»ã©ã®ç¨®é¡ããµãã¼ããããããã¡ã¤ãªã³ã°ãã¼ã«pprofãæ¨æºæ©è½ã¨ãã¦æä¾ãã¾ããä¸æ¹ãRustã¯ããããªæ©è½ãæä¾ãã¾ãããRustã¸ã®æãæºããããããã¾ããããRustã¸ã®æã¯ãè¦è¿ããæ±ããªãç´æã§ããæã®è¦è¿ãã«ä½ããä¸ããããã¨æå¾ ãã¦ã¯ããã¾ããã
Rustã§ãpprof
ããªãã¯ããã§ã«æ¤ç´¢ãµã¤ãã§ãpprof-rsãè¦ã¤ãã¦ããããããã¾ããããGoã®pprofã«ç¸å½ãããã¼ã«ããRustã«ãããã¯ãã ãããèãããã¨ã¯å½ç¶ã§ããããããpprof-rsã¯ãCPUãããã¡ã¤ãªã³ã°æ©è½ãããµãã¼ããã¾ãããå®æçã«ãã¹ã¿ãã¯ãã¬ã¼ã¹ãåéããpprofãã©ã¼ãããã§ä¿åãããã¨ãã§ãã¾ãï¼Flame Graphsãã©ã¼ãããã«ã対å¿ï¼ãpprofã¨åæ§ã«ãpprof-rsããã¦ã¼ã¶ã¢ã¼ãã§åä½ãããªãã¬ã¼ãã£ã³ã°ã·ã¹ãã ã®ã¿ã¤ãã¼æ©è½ã使ã£ã¦ãå®æçã«ã·ã°ãã«ãçºçãããå®è£ ã¨ãªã£ã¦ãã¾ãã
æ§è½åä¸ã®ããã«ã¯ãCPUãããã¡ã¤ãªã³ã°ã ãã§ã¯ä¸ååã§ããä¾ãã°ãRustã®éåæã¿ã¹ã¯ã®mutex競åãè¦ã¤ããå¿ è¦ãããããããã¾ãããGoã§å¯è½ãªããå¿ è¦ãã©ããã®åé¡ã§ã¯ãªãã®ã§ããRustã§ããããªããã°ããã¾ããã
ã©ã³ã¿ã¤ã ã¨ãããã¡ã¤ãªã³ã°
GoroutineãRustã®éåæã¿ã¹ã¯ããã¦ã¼ã¶ã¢ã¼ãã§åä½ããã©ã³ã¿ã¤ã ã管çããã°ãªã¼ã³ã¹ã¬ããã¨èãããã¨ãã§ããã©ã³ã¿ã¤ã ããmutexæ©è½ãå®è£ ãã¦ãã¾ããGoã§ã¯ãå¦çç³»ã«ã©ã³ã¿ã¤ã ãå«ã¾ãã¦ãã¾ãããRustã¯ãè¤æ°ã®éåæã©ã³ã¿ã¤ã ãéçºããã¦ãããå¿ è¦ã«å¿ãã¦é¸æãããã¨ãã§ãã¾ããæ¬è¨äºã§ã¯ãæã人æ°ã®ããTokioã使ãã¾ãã
Goã§ãmutexãããã¡ã¤ãªã³ã°ãæå¹ã«ãªã£ã¦ããã¨ãGoroutineãmutexãåå¾ããããã«ã¹ãªã¼ãããæéã®é·ããè¨é²ãã¾ããã¤ã¾ããGoroutineãmutexã®åå¾ã«å¤±æãã¦ããã解æ¾ãããã¾ã§ã®æéã§ããTokioã®mutexã³ã¼ãã«ã¯ããã®ãããªæ©è½ã¯ããã¾ãããããããæ¨å¹´æ«ã«ããããã¡ã¤ãªã³ã°ã«ä½¿ããããªæ©è½ã追å ããã¾ããã
Tracingã©ã¤ãã©ãª
Rustã®Tracingã©ã¤ãã©ãªã¯ããã¬ã¼ã¹ã¤ãã³ããåå¾ããããã®éçãªinstrumentationãã³ã¼ãã«åãè¾¼ã¿ãã¤ãã³ããçºçããéã®å¦çãå®ç¾©ããããã®ä»çµã¿ã§ããåç´ãªãã®ã³ã°ãã¡ã¢ãªã¸ã®ä¿åããããã¯ã¼ã¯ã¸ã®éä¿¡ããã£ã¹ã¯ã¸ã®æ¸ãè¾¼ã¿ãªã©ãæ§ã ãªå¦çãå®ç¾ãããã¨ãã§ãã¾ããTokio以å¤ã®ããã¸ã§ã¯ãã§ãæ¡ç¨ãé²ãã§ãã¾ãã
Tokioã®mutexã®ã³ã¼ãã®æ§ã ãªç®æã«ãinstrumentationãåãè¾¼ã¾ãã¦ãã¾ããä¸è¨ã¯ãmutexãéæ¾ããæ¬ä¼¼ã³ã¼ãã§ãã
mutexã®åå¾ã»è§£æ¾ã¤ãã³ãæã«æ å ±ã表示ããåç´ãªã³ã¼ããå®è£ ãã¦ã¿ã¾ãããä¼¼ããããªããæ¹ã§ãmutex競åãè¦ã¤ãããã¨ãã§ãããã§ãã
% cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.27s
Running `target/debug/profiling-mutex`
03:34:30.070078: Mutex (file="src/main.rs" line=113) Released
03:34:30.070463: Mutex (file="src/main.rs" line=113) Locked
03:34:33.072371: Mutex (file="src/main.rs" line=113) Released
03:34:33.073031: Mutex (file="src/main.rs" line=113) Locked
03:34:34.076974: Mutex (file="src/main.rs" line=113) Released
03:34:34.077524: Mutex (file="src/main.rs" line=113) Locked
表示ããã¦ãããã¡ã¤ã«åã¨è¡æ°ã¯ãmutexãå®ç¾©ããã¦ããå ´æã§ããæåã®è¡ã¯ãmutexã解æ¾ç¶æ ã§å®ç¾©ããããã¨ã示ãã¦ãã¾ãã
Tokioã¯éåæã¿ã¹ã¯éã®éä¿¡ãªã©ãæ§ã ãªç®æã«instrumentationãåãè¾¼ãã§ããããã¬ã¼ã¹æ å ±ãå¾ããã¨ãã§ãã¾ãã
ãã§ã«ããã¬ã¼ã¹æ å ±ã使ã£ã¦ã¿ãããªã£ã¦ããã§ããããï¼ã¢ããªã±ã¼ã·ã§ã³ã¸ã®å¤æ´ã¯äºç´°ã§ãåå¾ããããã¬ã¼ã¹ã¤ãã³ãã®ç¨®é¡ãç»é²ããã¤ãã³ãçºçæã®åä½ãå®è£ ããã ãã§ãããã ãã以ä¸ã®æ³¨æç¹ãããã¾ãã
- Tokioã§ãTracingã©ã¤ãã©ãªã¸ã®å¯¾å¿ã¯unstable featuresï¼ãã¤ã§ãAPIãå¤ããå¯è½æ§ããããããã©ã«ãã§ã¯æå¹ã«ãªããªããªã©ã®æå³ï¼ã¨ãªã£ã¦ãããç¹å¥ãªãªãã·ã§ã³ãã¤ãã¦åã³ã³ãã¤ã«ãå¿ è¦ã§ãã
- Tracingã©ã¤ãã©ãªèªä½ããæ´»çºã«éçºããã¦ããç¶æ³ã®ãããããã¥ã¡ã³ãã ãã§ãªããã³ã¼ããèªããã¨ãå¿ è¦ã¨ãªãå¯è½æ§ãé«ãã§ãã
ä¸è¬çã«ã¯ãæ§è½ã®ãªã¼ãããããé¿ããããããã¬ã¼ã¹ã¤ãã³ãããµã³ããªã³ã°ãããããã¡ã¤ãªã³ã°ã®ããã«ä½¿ãã¾ããããããTracingã©ã¤ãã©ãªã¯ãæ§ã ãªæ©è½ã«å¯¾å¿ã§ããæè»æ§ã®ããããã®å®è£ ãããªãè¤éã§ããã®ãªã¼ãã¼ããããæ¸å¿µããã¾ããæ§è½ã«å ããæ©è½ã§ãããããã¡ã¤ãªã³ã°ã®ããã«ã¯ãä»å¾ãTracingã©ã¤ãã©ãªã®æ¡å¼µãå¿ è¦ã ã¨æããã¾ãã
ã¾ã¨ã
Rustã¯ãGoã®ããã«æ¨æºæ©è½ã¨ãã¦ãããã¡ã¤ãªã³ã°ãã¼ã«ã¯æä¾ããã¦ãã¾ããããæ§ã ãªãããã¡ã¤ãªã³ã°ã¯å¯è½ã§ããã¾ããperfãuprobesã®ããã«ã«ã¼ãã«ã¢ã¼ãã§åä½ãããããã¡ã¤ãªã³ã°ãã¼ã«ãå©ç¨å¯è½ã§ãã
Rustã§ããã©ã¼ãã³ã¹ã追æ±ãããã¨ããã¨ã³ã¸ãã¢ã®ã¿ãªãã¾ãNTTã§ã¯ä»²éãåéä¸ã§ãã