运行在本地计算机上的C#代码从DocumentDB查询时,平均一个简单的DocumentDB查询大约需要0.5秒。另一个例子是,获得文档集合的引用平均需要0.7秒。这是否符合预期?下面是检查集合是否存在的代码,非常简单明了 - 但有没有改善性能差的方法?
// Create a new instance of the DocumentClient
var client = new DocumentClient(new Uri(EndpointUrl), AuthorizationKey);
// Get the database with the id=FamilyRegistry
var database = client.CreateDatabaseQuery().Where(db => db.Id == "FamilyRegistry").AsEnumerable().FirstOrDefault();
var stopWatch = new Stopwatch();
stopWatch.Start();
// Get the document collection with the id=FamilyCollection
var documentCollection = client.CreateDocumentCollectionQuery("dbs/"
+ database.Id).Where(c => c.Id == "FamilyCollection").AsEnumerable().FirstOrDefault();
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
var ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
var elapsedTime = String.Format("{0:00} seconds, {1:00} milliseconds",
ts.Seconds,
ts.Milliseconds );
Console.WriteLine("Time taken to get a document collection: " + elapsedTime);
Console.ReadKey();
本地计算机的平均输出:
Time taken to get a document collection: 0 seconds, 752 milliseconds
在我的另一段代码中,我正在进行20个小型文档的更新,每个文档的JSON大小约为400字节,但总共仍需要12秒才能完成。虽然我只是在开发环境下运行,但我预期性能应该更好。