The WiredTiger storage engine is the default storage engine. WiredTiger存储引擎是默认存储引擎。For existing deployments, if you do not specify the 对于现有部署,如果不指定--storageEngine or the storage.engine setting, the mongod instance can automatically determine the storage engine used to create the data files in the --dbpath or storage.dbPath.--storageEngine或storage.engine设置,mongod实例可以自动确定用于在--dbpath或storage.dbPath中创建数据文件的存储引擎。
Deployments hosted in the following environments can use the WiredTiger storage engine:在以下环境中托管的部署可以使用WiredTiger存储引擎:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
Note
All MongoDB Atlas deployments use the WiredTiger storage engine.所有MongoDB Atlas部署都使用WiredTiger存储引擎。
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
To learn more about WiredTiger memory use for deployments hosted in MongoDB Atlas, see Memory.要了解更多关于MongoDB Atlas中托管部署的WiredTiger内存使用的信息,请参阅内存。
Operation and Limitations操作和限制
The following operational notes and limitations apply to the WiredTiger engine:以下操作注意事项和限制适用于WiredTiger发动机:
You can't pin documents to the WiredTiger cache.您无法将文档固定到WiredTiger缓存。WiredTiger doesn't reserve a portion of the cache for reads and another for writes.WiredTiger不保留缓存的一部分用于读取,另一部分用于写入。WiredTiger allocates its cache to the entireWiredTiger将其缓存分配给整个mongodinstance. WiredTiger doesn't allocate cache on a per-database or per-collection level.mongod实例。WiredTiger不会在每个数据库或每个集合级别分配缓存。
Transaction (Read and Write) Concurrency事务(读写)并发
Starting in version 7.0, MongoDB uses a default algorithm to dynamically adjust the maximum number of concurrent storage engine transactions, or read and write tickets. The dynamic concurrent storage engine transaction algorithm optimizes database throughput during cluster overload.从7.0版本开始,MongoDB使用默认算法动态调整并发存储引擎事务或读写票证的最大数量。动态并发存储引擎事务算法在集群过载期间优化了数据库吞吐量。
Note
The dynamic algorithm also results in lower overall ticket usage, even under normal conditions, because the algorithm starts with a much lower baseline number of available tickets. As a result, when upgrading to MongoDB 7.0, you may observe a significant drop in ticket usage, which is expected behavior.即使在正常情况下,动态算法也会导致较低的总票使用率,因为该算法从较低的可用票基线数量开始。因此,当升级到MongoDB 7.0时,您可能会观察到票证使用率显著下降,这是预期的行为。
The maximum number of concurrent storage engine transactions, or read and write tickets, never exceeds 128 read tickets and 128 write tickets and may differ across nodes in a cluster. The maximum number of read tickets and write tickets within a single node are always equal.并发存储引擎事务或读写票证的最大数量永远不会超过128个读票证和128个写票证,并且可能因集群中的节点而异。单个节点内读取票和写入票的最大数量始终相等。
To specify a maximum number of read and write transactions, or read and write tickets, that the dynamic maximum can not exceed, use 要指定动态最大值不能超过的最大读写事务数或读写票证数,请使用storageEngineConcurrentReadTransactions and storageEngineConcurrentWriteTransactions.storageEngineConcurrentReadTransactions和storageEngineConcurrentWriteTransactions。
If you want to disable the dynamic concurrent storage engine transactions algorithm, file a support request to work with a MongoDB Technical Services Engineer.如果你想禁用动态并发存储引擎事务算法,请提交支持请求,与MongoDB技术服务工程师合作。
To view the number of concurrent read transactions (read tickets) and write transactions (write tickets) allowed in the WiredTiger storage engine, use the 要查看WiredTiger存储引擎中允许的并发读取事务(读取票)和写入事务(写入票)的数量,请使用serverStatus command and see the queues.execution response document.serverStatus命令并查看queues.execution响应文档。
Note
A low value of available in queues.execution does not indicate a cluster overload. Use the number of queued read and write tickets as an indication of cluster overload.
Document Level Concurrency
WiredTiger uses document-level concurrency control for write operations. As a result, multiple clients can modify different documents of a collection at the same time.
For most read and write operations, WiredTiger uses optimistic concurrency control. WiredTiger uses only intent locks at the global, database and collection levels. When the storage engine detects conflicts between two operations, one will incur a write conflict causing MongoDB to transparently retry that operation.
Some global operations, typically short lived operations involving multiple databases, still require a global "instance-wide" lock. Some other operations, such as renameCollection, still require an exclusive database lock in certain circumstances.
Snapshots and Checkpoints
WiredTiger uses MultiVersion Concurrency Control (MVCC). At the start of an operation, WiredTiger provides a point-in-time snapshot of the data to the operation. A snapshot presents a consistent view of the in-memory data.
When writing to disk, WiredTiger writes all the data in a snapshot to disk in a consistent way across all data files. The now-durable data act as a checkpoint in the data files. The checkpoint ensures that the data files are consistent up to and including the last checkpoint; i.e. checkpoints can act as recovery points.
MongoDB configures WiredTiger to create checkpoints, specifically, writing the snapshot data to disk at intervals of 60 seconds.
During the write of a new checkpoint, the previous checkpoint is still valid. As such, even if MongoDB terminates or encounters an error while writing a new checkpoint, upon restart, MongoDB can recover from the last valid checkpoint.
The new checkpoint becomes accessible and permanent when WiredTiger's metadata table is atomically updated to reference the new checkpoint. Once the new checkpoint is accessible, WiredTiger frees pages from the old checkpoints.
Snapshot History Retention
Starting in MongoDB 5.0, you can use the minSnapshotHistoryWindowInSeconds parameter to specify how long WiredTiger keeps the snapshot history.
Increasing the value of minSnapshotHistoryWindowInSeconds increases disk usage because the server must maintain the history of older modified values within the specified time window. The amount of disk space used depends on your workload, with higher volume workloads requiring more disk space.
MongoDB maintains the snapshot history in the WiredTigerHS.wt file, located in your specified dbPath.
Journal
WiredTiger uses a write-ahead log (i.e. journal) in combination with checkpoints to ensure data durability.
The WiredTiger journal persists all data modifications between checkpoints. If MongoDB exits between checkpoints, it uses the journal to replay all data modified since the last checkpoint. For information on the frequency with which MongoDB writes the journal data to disk, see Journaling Process.
WiredTiger journal is compressed using the snappy compression library. To specify a different compression algorithm or no compression, use the storage.wiredTiger.engineConfig.journalCompressor setting. For details on changing the journal compressor, see Change WiredTiger Journal Compressor.
Note
If a log record is less than or equal to 128 bytes, which is the minimum log record size for WiredTiger, WiredTiger does not compress that record.
Compression
With WiredTiger, MongoDB supports compression for all collections and indexes. Compression minimizes storage use at the expense of additional CPU.
By default, WiredTiger uses block compression with the snappy compression library for most collections and prefix compression for all indexes. However, the default block compression for time-series collections is zstd.
For collections, the following block compression libraries are also available:
To specify an alternate compression algorithm or no compression, use the storage.wiredTiger.collectionConfig.blockCompressor setting.
For indexes, to disable prefix compression, use the storage.wiredTiger.indexConfig.prefixCompression setting.
Compression settings are also configurable on a per-collection and per-index basis during collection and index creation. See Specify Storage Engine Options and db.collection.createIndex() storageEngine option.
For most workloads, the default compression settings balance storage efficiency and processing requirements.
The WiredTiger journal is also compressed by default. For information on journal compression, see Journal.
Memory Use内存使用
With WiredTiger, MongoDB utilizes both the WiredTiger internal cache and the filesystem cache.使用WiredTiger,MongoDB同时利用WiredTigeer内部缓存和文件系统缓存。
The default WiredTiger internal cache size is the larger of either:默认的WiredTiger内部缓存大小是以下两者中的较大值:
- 50% of (RAM - 1 GB), or
- 256 MB.
For example, on a system with a total of 4GB of RAM the WiredTiger cache uses 1.5GB of RAM (0.5 * (4 GB - 1 GB) =
1.5 GB). Conversely, on a system with a total of 1.25 GB of RAM WiredTiger allocates 256 MB to the WiredTiger cache because that is more than half of the total RAM minus one gigabyte (0.5 * (1.25 GB - 1 GB) = 128 MB < 256 MB).
Note
In some instances, such as when running in a container, the database can have memory constraints that are lower than the total system memory. In such instances, this memory limit, rather than the total system memory, is used as the maximum RAM available.在某些情况下,例如在容器中运行时,数据库的内存限制可能低于总系统内存。在这种情况下,这个内存限制,而不是整个系统内存,被用作可用的最大RAM。
To see the memory limit, see 要查看内存限制,请参阅hostInfo.system.memLimitMB.hostInfo.system.memLimitMB。
By default, WiredTiger uses Snappy block compression for all collections and prefix compression for all indexes. Compression defaults are configurable at a global level and can also be set on a per-collection and per-index basis during collection and index creation.默认情况下,WiredTiger对所有集合使用Snappy块压缩,对所有索引使用前缀压缩。压缩默认值可以在全局级别进行配置,也可以在集合和索引创建期间根据每个集合和每个索引进行设置。
Different representations are used for data in the WiredTiger internal cache versus the on-disk format:与磁盘格式相比,WiredTiger内部缓存中的数据使用了不同的表示方式:
Data in the filesystem cache is the same as the on-disk format, including benefits of any compression for data files. The filesystem cache is used by the operating system to reduce disk I/O.文件系统缓存中的数据与磁盘上的格式相同,包括对数据文件进行任何压缩的好处。操作系统使用文件系统缓存来减少磁盘I/O。Indexes loaded in the WiredTiger internal cache have a different data representation to the on-disk format, but can still take advantage of index prefix compression to reduce RAM usage. Index prefix compression deduplicates common prefixes from indexed fields.加载在WiredTiger内部缓存中的索引具有与磁盘上格式不同的数据表示形式,但仍然可以利用索引前缀压缩来减少RAM使用。索引前缀压缩可消除索引字段中的常见前缀的重复。Collection data in the WiredTiger internal cache is uncompressed and uses a different representation from the on-disk format. Block compression can provide significant on-disk storage savings, but data must be uncompressed to be manipulated by the server.WiredTiger内部缓存中的集合数据是未压缩的,并使用与磁盘格式不同的表示形式。块压缩可以显著节省磁盘存储空间,但数据必须解压缩才能由服务器操作。
With the filesystem cache, MongoDB automatically uses all free memory that is not used by the WiredTiger cache or by other processes.使用文件系统缓存,MongoDB会自动使用WiredTiger缓存或其他进程未使用的所有空闲内存。
To adjust the size of the WiredTiger internal cache, see --wiredTigerCacheSizeGB and storage.wiredTiger.engineConfig.cacheSizeGB. Avoid increasing the WiredTiger internal cache size above its default value. If your use case requires increased internal cache size, see --wiredTigerCacheSizePct and storage.wiredTiger.engineConfig.cacheSizePct.