On this page本页内容
Each index on a collection adds some amount of overhead to the performance of write operations.集合上的每个索引都会为写操作的性能增加一定的开销。
For each 对于集合上的每个insert
or delete
write operation on a collection, MongoDB either inserts or removes the corresponding document keys from each index in the target collection. insert
或delete
写入操作,MongoDB都会从目标集合中的每个索引中插入或删除相应的文档键。An update
operation may result in updates to a subset of indexes on the collection, depending on the keys affected by the update.update
操作可能会导致对集合上的索引子集进行更新,具体取决于受更新影响的键。
In general, the performance gains that indexes provide for read operations are worth the insertion penalty. 一般来说,索引为读取操作提供的性能提升值得插入惩罚。However, in order to optimize write performance when possible, be careful when creating new indexes and evaluate the existing indexes to ensure that your queries actually use these indexes.但是,为了尽可能优化写性能,在创建新索引和评估现有索引时要小心,以确保查询实际使用这些索引。
For indexes and queries, see Query Optimization. 有关索引和查询,请参阅查询优化。For more information on indexes, see Indexes and Indexing Strategies.有关索引的更多信息,请参阅索引和索引策略。
The capability of the storage system creates some important physical limits for the performance of MongoDB's write operations. 存储系统的性能对MongoDB的写操作的性能造成了一些重要的物理限制。Many unique factors related to the storage system of the drive affect write performance, including random access patterns, disk caches, disk readahead and RAID configurations.与驱动器存储系统相关的许多独特因素都会影响写入性能,包括随机访问模式、磁盘缓存、磁盘预读和RAID配置。
Solid state drives (SSDs) can outperform spinning hard disks (HDDs) by 100 times or more for random workloads.对于随机工作负载,固态硬盘(SSD)的性能比旋转硬盘(HDD)高出100倍或更多。
Production Notes for recommendations regarding additional hardware and configuration options.有关附加硬件和配置选项的建议的生产说明。
To provide durability in the event of a crash, MongoDB uses write ahead logging to an on-disk journal. 为了在崩溃时提供持久性,MongoDB使用写前日志记录到磁盘日志中。MongoDB writes the in-memory changes first to the on-disk journal files. MongoDB首先将内存中的更改写入磁盘日志文件。If MongoDB should terminate or encounter an error before committing the changes to the data files, MongoDB can use the journal files to apply the write operation to the data files.如果MongoDB在提交对数据文件的更改之前终止或遇到错误,MongoDB可以使用日志文件对数据文件应用写操作。
While the durability assurance provided by the journal typically outweigh the performance costs of the additional write operations, consider the following interactions between the journal and performance:虽然日志提供的耐久性保证通常超过附加写入操作的性能成本,但考虑日记和性能之间的下列交互:
j option
, mongod
will decrease the duration between journal writes, which can increase the overall write load.j
选项的写关注点,mongod
将减少日志写入之间的持续时间,这可能会增加总体写负载。commitIntervalMs
run-time option. commitIntervalMs
行时选项进行配置。For additional information on journaling, see Journaling.有关日志记录的更多信息,请参阅日志记录。