2017-02-22 36 views
-1

有什麼方法可以將單個分區中的大量實體(〜250K)從Azure表存儲器重新獲取到.NET應用程序?從Azure表存儲中有效地檢索大量實體

+2

請在您的問題中添加更多詳細信息,例如我們在討論多少實體或您想要下載哪些實體等?就目前而言,這個問題非常模糊。 –

回答

2

據我所知,有兩種方法可以優化從單個分區從Azure表存儲到.NET應用程序的大量實體的檢索。

1.如果您不需要獲取實體的所有屬性,我建議您可以使用服務器端投影。

單個實體最多可以有255個屬性,大小最大爲1 MB。當您查詢表格並檢索實體時,您可能不需要所有的屬性,並且可以避免不必要的數據傳輸(以幫助減少延遲和成本)。您可以使用服務器端投影來傳輸您所需的屬性。

來源:Azure Storage Table Design Guide: Designing Scalable and Performant Tables(Server-side projection)

更多細節,你可以參考遵循代碼:

string filter = TableQuery.GenerateFilterCondition(
     "PartitionKey", QueryComparisons.Equal, "Sales"); 
List<string> columns = new List<string>() { "Email" }; 
TableQuery<EmployeeEntity> employeeQuery = 
     new TableQuery<EmployeeEntity>().Where(filter).Select(columns); 

var entities = employeeTable.ExecuteQuery(employeeQuery); 
foreach (var e in entities) 
{ 
     Console.WriteLine("RowKey: {0}, EmployeeEmail: {1}", e.RowKey, e.Email); 
} 

2.如果你只是想顯示錶的消息,你不需要把所有的實體在同一時間。 你可以得到一部分結果。 如果你想獲得其他結果,你可以使用continuation token。 這將改善表查詢性能。

對錶服務的查詢可能一次返回最多1,000個實體,並且可能最多執行5秒。如果結果集包含超過1,000個實體,如果查詢未在五秒內完成,或者查詢跨越分區邊界,則表服務會返回一個連續標記以使客戶端應用程序能夠請求下一組實體。有關連續令牌如何工作的更多信息,請參閱查詢超時和分頁。

來源:Azure Storage Table Design Guide: Designing Scalable and Performant Tables(Retrieving large numbers of entities from a query)

通過使用延續令牌明確,你可以在你的應用程序中檢索數據的下一段控制。

更多細節,你可以參考遵循代碼:

string filter = TableQuery.GenerateFilterCondition(
     "PartitionKey", QueryComparisons.Equal, "Sales"); 
TableQuery<EmployeeEntity> employeeQuery = 
     new TableQuery<EmployeeEntity>().Where(filter); 

TableContinuationToken continuationToken = null; 

do 
{ 
     var employees = employeeTable.ExecuteQuerySegmented(
     employeeQuery, continuationToken); 
    foreach (var emp in employees) 
    { 
    ... 
    } 
    continuationToken = employees.ContinuationToken; 
} while (continuationToken != null); 

此外,我建議你可以注意表分區的可擴展性的目標。

目標吞吐量爲單個表分區(1個KB單位)每秒最多

如果達不到這個分區的可擴展性目標2000米的實體,存儲服務將油門。

+0

如果您不明確使用連續令牌,查詢工作如何? –

+0

如果使用ExecuteQuery方法,庫將自動使用連續令牌來獲取其餘數據。 如果使用ExecuteQuerySegmented方法,則需要將continuationToken參數傳遞給該方法,如果該標記爲空,它將返回前1000個實體。 –

相關問題