使用 Windows Azure 表格儲存服務時,預設連線限制與 HTTP 協定行為可能成為效能瓶頸。以下三項設定可顯著提升高併發場景下的吞吐量與回應速度。
預設 ServicePointManager.DefaultConnectionLimit 僅 2,嚴重限制並發。在 app.config 或程式碼中調大:
<system.net>
<connectionManagement>
<add address="*" maxconnection="24" />
</connectionManagement>
</system.net>
或程式碼:ServicePointManager.DefaultConnectionLimit = 24;
HTTP 1.1 預設會先送 Expect: 100-continue 等待伺服器回應,增加延遲。關閉它:
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
程式碼:ServicePointManager.Expect100Continue = false;
若僅執行查詢操作,關閉實體追蹤可減少記憶體與 CPU 開銷:
context.MergeOption = MergeOption.NoTracking;
套用上述三項設定後,表格服務在大量並發讀寫場景下表現將明顯改善。