Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Windows Azure 常見問題與解決方案 (上):Table Service 連線數、100-Continue、Context 追蹤優化

編輯:Win7 系統基礎知識

前言

Windows Azure (現 Microsoft Azure) 作為微軟雲端平台,開發與部署過程中常遇到效能與設定問題。本文整理 Table Service 三大效能調優參數:最大連線數、100-Continue、Context 追蹤關閉。

1.1 修改最大連線數 (ServicePointManager)

預設 ServicePointManager.DefaultConnectionLimit = 2 嚴重限制並發。調高至 24-200 視實例規格:

// 程式碼設定 (啟動時一次)
ServicePointManager.DefaultConnectionLimit = 24;

// 或組態檔 Web.config / App.config
<system.net>
  <connectionManagement>
    <add address="*" maxconnection="24" />
  </connectionManagement>
</system.net>

建議:Worker Role 高併發設 100-200,Web Role 視流量 24-50。

1.2 關閉 100-Continue (Expect100Continue)

HTTP 1.1 預設傳送 Expect: 100-continue 等待伺服器回應再傳送主體,增加延遲。關閉:

// 程式碼
ServicePointManager.Expect100Continue = false;

// 組態檔
<system.net>
  <settings>
    <servicePointManager expect100Continue="false" />
  </settings>
</system.net>

效果:減少每請求一個 RTT (來回延遲),大幅提升小請求吞吐量。

1.3 關閉 Context 追蹤 (MergeOption.NoTracking)

Entity Framework / WCF Data Services DataServiceContext 預設追蹤實體變更,純查詢場景浪費記憶體/CPU:

context.MergeOption = MergeOption.NoTracking;

適用:唯讀查詢、報表產生、大量資料匯出。不可用於需更新/刪除的場景。

結語

Azure Table Service 三大效能鑰匙:DefaultConnectionLimit 解除並發限制、Expect100Continue=false 消除 RTT、NoTracking 純查詢零開銷。下集將解決 PartitionKey/RowKey 設計、HttpHandler 設定、Storage 連線字串初始化三大開發實戰問題。

Copyright © Windows教程網 All Rights Reserved