RavenDbの埋め込みバージョンで数百万ものドキュメントを読み込むことができました。RavenDbは何百万という数のドキュメントをクエリするためのパフォーマンスを期待しています
私はこれらのアイテムを照会しようとしていますが、パフォーマンスは私が予想していたものではなく、できるだけ瞬間的にではなく、かなり軽いマシンでは18秒以上です。
以下は、私の素朴なコードです。
注:これで解決しました。最終コードは投稿の末尾にあります。そのためには、インデックスが必要であり、適切なタイプのものでなければならず、RavenDBにそれらのことを知らせる必要があります。クエリエンジンを使用して返されるレコードのパフォーマンスと品質に非常に満足しました。
ありがとう、 スティーブン
using (var store = new EmbeddableDocumentStore { DataDirectory = @"C:\temp\ravendata" }.Initialize())
{
using (IDocumentSession session = store.OpenSession())
{
var q = session.Query<Product>().Where(x => x.INFO2.StartsWith("SYS")).ToList();
}
}
[Serializable]
public class Product
{
public decimal ProductId { get; set; }
....
public string INFO2 { get; set; }
}
EDIT
私は、このクラスに
public class InfoIndex_Search : AbstractIndexCreationTask<Product>
{
public InfoIndex_Search()
{
Map = products =>
from p in products
select new { Info2Index = p.INFO2 };
Index(x => x.INFO2, FieldIndexing.Analyzed);
}
}
を追加し、このように見えるように、呼び出し方法を変更しました。
using (var store = new EmbeddableDocumentStore { DataDirectory = @"C:\temp\ravendata" }.Initialize())
{
// Tell Raven to create our indexes.
IndexCreation.CreateIndexes(Assembly.GetExecutingAssembly(), store);
List<Product> q = null;
using (IDocumentSession session = store.OpenSession())
{
q = session.Query<Product>().Where(x => x.INFO2.StartsWith("SYS")).ToList();
watch.Stop();
}
}
しかし、私はまだ18秒間、検索を行うと報告しています。私は何が欠けていますか?もう1つの注意点として、C:\ temp \ ravendata \ Indexes \ InfoIndex%2fSearchフォルダにはかなりの数の新しいファイルがありますが、データを挿入したときとほとんど同じくらいではありませんが、クエリーを数回試みる。場合は、IndexCreation.CreateIndexes(Assembly.GetExecutingAssembly()、ストア);挿入する前に呼び出され、その時だけ?このコードを使用して
EDIT1
私は、インスタンスにはほとんど起こらするクエリを取得することができたが、あなたが一度だけこれを実行することができそうですので、それは質問を頼みます。これはどこで実行され、適切な初期化手順は何ですか?
store.DatabaseCommands.PutIndex("ProdcustByInfo2", new IndexDefinitionBuilder<Product>
{
Map = products => from product in products
select new { product.INFO2 },
Indexes =
{
{ x => x.INFO2, FieldIndexing.Analyzed}
}
});
EDIT2:実施例
static void Main()
{
Stopwatch watch = Stopwatch.StartNew();
int q = 0;
using (var store = new EmbeddableDocumentStore { DataDirectory = @"C:\temp\ravendata" }.Initialize())
{
if (store.DatabaseCommands.GetIndex("ProdcustByInfo2") == null)
{
store.DatabaseCommands.PutIndex("ProdcustByInfo2", new IndexDefinitionBuilder<Product>
{
Map = products => from product in products
select new { product.INFO2 },
Indexes = { { x => x.INFO2, FieldIndexing.Analyzed } }
});
}
watch.Stop();
Console.WriteLine("Time elapsed to create index {0}{1}", watch.ElapsedMilliseconds, System.Environment.NewLine);
watch = Stopwatch.StartNew();
using (IDocumentSession session = store.OpenSession())
{
q = session.Query<Product>().Count();
}
watch.Stop();
Console.WriteLine("Time elapsed to query for products values {0}{1}", watch.ElapsedMilliseconds, System.Environment.NewLine);
Console.WriteLine("Total number of products loaded: {0}{1}", q, System.Environment.NewLine);
if (q == 0)
{
watch = Stopwatch.StartNew();
var productsList = Parsers.GetProducts().ToList();
watch.Stop();
Console.WriteLine("Time elapsed to parse: {0}{1}", watch.ElapsedMilliseconds, System.Environment.NewLine);
Console.WriteLine("Total number of items parsed: {0}{1}", productsList.Count, System.Environment.NewLine);
watch = Stopwatch.StartNew();
productsList.RemoveAll(_ => _ == null);
watch.Stop();
Console.WriteLine("Time elapsed to remove null values {0}{1}", watch.ElapsedMilliseconds, System.Environment.NewLine);
Console.WriteLine("Total number of items loaded: {0}{1}", productsList.Count, System.Environment.NewLine);
watch = Stopwatch.StartNew();
int batch = 0;
var session = store.OpenSession();
foreach (var product in productsList)
{
batch++;
session.Store(product);
if (batch % 128 == 0)
{
session.SaveChanges();
session.Dispose();
session = store.OpenSession();
}
}
session.SaveChanges();
session.Dispose();
watch.Stop();
Console.WriteLine("Time elapsed to populate db from collection {0}{1}", watch.ElapsedMilliseconds, System.Environment.NewLine);
}
watch = Stopwatch.StartNew();
using (IDocumentSession session = store.OpenSession())
{
q = session.Query<Product>().Where(x => x.INFO2.StartsWith("SYS")).Count();
}
watch.Stop();
Console.WriteLine("Time elapsed to query for term {0}{1}", watch.ElapsedMilliseconds, System.Environment.NewLine);
Console.WriteLine("Total number of items found: {0}{1}", q, System.Environment.NewLine);
}
Console.ReadLine();
}
INFO2をカバーするインデックスがありますか? –
私は今何をしますか。少し旅はしますが、十分に価値があります。 –