Write Operation Performance写操作性能

On this page本页内容

Indexes索引

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. 对于集合上的每个insertdelete写入操作,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操作可能会导致对集合上的索引子集进行更新,具体取决于受更新影响的键。

Note注意

MongoDB only updates a sparse or partial index if the documents involved in a write operation are included in the index.如果写操作中涉及的文档包含在索引中,MongoDB只会更新稀疏索引或部分索引。

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.有关索引的更多信息,请参阅索引索引策略

Storage Performance存储性能

Hardware硬件

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倍或更多。

Tip提示
See: 参阅

Production Notes for recommendations regarding additional hardware and configuration options.有关附加硬件和配置选项的建议的生产说明

Journaling日记

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:虽然日志提供的耐久性保证通常超过附加写入操作的性能成本,但考虑日记和性能之间的下列交互:

  • If the journal and the data file reside on the same block device, the data files and the journal may have to contend for a finite number of available I/O resources. 如果日志和数据文件位于同一块设备上,则数据文件和日志可能必须争夺有限数量的可用I/O资源。Moving the journal to a separate device may increase the capacity for write operations.将日志移动到单独的设备可能会增加写入操作的容量。
  • If applications specify write concerns that include the j option, mongod will decrease the duration between journal writes, which can increase the overall write load.如果应用程序指定了包含j选项写关注点mongod将减少日志写入之间的持续时间,这可能会增加总体写负载。
  • The duration between journal writes is configurable using the commitIntervalMs run-time option. 日志写入之间的持续时间可使用commitIntervalMs行时选项进行配置。Decreasing the period between journal commits will increase the number of write operations, which can limit MongoDB's capacity for write operations. 减少日志提交之间的时间间隔将增加写入操作的数量,这可能会限制MongoDB的写入操作能力。Increasing the amount of time between journal commits may decrease the total number of write operation, but also increases the chance that the journal will not record a write operation in the event of a failure.增加日志提交之间的时间间隔可能会减少写入操作的总数,但也会增加日志在发生故障时不记录写入操作的可能性。

For additional information on journaling, see Journaling.有关日志记录的更多信息,请参阅日志记录

←  Optimize Query PerformanceExplain Results →