gpt4 book ai didi

c# - RavenDB 查询时间过长

转载 作者:太空宇宙 更新时间:2023-11-03 12:08:27 24 4
gpt4 key购买 nike

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

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

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

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();
}
}
}
}

最佳答案

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

花费这么长时间的最常见原因是您要为第一次连接和建立文档存储设置付费。这里奇怪的部分是您在本地主机上执行此操作,所以我希望这会非常快,即使是在初始调用时也是如此。

您可以使用 Fiddler(将 url 更改为:"http://localhost.fiddler:8080" 这样它就会捕获它)查看网络成本是多少。

我曾看到过由于防病毒和数据包检测实用程序而发生的类似情况。

关于c# - RavenDB 查询时间过长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53670605/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com