2017-04-24 71 views
0

我试图在执行给定查询时打印查询统计信息。特别是我对毫秒级的服务器执行时间感兴趣。下面是我参考RavenDB查询统计信息服务器执行时间(以毫秒为单位)

void Main() 
{ 
    var documentStore = DocumentStoreHolder.Store; 
    Load_Stats(documentStore); 
} 

// Define other methods and classes here 

public static void Load_Stats(IDocumentStore documentStore) 
{ 


using (var session = documentStore.OpenSession()) 
{ 
    RavenQueryStatistics stats; 
    IRavenQueryable<Order> recentOrdersQuery = from order in session.Query<Order>().Statistics(out stats) where order.Company=="companies/1" select order; 
    List<Order> recentOrders = recentOrdersQuery.Take(3).ToList(); 
    Console.WriteLine("Index used was: " + stats.IndexName); 
    Console.WriteLine($"Other stats : 1. Execution time on the server : {stats.DurationMilliseconds} 2.Total number of results {stats.TotalResults} 3. The last document ETag {stats.ResultEtag} 4. The timestamp of last document indexed by the index {stats.IndexTimestamp}"); 
} 

但在此查询我到以毫秒为单位-1运行在服务器上查询花费时间的重复执行代码。我不明白为什么会这样。我应该将结果赋给一个长变量还是允许打印结果(stats.DurationMilliseconds)。 TIA

回答

1

最可能的原因就是这是不是去服务器

+0

感谢奥伦因为RavenDB能够从客户端缓存服务请求,!我尝试了一个不同的谓词,这是我以前的查询中没有使用过的,我能够得到一个有效的结果。将探索客户端的选项以禁用缓存以进行测试。 –

相关问题