On this page本页内容
For the fastest processing, ensure that your indexes fit entirely in RAM so that the system can avoid reading the index from disk.为了获得最快的处理速度,请确保索引完全适合RAM,这样系统就可以避免从磁盘读取索引。
To check the size of your indexes, use the 要检查索引的大小,请使用db.collection.totalIndexSize()
helper, which returns data in bytes:db.collection.totalIndexSize()
帮助程序,它以字节为单位返回数据:
The above example shows an index size of almost 4.3 gigabytes. 上面的示例显示索引大小几乎为4.3 GB。To ensure this index fits in RAM, you must not only have more than that much RAM available but also must have RAM available for the rest of the working set. 为了确保这个索引适合RAM,您不仅必须有超过那个数量的可用RAM,还必须为工作集的其余部分提供可用RAM。Also remember:还要记住:
If you have and use multiple collections, you must consider the size of all indexes on all collections. 如果您拥有并使用多个集合,则必须考虑所有集合上的所有索引的大小。The indexes and the working set must be able to fit in memory at the same time.索引和工作集必须能够同时放入内存。
There are some limited cases where indexes do not need to fit in memory. 在某些有限的情况下,索引不需要放入内存。See Indexes that Hold Only Recent Values in RAM.请参阅仅保存RAM中最近值的索引。
See also参阅
Indexes do not have to fit entirely into RAM in all cases. 在所有情况下,索引不必完全适合RAM。If the value of the indexed field increments with every insert, and most queries select recently added documents; then MongoDB only needs to keep the parts of the index that hold the most recent or “right-most” values in RAM. 如果索引字段的值随着每次插入而增加,并且大多数查询选择最近添加的文档;然后MongoDB只需要在RAM中保留索引中保存最新或“最右边”值的部分。This allows for efficient index use for read and write operations and minimize the amount of RAM required to support the index.这使得读写操作能够高效地使用索引,并将支持索引所需的RAM量降至最低。