# 提升應用程式效能和穩定性的監控和優化策略 :crown: Speaker: <font color="#ff7300">**Troy Chen @ONEworks**</font> {%hackmd 3_LMFJLvQV-rMOZRjKILnQ %} :raised_hands: Slido: https://app.sli.do/event/qU9X9s5LVvEoFTd9gsSZW6 ###### ✦✦✦✦✦ Here we go ! ✦✦✦✦✦ 著重在程式碼的效能。 ## Angeda New json serializer Web app memory leak Debug a memory leak in linux --- ## New json serializer Usage & Weakness Candidate & Stats Choice & Test Result How to replace Conclusion ### Weakness Slow / more CPU & Mem usage ### Candidate : Jil/FastJson/NetJson/SpanJson/Utf8Json/System.Text.Json System.Text.Json vs Newtonsoft https://medium.com/justeattakeaway-tech/json-serialization-libraries-performance-tests-b54cbb3cccbb ### Choose: System.Text.Json ### 碰到的問題 Not support DataTable/Xml serialization 但預期愈來愈少, actually legacy code --- # Web app memory link Scenario : Mem 漲到80% -> 掉下來 -> 重覆 Work-around : IIS Recycle 分析 w3wp dump (MS debug Diagnostic tool & JetBrains dotMemory) dotMemory Analysis report 發現是3.36GB FileMonitor 做 XML setting file的 Cache 其實不需要monitor , 改寫cache 解決問題. dotMemory > 直接可看到最大量的 class > 也可看得到memory裡頭Duplicated String 是什麼 tip : 使用string.Intern 減少memory 裡頭string pool , 避免 duplicated string # Memory leak in Linux Scenario : 監測到 2GB -> 13GB step1 : 安裝dotnet-dump 在container step2 : dotnet-dump collect -p ProcessId > 在container id 都是1 step3 : dotnet-dump analyze FileName step4 : dotnet-dump - stat 結果是Free Block 思考: 是否是跟GC有關 GC: marking -> relocation -> compating 大物件, 超過85,000 bytes 是不會做壓縮的. LargeObjectHeap Solution : 定期強制壓LOH , 且沒有CPU的影響 --- # QA 會選擇調校newtonsoft.Json的原因是什麼?有甚麼跡象判斷效能的bottle neck 是來自Json serializes嗎? 91建議 目標是 1台撐4,000