2013-04-02 106 views
0

我使用RavenDB,但我注意到我的數據庫在閱讀時非常緩慢。這是我如何查詢到我的數據庫:RavenDB緩慢閱讀

 IEnumerable<Reduced> items; 
     Filter filter = (Filter)Filter; 

     var watch = Stopwatch.StartNew(); 
     using (var session = documentStore.OpenSession()) 
     { 

      var query = session.Query<eBayItem,eBayItemIndexer>().Where(y => y.Price <= filter.MaxPrice && y.Price >= filter.MinPrice); 
      query = filter.Keywords.ToArray() 
      .Aggregate(query, (q, term) => 
       q.Search(xx => xx.Title, term, options: SearchOptions.And)); 
      if (filter.ExcludedKeywords.Count > 0) 
      { 
       query = filter.ExcludedKeywords.ToArray().Aggregate(query, (q, exterm) => 
       q.Search(it => it.Title, exterm, options: SearchOptions.Not)); 
      } 
      items = query.AsProjection<Reduced>().ToList(); 
      Console.WriteLine("Query: " + query.ToString()); 
      Console.WriteLine("Results: " + items.Count()); 
     } 
     watch.Stop(); 
     Console.WriteLine("Query time: " + watch.Elapsed.Milliseconds + " ms"); 
     return items; 

輸出:

  • 查詢:PRICE_RANGE:[* TO Dx600]和PRICE_RANGE:DX400爲null]和標題(佳能)和名稱:(MP)和名稱:(黑色)-Title:(G1)-Title:(T3)
  • 結果:3
  • 查詢時間:365毫秒

索引:

public class eBayItemIndexer : AbstractIndexCreationTask<eBayItem> 
{ 
    public eBayItemIndexer() 
    { 
     Map = contentItems => 
      from contentItem in contentItems 
      select new { contentItem.Title, contentItem.Price }; 

     Index(x => x.Title, FieldIndexing.Analyzed); 
     Index(x => x.Price, FieldIndexing.Analyzed); 


     TransformResults = (database, items) => 
      from contentItem in items 
      select new { contentItem.Id }; 
    } 
} 

初始化:

 documentStore = new EmbeddableDocumentStore() { DataDirectory = "test.db" }; 
     documentStore.Initialize(); 
     IndexCreation.CreateIndexes(typeof(eBayItemIndexer).Assembly, documentStore); 
     documentStore.Configuration.TransactionMode = Raven.Abstractions.Data.TransactionMode.Lazy; 
     documentStore.Configuration.AllowLocalAccessWithoutAuthorization = true; 

是他們的一些錯誤,使得它慢的代碼?

回答

0

EmbeddableDocumentStore可能是問題所在。更準確地說,它看起來像是初始化商店,然後立即調用查詢。索引上的前幾個查詢總是會稍微慢一些。

+0

保持程序空閒1小時後,查詢仍然需要350毫秒的avarage。 – Svexo

+0

它必須與EmbeddableDocumentStore做一些事情,但是,託管一個服務器本地,querty時間大約是20ms – Svexo

+0

@Ayende我也嘗試在嵌入模式下使用db,並且我的init時間很糟糕。我能做些什麼來加快速度? – Skadoosh