我目前正面臨Azure DocumentDB的響應時間非常慢(首次嘗試它)。Azure DocumentDB上的性能下降
集合中有31個對象,我將獲取並返回給調用者。我使用的代碼是這樣的:
public async Task<List<dynamic>> Get(string collectionName = null)
{
// Lookup from Dictionary, takes literally no time
var collection = await GetCollectionAsync(collectionName);
var sw = Stopwatch.StartNew();
var query = await
_client.CreateDocumentQuery(collection.DocumentsLink,
new FeedOptions { MaxItemCount = 1000 })
.AsDocumentQuery()
.ExecuteNextAsync();
Trace.WriteLine($"Get documents: {sw.ElapsedMilliseconds} ms");
return query.ToList();
}
實例化客戶端,我用下面的代碼:
_client = new DocumentClient(new Uri(endpoint), authKey, new ConnectionPolicy
{
ConnectionMode = ConnectionMode.Direct,
ConnectionProtocol = Protocol.Tcp
});
的響應時間,我從Stopwatch
越來越是360ms和1200ms之間返回31個對象。對我而言,那是挺慢。如果沒有自定義ConnectionPolicy
,平均響應時間大約是950ms。
我在這裏做錯了什麼?是否有可能以某種方式加速這些請求?
這裏是從跟蹤輸出,打印出秒錶的經過時間:
Get documents: 1984 ms
Get documents: 1252 ms
Get documents: 1246 ms
Get documents: 359 ms
Get documents: 356 ms
Get documents: 356 ms
Get documents: 351 ms
Get documents: 1248 ms
Get documents: 1314 ms
Get documents: 1250 ms
您是否曾嘗試在與您的DocumentDB實例相同的數據中心中運行代碼?我對我的系統在快速互聯網連接(即使是一次操作最少250ms)上運行操作感到非常失望,但是當我運行在同一個數據中心時,延遲低於10ms。如果您不想將實驗推送到數據中心,請嘗試使用10倍數據量的查詢。我懷疑你只會看到稍微增加的數字。如果是這樣,那會給你證據表明它是從數據中心外部調用它的延遲。 –
我確實認爲有一種情況是,從延遲角度來看,穿越數據中心邊界太昂貴。我的網絡連接上的ping時間只有50-70ms。即使加倍,也不能解釋最小250ms的延遲。 –
我可以這麼說:從同一個數據中心的SQL服務器(Azure)檢索31行比這更快_much_。即使行數比從DocumentDB中檢索到的對象數據更多。 –