C# RavenDB中的查询时间太长

C# RavenDB中的查询时间太长,c#,testing,time,ravendb,C#,Testing,Time,Ravendb,我在RavenDB中有一个测试query时间的例子。因此,我使用Linq来query和StopWatch来获取计时 但是当我运行我的代码时,计时似乎太长了(它是2401 ms),所以我尝试通过ranvenstudio进行查询,结果是计时只花了1 ms。我不知道为什么它有这么多不同 Ps:我的数据库有200000个文档,当然,我有索引 using System; using System.Collections.Generic; using System.Diagnostics; using Sy

我在
RavenDB
中有一个测试
query
时间的例子。因此,我使用
Linq
query
StopWatch
来获取计时

但是当我运行我的代码时,计时似乎太长了(它是
2401 ms
),所以我尝试通过
ranvenstudio
进行查询,结果是计时只花了
1 ms
。我不知道为什么它有这么多不同

Ps:我的数据库有200000个文档,当然,我有
索引

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Raven.Client.Documents;
using Raven.Client.Documents.BulkInsert;

namespace ConsoleApplication6
{
    public class Customer
    {
        public string Id { get; set; }
        public string Name { get; set; }
    }

    public class SupportCall
    {
        public string Id { get; set; }
        public int Cost { get; set; }
        public string CustomerId { get; set; }
        public DateTime StartDay { get; set; }
        public DateTime EndDay { get; set; }
        public string Issue { get; set; }
    }

    internal class Program
    {
        private static char[] _buffer = new char[6];
        private static string RandomName(Random rand)
        {
            _buffer[0] = (char)rand.Next(65, 91);
            for (int i = 1; i < 6; i++)
            {
                _buffer[i] = (char)rand.Next(97, 123);
            }
            return new string(_buffer);
        }
        static void Main(string[] args)
        {
            using (var store = new DocumentStore
            {
                Urls = new[] { "http://localhost:8080" },
                Database = "Test"
            }.Initialize())
            { 
                using (var session = store.OpenSession())
                {
                    var sp = Stopwatch.StartNew();
                    SupportCall supportCall = session.Query<SupportCall>()
                        .Include<SupportCall>(s => s.CustomerId)
                        .Where(s => s.Cost == 21821).FirstOrDefault();
                    Customer customer = session.Load<Customer>(supportCall.CustomerId);
                    sp.Stop();
                    Console.WriteLine(sp.ElapsedMilliseconds);
                }
                Console.ReadKey();
            }
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统诊断;
使用System.Linq;
使用System.Security.Cryptography.X509证书;
使用System.Threading.Tasks;
使用Raven.Client.Documents;
使用Raven.Client.Documents.BulkInsert;
命名空间控制台应用程序6
{
公共类客户
{
公共字符串Id{get;set;}
公共字符串名称{get;set;}
}
公共类支持呼叫
{
公共字符串Id{get;set;}
公共整数成本{get;set;}
公共字符串CustomerId{get;set;}
公共日期时间开始日期{get;set;}
公共日期时间结束日{get;set;}
公共字符串问题{get;set;}
}
内部课程计划
{
私有静态字符[]_buffer=新字符[6];
私有静态字符串RandomName(随机兰德)
{
_缓冲区[0]=(字符)rand.Next(65,91);
对于(int i=1;i<6;i++)
{
_缓冲区[i]=(字符)rand.Next(97123);
}
返回新字符串(_buffer);
}
静态void Main(字符串[]参数)
{
使用(var存储=新文档存储)
{
URL=new[]{”http://localhost:8080" },
Database=“Test”
}.Initialize())
{ 
使用(var session=store.OpenSession())
{
var sp=Stopwatch.StartNew();
SupportCall SupportCall=session.Query()
.Include(s=>s.CustomerId)
其中(s=>s.Cost==21821).FirstOrDefault();
Customer=session.Load(supportCall.CustomerId);
sp.Stop();
控制台写入线(sp.ElapsedMilliseconds);
}
Console.ReadKey();
}
}
}
}

您可以进行相同的查询(实际上,最好使用不同的参数,以避免缓存成本)并再次检查吗

花费这么长时间的最常见原因是您要为首次连接和建立文档存储设置付费。 奇怪的是,你是在本地主机上做这件事的,所以我希望这会非常快,即使是在最初的通话中

您可以使用Fiddler(将url更改为:
)http://localhost.fiddler:8080“
因此它将捕获它)以查看网络上的成本

我见过这样的事情发生,因为反病毒和包检查UTIL