c#RavenDB嵌入式优化

c#RavenDB嵌入式优化,c#,.net,database,optimization,ravendb,C#,.net,Database,Optimization,Ravendb,我有一个数据库(RavenDB),它需要能够每10秒处理300个查询(全文搜索)。为了提高性能,我将数据库分割成多个DocumentStore 我的代码: 不,这不好。 使用单个嵌入式RavenDB。如果需要切分,这涉及多台机器 一般来说,RavenDB查询的时间都在几毫秒内。您需要显示查询的外观(可以对查询调用ToString()来查看) 以这种方式拥有RavenDB的碎片意味着他们都在为CPU和IO而战我知道这是一篇老文章,但这是我得到的最热门搜索结果 我遇到的问题与我的查询耗时500毫秒的

我有一个数据库(RavenDB),它需要能够每10秒处理300个查询(全文搜索)。为了提高性能,我将数据库分割成多个DocumentStore 我的代码:

不,这不好。 使用单个嵌入式RavenDB。如果需要切分,这涉及多台机器

一般来说,RavenDB查询的时间都在几毫秒内。您需要显示查询的外观(可以对查询调用ToString()来查看)


以这种方式拥有RavenDB的碎片意味着他们都在为CPU和IO而战

我知道这是一篇老文章,但这是我得到的最热门搜索结果


我遇到的问题与我的查询耗时500毫秒的问题相同。现在通过应用以下搜索实践需要100毫秒:

Price_Range:[*到Dx600]和Price_Range:[Dx200到NULL]和Title:(佳能)和Title:(MP)和Title:(黑色)-Title:(G1)-Title:(T3)这是我的查询。
            var watch = Stopwatch.StartNew();
        int taskcnt = 0;
        int sum = 0;


        for (int i = 0; i < 11; i++)
        {
            Parallel.For(0, 7, new Action<int>((x) =>
            {
                for(int docomentStore = 0;docomentStore < 5; docomentStore++)
                {
                    var stopWatch = Stopwatch.StartNew();
                    Task<IList<eBayItem>> task = new Task<IList<eBayItem>>(Database.ExecuteQuery, new Filter()
                    {
                        Store = "test" + docomentStore,
                        MaxPrice = 600,
                        MinPrice = 200,
                        BIN = true,
                        Keywords = new List<string>() { "Canon", "MP", "Black" },
                        ExcludedKeywords = new List<string>() { "G1", "T3" }
                    });
                    task.ContinueWith((list) => {
                        stopWatch.Stop();
                        sum += stopWatch.Elapsed.Milliseconds;
                        taskcnt++;
                        if (taskcnt == 300)
                        {
                            watch.Stop();
                            Console.WriteLine("Average time: " + (sum / (float)300).ToString());
                            Console.WriteLine("Total time: " + watch.Elapsed.ToString() + "ms");

                        }

                    });
                    task.Start();
                }

            }));
            Thread.Sleep(1000);

        }
        public static IList<eBayItem> ExecuteQuery(object Filter)
    {
        IList<eBayItem> items;
        Filter filter = (Filter)Filter;

        if (int.Parse(filter.Store.ToCharArray().Last().ToString()) > 4)
        {
            Console.WriteLine(filter.Store); return null;
        }
        using (var session = Shards[filter.Store].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.ToList<eBayItem>();
        }
        return items;
    }
        static Dictionary<string, EmbeddableDocumentStore> Shards = new Dictionary<string, EmbeddableDocumentStore>();
    public static void Connect()
    {
        Shards.Add("test0", new EmbeddableDocumentStore() { DataDirectory = "test.db" });
        Shards.Add("test1", new EmbeddableDocumentStore() { DataDirectory = "test1.db" });
        Shards.Add("test2", new EmbeddableDocumentStore() { DataDirectory = "test2.db" });
        Shards.Add("test3", new EmbeddableDocumentStore() { DataDirectory = "test3.db" });
        Shards.Add("test4", new EmbeddableDocumentStore() { DataDirectory = "test4.db" });
        foreach (string  key in Shards.Keys)
        {
            EmbeddableDocumentStore store = Shards[key];
            store.Initialize();
            IndexCreation.CreateIndexes(typeof(eBayItemIndexer).Assembly, store);
        }
    }
Price_Range:[* TO Dx600] AND Price_Range:[Dx200 TO NULL] AND Title:(Canon) AND Title:(MP) AND Title:(Black) -Title:(G1) -Title:(T3)