- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我能够使用嵌入式版本的 RavenDb 加载几百万个文档,非常漂亮!。
现在我试图查询这些项目,我发现性能不是我所期望的,如果可能的话几乎是瞬时的,而是在一台相当强大的机器上超过 18 秒。
下面,你会发现我的天真代码。
注意:我现在已经解决了这个问题,最终代码在帖子底部。需要注意的是,您需要索引,它们必须是正确的类型,并且需要让 RavenDB 意识到它们。对通过查询引擎返回的记录的性能和质量非常满意。
谢谢,
斯蒂芬
using (var store = new EmbeddableDocumentStore { DataDirectory = @"C:\temp\ravendata" }.Initialize())
{
using (IDocumentSession session = store.OpenSession())
{
var q = session.Query<Product>().Where(x => x.INFO2.StartsWith("SYS")).ToList();
}
}
[Serializable]
public class Product
{
public decimal ProductId { get; set; }
....
public string INFO2 { get; set; }
}
public class InfoIndex_Search : AbstractIndexCreationTask<Product>
{
public InfoIndex_Search()
{
Map = products =>
from p in products
select new { Info2Index = p.INFO2 };
Index(x => x.INFO2, FieldIndexing.Analyzed);
}
}
using (var store = new EmbeddableDocumentStore { DataDirectory = @"C:\temp\ravendata" }.Initialize())
{
// Tell Raven to create our indexes.
IndexCreation.CreateIndexes(Assembly.GetExecutingAssembly(), store);
List<Product> q = null;
using (IDocumentSession session = store.OpenSession())
{
q = session.Query<Product>().Where(x => x.INFO2.StartsWith("SYS")).ToList();
watch.Stop();
}
}
store.DatabaseCommands.PutIndex("ProdcustByInfo2", new IndexDefinitionBuilder<Product>
{
Map = products => from product in products
select new { product.INFO2 },
Indexes =
{
{ x => x.INFO2, FieldIndexing.Analyzed}
}
});
static void Main()
{
Stopwatch watch = Stopwatch.StartNew();
int q = 0;
using (var store = new EmbeddableDocumentStore { DataDirectory = @"C:\temp\ravendata" }.Initialize())
{
if (store.DatabaseCommands.GetIndex("ProdcustByInfo2") == null)
{
store.DatabaseCommands.PutIndex("ProdcustByInfo2", new IndexDefinitionBuilder<Product>
{
Map = products => from product in products
select new { product.INFO2 },
Indexes = { { x => x.INFO2, FieldIndexing.Analyzed } }
});
}
watch.Stop();
Console.WriteLine("Time elapsed to create index {0}{1}", watch.ElapsedMilliseconds, System.Environment.NewLine);
watch = Stopwatch.StartNew();
using (IDocumentSession session = store.OpenSession())
{
q = session.Query<Product>().Count();
}
watch.Stop();
Console.WriteLine("Time elapsed to query for products values {0}{1}", watch.ElapsedMilliseconds, System.Environment.NewLine);
Console.WriteLine("Total number of products loaded: {0}{1}", q, System.Environment.NewLine);
if (q == 0)
{
watch = Stopwatch.StartNew();
var productsList = Parsers.GetProducts().ToList();
watch.Stop();
Console.WriteLine("Time elapsed to parse: {0}{1}", watch.ElapsedMilliseconds, System.Environment.NewLine);
Console.WriteLine("Total number of items parsed: {0}{1}", productsList.Count, System.Environment.NewLine);
watch = Stopwatch.StartNew();
productsList.RemoveAll(_ => _ == null);
watch.Stop();
Console.WriteLine("Time elapsed to remove null values {0}{1}", watch.ElapsedMilliseconds, System.Environment.NewLine);
Console.WriteLine("Total number of items loaded: {0}{1}", productsList.Count, System.Environment.NewLine);
watch = Stopwatch.StartNew();
int batch = 0;
var session = store.OpenSession();
foreach (var product in productsList)
{
batch++;
session.Store(product);
if (batch % 128 == 0)
{
session.SaveChanges();
session.Dispose();
session = store.OpenSession();
}
}
session.SaveChanges();
session.Dispose();
watch.Stop();
Console.WriteLine("Time elapsed to populate db from collection {0}{1}", watch.ElapsedMilliseconds, System.Environment.NewLine);
}
watch = Stopwatch.StartNew();
using (IDocumentSession session = store.OpenSession())
{
q = session.Query<Product>().Where(x => x.INFO2.StartsWith("SYS")).Count();
}
watch.Stop();
Console.WriteLine("Time elapsed to query for term {0}{1}", watch.ElapsedMilliseconds, System.Environment.NewLine);
Console.WriteLine("Total number of items found: {0}{1}", q, System.Environment.NewLine);
}
Console.ReadLine();
}
最佳答案
首先,您是否有涵盖 INFO2 的索引?
其次,请参阅 Daniel Lang 的“在 RavenDB 中搜索字符串属性”博客文章:
http://daniellang.net/searching-on-string-properties-in-ravendb/
如果有帮助,以下是我创建索引的方法:
public class LogMessageCreatedTime : AbstractIndexCreationTask<LogMessage>
{
public LogMessageCreatedTime()
{
Map = messages => from message in messages
select new { MessageCreatedTime = message.MessageCreatedTime };
}
}
private static DocumentStore GetDatabase()
{
DocumentStore documentStore = new DocumentStore();
try
{
documentStore.ConnectionStringName = "RavenDb";
documentStore.Initialize();
// Tell Raven to create our indexes.
IndexCreation.CreateIndexes(typeof(DataAccessFactory).Assembly, documentStore);
}
catch
{
documentStore.Dispose();
throw;
}
return documentStore;
}
关于RavenDb 对查询数百万文档的性能的期望,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9841775/
我正在玩Raven DB几天,我想将其用作Web聊天应用程序的存储。我有包含一些用户数据和聊天记录的文档-这是大集合的聊天消息。 每次加载用户文档时,聊天记录也会加载,即使我只需要几个字段,例如:用户
我的实体是: class Resource { string Name; string EmployeeId; } 如何查询多名员工的资源?我尝试了这个: Resource[] Fin
我知道这篇文章的标题会让一些人感到畏缩。我自 2011 年 12 月以来一直在使用 RavenDB,并且逐渐意识到我以不适合使用文档数据库的方式对数据进行建模。首先,我完全明白这一点。其次,考虑到我目
考虑 2 个查询: var test1 = store.OpenSession().Query().Where(x => x.Id == 1).ToList(); var test2 =
我正在运行 RavenDB.Client 2.0.2173-Unstable。我正在创建一个 Multi-Tenancy 系统,作为我注册过程的一部分,我想创建一个新的 Raven 数据库。 我有三行
我正在使用在 Visual Studio 2010 中通过 NuGet 安装的嵌入式 RavenDB => RavenDB-Embedded.1.0.499 包。它正在我阅读完这篇优秀文章后开始的当前
我们在 AWS 上有一个带有集群 RavenDB 服务器 (5.23) 的 DotNet Core API (C#)。创建文档时,Id 具有不同的格式,具体取决于客户端。如果使用 Swagger/Po
我想知道取回搜索记录总数的最佳方法是什么,同时取回第 N 个 128 记录块数据段,这似乎是 RavenDb 运行时强加的上限。 例如给定这个查询,我还需要知道记录的总数。 var bookmarks
我使用的是 RavenDB 2.0.3.0 版。连接调试器后,涉及 RavenDB 的所有内容都运行得非常缓慢。每个查询需要几秒钟才能完成。 如果我在调试器坐在那里时按下暂停键,我总是看到它挂断了以下
我使用以下代码从 RavenDB 中删除文档。在 Raven UI 的底部,我可以看到文档数量从 3,000,000 减少到 2,000,000。但是“数据”文件的大小不会缩小。它总是大约100G。
我想在我的 Raven DB 中轮询新文档。推荐的方法是什么?我可以使用 IndexTimestamp 还是可以依赖文档的顺序? 我想我想分两步完成: 1.检查是否有新的东西,如果有: 1.1。获取最
我已经更改了我的数据模型,并且需要将所有对象的属性更改为 null,因为在我的模型更改后反序列化它们会引发异常。 我猜我可以为每个文档发布一个补丁,但我找不到任何方法来做到这一点,修补某种类型的每个文
有没有办法在进行空间搜索时从 RavenDB 获取距离计算值。我尝试转换建议的 _ = SpatialIndex.Generate(r.Latitude, r.Longitude) 至 距离 = Sp
是否有一种明智的方法来 stub /模拟调用 IDocumentSession.Query() 的结果? ? 我有一个命令,我想验证在对象上调用了方法(即正在测试的“单元”是命令,而不是命令编排的对象
我想在存储在 RavenDB 文档数据库中的两个实体之间有一个引用。由于这不是关系数据库,我知道我应该使用 RavenDBs 文档中描述的非规范化引用技术。虽然起初这看起来不错,但一旦我开始创建一个真
是否可以使用返回单个文档但不是关键的属性从数据存储加载(而不是查询)文档? 在我的场景中,我有用户和品牌。品牌是用户,但用户不一定是品牌。每个品牌都有一个 UserId 属性及其 Id。有没有办法通过
通过官方 RavenDB 阅读一个简单的问题 documentation ,我知道您可以使用客户端 API 函数执行这些操作,但不能使用 RQL,或者无论如何都可以使用 RQL 执行。 最佳答案 您正
我正尝试在 RavenDB 中检索我按 int 列表排序的文档。 Queryable = Queryable.OrderBy(dto => SearchIds.IndexOf(dto.Property
我刚刚让 RavenDB 开始工作。 我意识到我必须启动 RavenDB\packages\RavenDB.1.0.573\server.exe 才能通过以下方式在我的应用程序中访问它: Do
RavenDB 是否有众所周知的做法来检查 RavenDb 的可用性或检查它在任何给定时间的过载程度?我研究了一些 ravendb API 服务。好像没找到关于健康监测的。有没有像官方的 ravend
我是一名优秀的程序员,十分优秀!