RavenDB选择性能差

RavenDB选择性能差,ravendb,Ravendb,我正在为我未来的项目测试RavenDB。数据库性能对我来说是一个必须的要求,这就是为什么我希望能够将RavenDB调优到至少在SQL Server的性能范围内,但我的测试表明,RavenDB在选择查询中比SQL Server慢大约10-20倍,即使RavenDB已被索引,而SQL Server没有任何索引 我用150k文档填充了数据库。每个文档都有一个子元素的集合。数据库大小约为1GB,索引大小也是如此。Raven/Esent/CacheSizeMax设置为2048,Raven/Esent/Ma

我正在为我未来的项目测试RavenDB。数据库性能对我来说是一个必须的要求,这就是为什么我希望能够将RavenDB调优到至少在SQL Server的性能范围内,但我的测试表明,RavenDB在选择查询中比SQL Server慢大约10-20倍,即使RavenDB已被索引,而SQL Server没有任何索引

我用150k文档填充了数据库。每个文档都有一个子元素的集合。数据库大小约为1GB,索引大小也是如此。Raven/Esent/CacheSizeMax设置为2048,Raven/Esent/MaxVerPages设置为128。 以下是文档的外观:

{
  "Date": "2028-09-29T01:27:13.7981628",
  "Items": [
    {
      {
      "ProductId": "products/673",
      "Quantity": 26,
      "Price": {
        "Amount": 2443.0,
        "Currency": "USD"
      }
    },
    {
      "ProductId": "products/649",
      "Quantity": 10,
      "Price": {
        "Amount": 1642.0,
        "Currency": "USD"
      }
    }
  ],
  "CustomerId": "customers/10"
}


public class Order
{
    public DateTime Date { get; set; }
    public IList<OrderItem> Items { get; set; }
    public string CustomerId { get; set; }
}

public class OrderItem
{
    public string ProductId { get; set; }
    public int Quantity { get; set; }
    public Price Price { get; set; }
}

public class Price
{
    public decimal Amount { get; set; }
    public string Currency { get; set; }
}
错误CS1977:如果不首先将lambda表达式强制转换为委托或表达式树类型,则无法将lambda表达式用作动态调度操作的参数, 以下索引生成约800万个索引项:

from doc in docs.Orders
from docItemsItem in ((IEnumerable<dynamic>)doc.Items).DefaultIfEmpty()
select new { Items_Price_Amount = docItemsItem.Price.Amount, Items_Quantity = docItemsItem.Quantity, Date = doc.Date }
可以用同样的结果查询,但在我们的测试中显示速度是原来的两倍

主要的问题是,您正在进行多个范围查询,这些查询代价很高,并且有大量的潜在值,然后您将有大量的实际匹配项用于查询

顺便说一句,进行精确匹配要快得多


我们仍在努力加快速度。

看到Raven DB性能不佳,我们感到惊讶。这表明底层数据结构或索引定义存在严重问题。Davita,这似乎根本不对。像这样的查询最多需要50毫秒左右。您能创建一个可复制的测试用例并将其发送到邮件列表吗?我们非常重视perf,并将此类场景视为bug。值得一提的是,您的情景完全符合我们的操作参数,您所引用的数字远远超出了我们的经验,因此这里有些问题。一个测试用例将非常有助于了解Anks伙计们的情况,这就是我所期望的答案:@Ayende,你能更具体一点吗?你所说的测试用例是什么意思?我可以给你完整的数据库转储+vs项目。还有什么我能做的吗?再次感谢,我感谢您的帮助:收到了,并在本地转载,请给我们几天时间来了解Anks Ayende的情况,我将在几个小时内检查解决方案,并让您知道结果。然而,如果我们能够加快索引查找,那将是非常棒的,我认为800万个条目对于降低DBMS的速度来说是非常重要的。无论如何,非常感谢您的出色工作和支持:问题不在于条目的数量,而在于查询类型。为此,我们必须在内存中保留大量数据,而且成本很高。尝试使用精确匹配,或者仅使用单个范围查询,您将看到一个重大差异。
session.Query<Order>("OrdersIndex").Where(o =>
    o.Items.Any(oi => oi.Price.Amount > 0 && oi.Quantity < 100)).Take(128).ToList();
public Index_OrdersIndex()
    {
        this.ViewText = @"from doc in docs.Orders
select new { Items_Price_Amount = doc.Items(s=>s.Price.Amount), Items_Quantity = doc.Items(s=>s.Quantity), Date = doc.Date }
";
        this.ForEntityNames.Add("Orders");
        this.AddMapDefinition(docs => from doc in docs
            where doc["@metadata"]["Raven-Entity-Name"] == "Orders"
            select new { Items_Price_Amount = doc.Items(s => s.Price.Amount), Items_Quantity = doc.Items.(s => s.Quantity), Date = doc.Date, __document_id = doc.__document_id });
        this.AddField("Items_Price_Amount");
        this.AddField("Items_Quantity");
        this.AddField("Date");
        this.AddField("__document_id");
        this.AddQueryParameterForMap("Date");
        this.AddQueryParameterForMap("__document_id");
        this.AddQueryParameterForReduce("Date");
        this.AddQueryParameterForReduce("__document_id");
    }
}
from doc in docs.Orders
from docItemsItem in ((IEnumerable<dynamic>)doc.Items).DefaultIfEmpty()
select new { Items_Price_Amount = docItemsItem.Price.Amount, Items_Quantity = docItemsItem.Quantity, Date = doc.Date }
from doc in docs.Orders
select new { Items_Price_Amount = doc.Items(s=>s.Price.Amount), Items_Quantity = doc.Items.(s=>s.Quantity), Date = doc.Date }