简体   繁体   English

如何最有效地搜索数据? (RAM或MongoDB中的对象)

[英]How to search data most efficiently? (Object in RAM or MongoDB)

In a scenario where your nodeJS server has a static collection of 40mb of text loaded in memory, 在您的nodeJS服务器在内存中加载了40mb静态文本集合的情况下,

Everytime your webclient asks for a search (1000 elements to look through), which method would be optimal? 每当您的网络客户端请求搜索(可浏览1000个元素)时,哪种方法是最佳的?

  • Query the mongoDB database 查询mongoDB数据库
  • Execute a .find() on the collection already in RAM that will parse through the 1000 elements looking for multiple different strings in that element 在内存中已经存在的集合上执行.find(),它将解析1000个元素,在该元素中查找多个不同的字符串

I am looking for the most performant method before I start implementing a complex .find() function. 在开始实现复杂的.find()函数之前,我正在寻找性能最高的方法。

As @Storm mentioned, 正如@Storm所说,

In a scenario where your nodeJS server has a static collection of 40mb of text loaded in memory 在您的nodeJS服务器具有40mb 静态文本加载到内存的情况下

So I suppose the data will not be changed after loaded. 所以我想数据加载后不会改变。

Before we choose any technical solution, I suggest you to do a performance load test with common MongoDB settings. 在选择任何技术解决方案之前,建议您使用通用的MongoDB设置进行性能负载测试。 Based on below conditions(you didn't mention): 根据以下条件(您没有提及):

  1. The volumn of requests from client(eg 1K/s, 10K/s,...) 来自客户端的请求量(例如1K / s,10K / s等)
  2. The target response time(eg 95% of all less than 10ms) 目标响应时间(例如,所有响应时间的95%小于10毫秒)
  3. What queries you will perform? 您将执行哪些查询?

Since 40mb 1000 documents is not a large data, MongoDB prefer to put hot data into memory to speedup the queries. 由于40mb 1000文档不是大数据,因此MongoDB倾向于将热数据放入内存中以加快查询速度。 If the common MongoDB settings can not satisfy your performance goal, you can consider: 如果常用的MongoDB设置不能满足您的性能目标,则可以考虑:

1. Improve the infrastructure software 1.改善基础架构软件

  • Try MongoDB In-Memory engine (Since the data will not be modified) 尝试使用MongoDB 内存引擎 (因为不会修改数据)
  • Try other memory based DB such as Redis(If you don't need very complex query) 尝试其他基于内存的数据库,例如Redis(如果您不需要非常复杂的查询)

2. Improve the code quality of your usage 2.提高使用代码的质量

  • Build efficient indexes in MongoDB 在MongoDB中建立有效的索引
  • Any better data model design? 还有更好的数据模型设计吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM