了解MongoDB缓存系统 [英] understand MongoDB cache system

查看:64
本文介绍了了解MongoDB缓存系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个基本问题,但非常重要,我不确定要明白这一点.

This is a basic question, but very important, and i am not sure to really get the point.

在官方文档上,我们可以阅读

On the official documentation we can read

MongoDB将所有最近使用的数据保留在RAM中.如果您已经为查询创建了索引,并且您的工作数据集适合RAM,那么MongoDB将从内存中提供所有查询.

MongoDB keeps all of the most recently used data in RAM. If you have created indexes for your queries and your working data set fits in RAM, MongoDB serves all queries from memory.

我不确定的部分是

如果您为查询创建了索引,并且您的工作数据集适合RAM

If you have created indexes for your queries and your working data set fits in RAM

这里的索引"是什么意思?

what does mean "indexes" here?

例如,如果我更新了一个模型,然后我查询它,因为我已经更新了它,所以它现在位于RAM中,因此它将来自内存,但这在我看来并不是很清楚.

For example, if i update a model, then i query it, because i have updated it, it's now in RAM so it will come from the memory, but this is not very clear in my mind.

我们如何确定查询的数据是否来自内存?我知道MongoDB使用空闲内存来缓存有关当前空闲的内存的数据,但是有人可以进一步解释全局行为吗?

How can we be sure that datas we query will come from the memory or not? I understand that MongoDB uses the free memory to cache datas about the memory which is free on the moment, but does someone could explain further the global behavior ?

在哪种情况下,在我们的节点服务器中使用一个存储数据的变量比信任MongoDB缓存系统更好?

In which case could it be better to use a variable in our node server which store datas than trust the MongoDB cache system?

您如何在全球范围内建议使用MongoDB来获得巨大流量?

How do you globally advise to use MongoDB for huge traffic?

推荐答案

注意:这是在2013年写的,当时MongoDB还很年轻,它没有今天的功能,虽然这个答案对mmap仍然适用,但对MongoDB现在实现的其他存储技术(例如WiredTiger或Percona)则不适用.

Note: This was written back in 2013 when MongoDB was still quite young, it didn't have the features it does today, while this answer still holds true for mmap, it does not for the other storage technologies MongoDB now implements, such as WiredTiger, or Percona.

一个开始确切了解什么是索引的好地方:

A good place to start to understand exactly what is an index: http://docs.mongodb.org/manual/core/indexes/

仔细研究后,您会发现它们为什么如此好,但是,请跳过一些更复杂的问题.

After you have brushed up on that you will udersand why they are so good, however, skipping forward to some of the more intricate questions.

我们如何确定查询的数据是否来自内存?

How can we be sure that datas we query will come from the memory or not?

一种方法是查看任何查询explain()上的yields字段.这将告诉您由于数据不在RAM中,读取器产生锁定的次数.

One way is to look at the yields field on any query explain(). This will tell you how many times the reader yielded its lock because data was not in RAM.

另一种更深入的方法是查看诸如 mongostat 之类的程序,其他此类程序.这些程序将告诉您mongod上正在发生什么页面错误(何时需要将数据从磁盘分页到RAM中).

Another more indepth way is to look on programs like mongostat and other such programs. These programs will tell you about what page faults (when data needs to be paged into RAM from disk) are happening on your mongod.

我知道MongoDB使用空闲内存来缓存有关当前空闲的内存的数据,但是有人可以进一步解释全局行为吗?

I understand that MongoDB uses the free memory to cache datas about the memory which is free on the moment, but does someone could explain further the global behavior ?

这实际上是不正确的.仅仅说MongoDB可以做到这一点比较容易,但实际上却没有.实际上,操作系统和它自己的分页算法(通常是 LRU )确实可以这对于MongoDB.不过,MongoDB确实会在一段时间内缓存索引计划,因此它不必不断地检查和测试索引.

This is actually incorrect. It is easier to just say that MongoDB does this but in reality it does not. It is in fact the OS and its own paging algorithms, usually the LRU, that does this for MongoDB. MongoDB does cache index plans for a certain period of time though so that it doesn't have to constantly keep checking and testing for indexes.

在哪种情况下,在我们的节点服务器中使用一个存储数据的变量比信任MongoDB缓存系统更好?

In which case could it be better to use a variable in our node server which store datas than trust the MongoDB cache system?

不确定您的期望如何工作……我的意思是两者的作用截然不同,如果您打算在启动时将MongoDB中的数据读入应用程序到该var中,那么我绝对不会推荐它.

Not sure how you expect that to work...I mean the two do quite different things and if you intend to read your data from MongoDB into your application on startup into that var then I definitely would not recommend it.

除了用于内存管理的OS算法非常成熟和快速之外,还可以.

Besides OS algorithms for memory management are extremely mature and fast, so it is ok.

您如何在全球范围内建议使用MongoDB来获得巨大流量?

How do you globally advise to use MongoDB for huge traffic?

嗯,这是一个很大的问题.确实,我会向您推荐有关此主题的Google,但正如文档所述,您需要确保您的工作集适合RAM中的一个.

Hmm, this is such a huge question. Really I would recommend you Google a little in this subject but as the documentation states you need to ensure your working set fits into RAM for one.

这是一个很好的起点:

Here is a good starting point: What does it mean to fit "working set" into RAM for MongoDB?

这篇关于了解MongoDB缓存系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆