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. 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.有关索引和查询,请参阅查询优化。有关索引的详细信息,请参阅索引和索引策略。
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倍或更多。
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.有关日记的其他信息,请参阅日志。