我正在为我未来的项目测试RavenDB . 数据库性能是我必须要求的,这就是为什么我希望能够将RavenDB调整到至少在SQL Server的性能范围内,但是我的测试显示raven db在选择查询中比SQL Server慢大约10x-20x,甚至当RavenDB被索引并且SQL Server没有任何索引时 .
我用150k文件填充数据库 . 每个文档都有一个子元素集合 . Db尺寸约为 . 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; }
}
这是定义的索引:
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 }
我使用Management studio定义了索引,而不是代码BTW(不知道它是否对性能有任何负面/正面影响) .
此查询需要500毫秒到1500毫秒才能完成(请注意,这是执行查询所需的时间,直接显示在ravendb的控制台上 . 因此它不包含http请求时间和反序列化开销 . 只需查询执行时间) .
session.Query<Order>("OrdersIndex").Where(o =>
o.Items.Any(oi => oi.Price.Amount > 0 && oi.Quantity < 100)).Take(128).ToList();
我在运行4.2 GHz的四核i5 cpu上运行查询,db位于SSD上 .
现在,当我在sql server express上填充相同数量的数据时,使用相同的模式和相同数量的关联对象 . 没有索引,sql server执行相同的查询,包括35ms的连接 . 使用索引需要0ms:| .
在数据库服务器预热时执行所有测试 .
虽然,我对RavenDB的性能仍然非常满意,但我很好奇我是否遗漏了什么或RavenDB比关系数据库慢?抱歉我的英语不好 .
谢谢
UPDATE
Ayande,我尝试了你的建议,但当我尝试定义你发给我的索引时,我收到以下错误:
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");
}
}
错误CS1977:不能将lambda表达式用作动态调度操作的参数,而无需先将其转换为委托或表达式树类型
1 回答
Davita,以下索引产生约800万个索引条目:
这个产生的远远少于:
并且可以用相同的结果查询,但是在我们的测试中显示的速度大约是原来的两倍 .
主要问题是您正在进行多个范围查询,这些查询在具有大量潜在值的情况下很昂贵,然后您有大量实际匹配的查询 .
顺便说一句,完全匹配要快得多 .
我们仍在研究如何加快速度 .