Docs HomeMongoDB Manual

Production Notes生产说明

This page details system configurations that affect MongoDB, especially when running in production.本页详细介绍了影响MongoDB的系统配置,尤其是在生产环境中运行时。

Note

MongoDB Atlas is a cloud-hosted database-as-a-service. MongoDB Cloud Manager, a hosted service, and Ops Manager, an on-premise solution, provide monitoring, backup, and automation of MongoDB instances. MongoDB Atlas是一个云托管的数据库即服务。托管服务MongoDB Cloud Manager和内部部署解决方案Ops Manager提供MongoDB实例的监控、备份和自动化。For documentation, see Atlas documentation, the MongoDB Cloud Manager documentation and Ops Manager documentation有关文档,请参阅Atlas文档MongoDB Cloud Manager文档Ops Manager文档

Platform Support平台支持

For running in production, refer to the Recommended Platforms for operating system recommendations.有关在生产中运行的操作系统建议,请参阅推荐的平台

Platform Support Notes平台支持说明

x86_64

MongoDB requires the following minimum x86_64 microarchitectures: MongoDB至少需要以下x86_64微体系结构:[5]

  • For Intel x86_64, MongoDB requires one of:对于Intel x86_64,MongoDB需要以下之一:

    • a Sandy Bridge or later Core processor, orSandy Bridge或更高版本的Core处理器,或
    • a Tiger Lake or later Celeron or Pentium processor.Tiger Lake或更高版本的赛扬或奔腾处理器。
  • For AMD x86_64, MongoDB requires:对于AMD x86_64,MongoDB需要:

    • a Bulldozer or later processor.推土机或更高版本的处理器。

Starting in MongoDB 5.0, mongod, mongos, and the legacy mongo shell no longer support x86_64 platforms which do not meet this minimum microarchitecture requirement.从MongoDB 5.0开始,mongodmongos和遗留的mongoshell不再支持不满足最低微体系结构要求的x86_64平台。

  • MongoDB only supports Oracle Linux running the Red Hat Compatible Kernel (RHCK). MongoDB仅支持运行Red Hat Compatible Kernel(RHCK)的Oracle Linux。MongoDB does not support the Unbreakable Enterprise Kernel (UEK).MongoDB不支持Unbreakable Enterprise Kernel(UEK)。
  • MongoDB 5.0 requires use of the AVX instruction set, available on select Intel and AMD processors.MongoDB 5.0需要使用AVX指令集,可在选定的英特尔和AMD处理器上使用。

ARM64

MongoDB on arm64 requires the ARMv8.2-A or later microarchitecture.arm64上的MongoDB需要ARMv8.2-A或更高版本的微体系结构。

Starting in MongoDB 5.0, mongod, mongos, and the legacy mongo shell no longer support arm64 platforms which do not meet this minimum microarchitecture requirement.从MongoDB 5.0开始,mongodmongos和遗留的mongoshell不再支持不满足最低微体系结构要求的arm64平台。

Platform Support Matrix平台支持矩阵

Platform平台Architecture建筑学Edition版本7.06.05.04.4
Amazon Linux 2023x86_64Enterprise6.2.0+
Amazon Linux 2023x86_64Community6.2.0+
Amazon Linux V2x86_64Enterprise
Amazon Linux V2x86_64Community
Debian 12x86_64Enterprise
Debian 11x86_64Enterprise5.0.8+
Debian 11x86_64Enterprise5.0.8+
Debian 11x86_64Community5.0.8+
Debian 10x86_64Enterprise
Debian 10x86_64Community
Debian 9x86_64Enterprise
Debian 9x86_64Community
RHEL/CentOS Stream/Oracle Linux/Rocky/Alma 9.0+x86_64Enterprise6.0.4+
RHEL/CentOS Stream/Oracle Linux/Rocky/Alma 9.0+x86_64Community6.0.4+
RHEL/CentOS Stream/Oracle Linux/Rocky/Alma 8.0+x86_64Enterprise
RHEL/CentOS Stream/Oracle Linux/Rocky/Alma 8.0+x86_64Community
RHEL/CentOS/Oracle Linux 7.0+x86_64Enterprise
RHEL/CentOS/Oracle Linux 7.0+x86_64Community
RHEL/CentOS/Oracle Linux 6.2+x86_64Enterprise
RHEL/CentOS/Oracle Linux 6.2+x86_64Community
SLES 15x86_64Enterprise
SLES 15x86_64Community
SLES 12x86_64Enterprise
SLES 12x86_64Community
Ubuntu 22.04x86_64Enterprise6.0.4+
Ubuntu 22.04x86_64Community6.0.4+
Ubuntu 20.04x86_64Enterprise
Ubuntu 20.04x86_64Community
Ubuntu 18.04x86_64Enterprise
Ubuntu 18.04x86_64Community
Ubuntu 16.04x86_64Enterprise
Ubuntu 16.04x86_64Community
Windows 11x86_64Enterprise
Windows 11x86_64Community
Windows Server 2022x86_64Enterprise
Windows Server 2022x86_64Community
Windows Server 2019x86_64Enterprise
Windows Server 2019x86_64Community
Windows 7/8/8.1x86_64Enterprise
Windows 7/8/8.1x86_64Community
Windows Server 2008R2/2012/2012R2x86_64Enterprise
Windows Server 2008R2/2012/2012R2x86_64Community
Windows 10 / Server 2016x86_64Enterprise
Windows 10 / Server 2016x86_64Community
macOS 13x86_64Enterprise
macOS 13x86_64Community
macOS 12x86_64Enterprise
macOS 12x86_64Community
macOS 11x86_64Enterprise
macOS 11x86_64Community
macOS 10.15x86_64Enterprise
macOS 10.15x86_64Community
macOS 10.14x86_64Enterprise
macOS 10.14x86_64Community
macOS 10.13x86_64Enterprise
macOS 10.13x86_64Community
macOS 13arm64Enterprise
macOS 13arm64Community
macOS 12arm64Enterprise
macOS 12arm64Community
macOS 11arm64Enterprise
macOS 11arm64Community
Amazon Linux 2023arm64Enterprise6.2.0+
Amazon Linux 2023arm64Community6.2.0+
Amazon Linux 2arm64Enterprise4.4.4+
Amazon Linux 2arm64Community4.4.4+
RHEL/CentOS/Rocky/Alma 9arm64Enterprise
RHEL/CentOS/Rocky/Alma 9arm64Community
RHEL/CentOS/Rocky/Alma 8arm64Enterprise4.4.4+
RHEL/CentOS/Rocky/Alma 8arm64Community4.4.4+
Ubuntu 22.04arm64Enterprise6.0.4+
Ubuntu 22.04arm64Community6.0.4+
Ubuntu 20.04arm64Enterprise
Ubuntu 20.04arm64Community
Ubuntu 18.04arm64Enterprise
Ubuntu 18.04arm64Community
Ubuntu 16.04arm64Enterprise
Ubuntu 16.04arm64Community
RHEL/CentOS Stream/Rocky/Alma 9ppc64leEnterprise
RHEL/CentOS Stream/Rocky/Alma 8ppc64leEnterprise
RHEL/CentOS 7ppc64leEnterprise6.0.7+
Ubuntu 18.04ppc64leEnterprise4.4.0 - 4.4.10
RHEL/CentOS Stream/Rocky/Alma 9s390xEnterprise
RHEL/CentOS Stream/Rocky/Alma 9s390xCommunity
RHEL/CentOS Stream/Rocky/Alma 8s390xEnterprise5.0.9+
RHEL/CentOS Stream/Rocky/Alma 8s390xCommunity
RHEL/CentOS 7s390xEnterprise
RHEL/CentOS 7s390xCommunity
RHEL/CentOS 6s390xEnterprise
RHEL/CentOS 6s390xCommunity
SLES 12s390xEnterprise4.4.0 - 4.4.6
SLES 12s390xCommunity4.4.0 - 4.4.6
Ubuntu 18.04s390xEnterprise4.4.0 - 4.4.6
Ubuntu 18.04s390xCommunity4.4.0 - 4.4.6
[1] MongoDB versions 5.0 and greater are tested against SLES 12 service pack 5. MongoDB 5.0及更高版本针对SLES 12 service pack 5进行了测试。Earlier versions of MongoDB are tested against SLES 12 with no service pack.MongoDB的早期版本是在没有service pack的情况下针对SLES12进行测试的。
[2] MongoDB versions 7.0 and later are tested against SLES 15 service pack 4. MongoDB 7.0及更高版本针对SLES 15 service pack 4进行了测试。Earlier versions of MongoDB are tested against SLES 15 with no service pack.MongoDB的早期版本是在没有service pack的情况下针对SLES 15进行测试的。
[3] MongoDB version 7.0 is built and tested against RHEL 7.9. MongoDB 7.0版是针对RHEL 7.9构建和测试的。Earlier versions of MongoDB are tested against RHEL 7 and assume forward compatibility.MongoDB的早期版本针对RHEL7进行了测试,并假定具有前向兼容性。

Recommended Platforms推荐的平台

While MongoDB supports a variety of platforms, the following operating systems are recommended for production use on x86_64 architecture:虽然MongoDB支持多种平台,但建议在x86_64体系结构上生产使用以下操作系统:

  • Amazon Linux 2
  • Debian 10
  • RHEL / CentOS 7 and 8 [6]
  • SLES 12 and 15
  • Ubuntu LTS 20.04 and 22.04
  • Windows Server 2016 and 2019
[4] MongoDB only supports Oracle Linux running the Red Hat Compatible Kernel (RHCK). MongoDB does not support the Unbreakable Enterprise Kernel (UEK).MongoDB仅支持运行Red Hat Compatible Kernel(RHCK)的Oracle Linux。MongoDB不支持Unbreakable Enterprise Kernel(UEK)。
[5] MongoDB 5.0 requires use of the AVX instruction set, available on select Intel and AMD processors.MongoDB 5.0需要使用AVX指令集,可在选定的英特尔和AMD处理器上使用。
[6] MongoDB on-premises products released for RHEL version 8.0+ are compatible with and supported on Rocky Linux version 8.0+ and AlmaLinux version 8.0+, contingent upon those distributions meeting their obligation to deliver full RHEL compatibility.为RHEL 8.0+版发布的MongoDB内部部署产品与Rocky Linux 8.0+版和AlmaLinux 8.0+版本兼容并受其支持,这取决于这些发行版是否履行了提供完全RHEL兼容性的义务。

Use the Latest Stable Packages使用最新的稳定软件包

Be sure you have the latest stable release.请确保您拥有最新的稳定版本。

All MongoDB releases are available on the MongoDB Download Center page. 所有MongoDB版本都可以在MongoDB下载中心页面上找到。The MongoDB Download Center is a good place to verify the current stable release, even if you are installing via a package manager.MongoDB下载中心是验证当前稳定版本的好地方,即使您是通过包管理器进行安装。

For other MongoDB products, refer either to the MongoDB Download Center page or their respective documentation.对于其他MongoDB产品,请参阅MongoDB下载中心页面或其各自的文档。

MongoDB dbPath

The files in the dbPath directory must correspond to the configured storage engine. dbPath目录中的文件必须与配置的存储引擎相对应。mongod will not start if dbPath contains data files created by a storage engine other than the one specified by --storageEngine.如果dbPath包含由--storageEngine指定的存储引擎以外的存储引擎创建的数据文件,则mongod不会启动。

mongod must possess read and write permissions for the specified dbPath.必须拥有指定dbPath的读写权限。

If you use an antivirus (AV) scanner or an endpoint detection and response (EDR) scanner, configure your scanner to exclude the database storage path and the database log path from the scan.如果使用防病毒(AV)扫描仪或端点检测和响应(EDR)扫描仪,请将扫描仪配置为从扫描中排除数据库存储路径数据库日志路径

The data files in the database storage path are compressed. Additionally, if you use the encrypted storage engine, the data files are also encrypted. 数据库存储路径中的数据文件被压缩。此外,如果使用加密存储引擎,数据文件也会被加密。The I/O and CPU costs to scan these files may significantly decrease performance without providing any security benefits.扫描这些文件的I/O和CPU成本可能会显著降低性能,但不会带来任何安全优势。

If you don't exclude the directories in your database storage path and database log path, the scanner could quarantine or delete important files. Missing or quarantined files can corrupt your database and crash your MongoDB instance.如果不排除数据库存储路径和数据库日志路径中的目录,扫描仪可能会隔离或删除重要文件。丢失或隔离的文件可能会损坏数据库并使MongoDB实例崩溃。

Concurrency并发

WiredTiger

WiredTiger supports concurrent access by readers and writers to the documents in a collection. 支持读者和作者同时访问集合中的文档。Clients can read documents while write operations are in progress, and multiple threads can modify different documents in a collection at the same time.客户端可以在写入操作进行时读取文档,多个线程可以同时修改集合中的不同文档。

Tip

See also: 另请参阅:

Allocate Sufficient RAM and CPU provides information about how WiredTiger takes advantage of multiple CPU cores and how to improve operation throughput.分配足够的RAM和CPU提供了有关WiredTiger如何利用多个CPU核心以及如何提高操作吞吐量的信息。

Data Consistency数据一致性

Journaling日记

MongoDB uses write ahead logging to an on-disk journal. MongoDB使用写前日志记录到磁盘上的日志Journaling guarantees that MongoDB can quickly recover write operations that were written to the journal but not written to data files in cases where mongod terminated due to a crash or other serious failure. See Journaling for more information.日志可以保证MongoDB在mongod因崩溃或其他严重故障而终止的情况下,可以快速恢复写入日志但未写入数据文件的写入操作。有关详细信息,请参阅日志记录

Read Concern读取关注

Starting in MongoDB 3.6, you can use causally consistent sessions to read your own writes, if the writes request acknowledgement.从MongoDB 3.6开始,如果写入请求确认,您可以使用因果一致会话来读取自己的写入。

Prior to MongoDB 3.6, in order to read your own writes you must issue your write operation with { w: "majority" } write concern, and then issue your read operation with primary read preference, and either "majority" or "linearizable" read concern.在MongoDB 3.6之前,为了读取您自己的写入,您必须发出具有{ w: "majority" }写入关注的写入操作,然后发出具有primary读取偏好的读取操作,以及"majority""linearizable"读取关注。

Write Concern撰写关注事项

Write Concern撰写关注事项 describes the level of acknowledgement requested from MongoDB for write operations. 描述了MongoDB为写入操作请求的确认级别。The level of the write concerns affects how quickly the write operation returns. 写入关注的级别会影响写操作返回的速度。When write operations have a weak write concern, they return quickly. 当写操作存在弱写入关注时,它们会很快返回。With stronger write concerns, clients must wait after sending a write operation until MongoDB confirms the write operation at the requested write concern level. 对于更强的写入关注,客户端必须在发送写操作后等待,直到MongoDB在请求的写入关注级别确认写操作。With insufficient write concerns, write operations may appear to a client to have succeeded, but may not persist in some cases of server failure.如果没有足够的写入关注,写操作在客户端看来可能已经成功,但在某些服务器故障的情况下可能不会持续。

See the Write Concern document for more information about choosing an appropriate write concern level for your deployment.有关为部署选择适当的写入关注级别的详细信息,请参阅写入关注文档。

Networking网络

Use Trusted Networking Environments使用受信任的网络环境

Always run MongoDB in a trusted environment, with network rules that prevent access from all unknown machines, systems, and networks. 始终在受信任的环境中运行MongoDB,使用网络规则防止来自所有未知机器、系统和网络的访问。As with any sensitive system that is dependent on network access, your MongoDB deployment should only be accessible to specific systems that require access, such as application servers, monitoring services, and other MongoDB components.与任何依赖网络访问的敏感系一致性样,您的MongoDB部署应该只能对需要访问的特定系统进行访问,例如应用程序服务器、监控服务和其他MongoDB组件。

Important

By default, authorization is not enabled, and mongod assumes a trusted environment. 默认情况下,不启用authorization,并且mongod假定一个受信任的环境。Enable authorization mode as needed. 根据需要启用authorization模式。For more information on authentication mechanisms supported in MongoDB as well as authorization in MongoDB, see Authentication and Role-Based Access Control.有关MongoDB支持的身份验证机制以及MongoDB中的授权的更多信息,请参阅身份验证基于角色的访问控制

For additional information and considerations on security, refer to the documents in the Security Section, specifically:有关安全的更多信息和注意事项,请参阅安全部分的文件,特别是:

For Windows users, consider the Windows Server Technet Article on TCP Configuration when deploying MongoDB on Windows.对于Windows用户,在Windows上部署MongoDB时,请考虑Windows Server Technet关于TCP配置的文章。

Disable HTTP Interface禁用HTTP接口

Changed in version 3.6.3.6版更改。MongoDB 3.6 removes the deprecated HTTP interface and REST API to MongoDB.MongoDB 3.6删除了MongoDB中不推荐使用的HTTP接口和REST API。

Earlier versions of MongoDB provide an HTTP interface to check the status of the server and, optionally, run queries. 早期版本的MongoDB提供了一个HTTP接口来检查服务器的状态,并可以选择运行查询。The HTTP interface is disabled by default. Do not enable the HTTP interface in production environments.默认情况下,HTTP接口处于禁用状态。不要在生产环境中启用HTTP接口。

Manage Connection Pool Sizes管理连接池大小

Avoid overloading the connection resources of a mongod or mongos instance by adjusting the connection pool size to suit your use case. 通过调整连接池大小以适应您的用例,避免mongodmongos实例的连接资源过载。Start at 110-115% of the typical number of current database requests, and modify the connection pool size as needed. 从当前数据库请求的典型数量的110-115%开始,并根据需要修改连接池大小。Refer to the Connection Pool Options for adjusting the connection pool size.请参阅连接池选项以调整连接池大小。

The connPoolStats command returns information regarding the number of open connections to the current database for mongos and mongod instances in sharded clusters.connPoolStats命令返回关于分片集群中mongosmongod实例到当前数据库的打开连接数的信息。

See also Allocate Sufficient RAM and CPU.另请参阅分配足够的RAM和CPU

Hardware Considerations硬件注意事项

MongoDB is designed specifically with commodity hardware in mind and has few hardware requirements or limitations. MongoDB是专门考虑到商品硬件而设计的,几乎没有硬件需求或限制。MongoDB's core components run on little-endian hardware, primarily x86/x86_64 processors. Client libraries (i.e. drivers) can run on big or little endian systems.MongoDB的核心组件运行在little-endian硬件上,主要是x86/x8_64处理器。客户端库(即驱动程序)可以在大端系统或小端系统上运行。

Allocate Sufficient RAM and CPU分配足够的RAM和CPU

At a minimum, ensure that each mongod or mongos instance has access to two real cores or one multi-core physical CPU.至少,确保每个mongodmongos实例都可以访问两个实核或一个多核物理CPU。

WiredTiger

The WiredTiger storage engine is multithreaded and can take advantage of additional CPU cores. WiredTiger存储引擎是多线程的,可以利用额外的CPU内核。Specifically, the total number of active threads (i.e. concurrent operations) relative to the number of available CPUs can impact performance:具体来说,活动线程的总数(即并发操作)相对于可用CPU的数量会影响性能:

  • Throughput increases as the number of concurrent active operations increases up to the number of CPUs.吞吐量随着并发活动操作的数量增加到CPU的数量而增加
  • Throughput decreases as the number of concurrent active operations exceeds the number of CPUs by some threshold amount.当并发活动操作的数量超过CPU的数量某个阈值时,吞吐量会降低

The threshold depends on your application. 阈值取决于您的应用程序。You can determine the optimum number of concurrent active operations for your application by experimenting and measuring throughput. 您可以通过试验和测量吞吐量来确定应用程序的最佳并发活动操作数。The output from mongostat provides statistics on the number of active reads/writes in the (ar|aw) column.mongostat的输出提供了(ar|aw)列中活动读/写次数的统计信息。

With WiredTiger, MongoDB utilizes both the WiredTiger internal cache and the filesystem cache.有了WiredTiger,MongoDB既利用了WiredTinger内部缓存,也利用了文件系统缓存。

Starting in MongoDB 3.4, the default WiredTiger internal cache size is the larger of either:从MongoDB 3.4开始,默认的WiredTiger内部缓存大小是以下两者中较大的一个:

  • 50% of (RAM - 1 GB), or
  • 256 MB.

For example, on a system with a total of 4GB of RAM the WiredTiger cache will use 1.5GB of RAM (0.5 * (4 GB - 1 GB) = 1.5 GB). 例如,在总内存为4GB的系统上,WiredTiger缓存将使用1.5GB的RAM(0.5 * (4 GB - 1 GB) = 1.5 GB)。Conversely, a system with a total of 1.25 GB of RAM will allocate 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).相反,总RAM为1.25 GB的系统将为WiredTiger缓存分配256 MB,因为这超过了总RAM的一半减去1 GB(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. 默认情况下,WiredTiger对所有集合使用Snappy块压缩,对所有索引使用前缀压缩。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.压缩默认值可以在全局级别进行配置,也可以在集合和索引创建期间按每个集合和每个索引进行设置。

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. WiredTiger内部缓存中加载的索引具有与磁盘上格式不同的数据表示形式,但仍然可以利用索引前缀压缩来减少RAM的使用。Index prefix compression deduplicates common prefixes from indexed fields.索引前缀压缩从索引字段中消除常见前缀的重复。
  • Collection data in the WiredTiger internal cache is uncompressed and uses a different representation from the on-disk format. WiredTiger内部缓存中的采集数据未压缩,使用不同于磁盘格式的表示形式。Block compression can provide significant on-disk storage savings, but data must be uncompressed to be manipulated by the server.块压缩可以显著节省磁盘上的存储空间,但数据必须经过压缩才能由服务器操作。

Via 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 storage.wiredTiger.engineConfig.cacheSizeGB and --wiredTigerCacheSizeGB. Avoid increasing the WiredTiger internal cache size above its default value.要调整WiredTiger内部缓存的大小,请参阅storage.wiredTiger.engineConfig.cacheSizeGB--wiredTigerCacheSizeGB。避免将WiredTiger内部缓存大小增加到其默认值以上。

Note

The storage.wiredTiger.engineConfig.cacheSizeGB limits the size of the WiredTiger internal cache. storage.wiredTiger.engineConfig.cacheSizeGB限制了WiredTiger内部缓存的大小。The operating system will use the available free memory for filesystem cache, which allows the compressed MongoDB data files to stay in memory. 操作系统将使用可用的空闲内存进行文件系统缓存,这允许压缩的MongoDB数据文件留在内存中。In addition, the operating system will use any free RAM to buffer file system blocks and file system cache.此外,操作系统将使用任何空闲的RAM来缓冲文件系统块和文件系统缓存。

To accommodate the additional consumers of RAM, you may have to decrease WiredTiger internal cache size.为了容纳更多的RAM消耗者,您可能需要减小WiredTiger内部缓存的大小。

The default WiredTiger internal cache size value assumes that there is a single mongod instance per machine. 默认的WiredTiger内部缓存大小值假定每台机器有一个mongod实例。If a single machine contains multiple MongoDB instances, then you should decrease the setting to accommodate the other mongod instances.如果一台机器包含多个MongoDB实例,那么应该减少设置以容纳其他mongod实例。

If you run mongod in a container (e.g. lxc, cgroups, Docker, etc.) that does not have access to all of the RAM available in a system, you must set storage.wiredTiger.engineConfig.cacheSizeGB to a value less than the amount of RAM available in the container. 如果在无法访问系统中所有可用RAM的容器(例如lxccgroups、Docker等)中运行mongod,则必须将storage.wiredTiger.engineConfig.cacheSizeGB设置为小于容器中可用RAM量的值。The exact amount depends on the other processes running in the container. See memLimitMB.确切的数量取决于容器中运行的其他进程。请参阅memLimitMB

To view statistics on the cache and eviction rate, see the wiredTiger.cache field returned from the serverStatus command.要查看缓存和逐出率的统计信息,请参阅serverStatus命令返回的wiredTiger.cache字段。

Compression and Encryption压缩和加密

When using encryption, CPUs equipped with AES-NI instruction-set extensions show significant performance advantages. 当使用加密时,配备AES-NI指令集扩展的CPU显示出显著的性能优势。If you are using MongoDB Enterprise with the Encrypted Storage Engine, choose a CPU that supports AES-NI for better performance.如果您将MongoDB Enterprise与加密存储引擎一起使用,请选择支持AES-NI的CPU以获得更好的性能。

Tip

See also: 另请参阅:

Concurrency并发

Use Solid State Disks (SSDs)使用固态磁盘(SSD)

MongoDB has good results and a good price-performance ratio with SATA SSD (Solid State Disk).MongoDB使用SATA SSD(固态硬盘)具有良好的性能和性价比。

Use SSD if available and economical.如果可用且经济,请使用SSD。

Commodity (SATA) spinning drives are often a good option, as the random I/O performance increase with more expensive spinning drives is not that dramatic (only on the order of 2x). Using SSDs or increasing RAM may be more effective in increasing I/O throughput.商品(SATA)旋转驱动器通常是一个不错的选择,因为随着更昂贵的旋转驱动器,随机I/O性能的提高并没有那么显著(只有2倍的数量级)。使用SSD或增加RAM可能更有效地提高I/O吞吐量。

MongoDB and NUMA HardwareMongoDB和NUMA硬件

Running MongoDB on a system with Non-Uniform Memory Access (NUMA) can cause a number of operational problems, including slow performance for periods of time and high system process usage.在具有非一致性内存访问(NUMA)的系统上运行MongoDB可能会导致许多操作问题,包括一段时间内性能缓慢和系统进程使用率高。

When running MongoDB servers and clients on NUMA hardware, you should configure a memory interleave policy so that the host behaves in a non-NUMA fashion. 当在NUMA硬件上运行MongoDB服务器和客户端时,应该配置一个内存交错策略,以便主机以非NUMA的方式运行。MongoDB checks NUMA settings on start up when deployed on Linux (since version 2.0) and Windows (since version 2.6) machines. MongoDB在Linux(自2.0版起)和Windows(自2.6版起)机器上部署时,会在启动时检查NUMA设置。If the NUMA configuration may degrade performance, MongoDB prints a warning.如果NUMA配置可能会降低性能,MongoDB会打印一条警告。

Tip

See also: 另请参阅:

  • The MySQL "swap insanity" problem and the effects of NUMA post, which describes the effects of NUMA on databases. MySQL“交换疯狂”问题和NUMA帖子的影响,该帖子描述了NUMA对数据库的影响。The post introduces NUMA and its goals, and illustrates how these goals are not compatible with production databases. 这篇文章介绍了NUMA及其目标,并说明了这些目标如何与生产数据库不兼容。Although the blog post addresses the impact of NUMA for MySQL, the issues for MongoDB are similar.尽管这篇博客文章讨论了NUMA对MySQL的影响,但MongoDB的问题是相似的。
  • NUMA: An Overview.

Configuring NUMA on Windows在Windows上配置NUMA

On Windows, memory interleaving must be enabled through the machine's BIOS. Consult your system documentation for details.在Windows上,必须通过机器的BIOS启用内存交错。有关详细信息,请参阅系统文档。

Configuring NUMA on Linux在Linux上配置NUMA

On Linux, you must disable zone reclaim and also ensure that your mongod and mongos instances are started by numactl, which is generally configured through your platform's init system. 在Linux上,您必须禁用区域回收,并确保您的mongodmongos实例由numactl启动,numactl通常通过平台的init系统进行配置。You must perform both of these operations to properly disable NUMA for use with MongoDB.您必须执行这两个操作才能正确地禁用NUMA以便与MongoDB一起使用。

  1. Disable zone reclaim with one of the following commands:使用以下命令之一禁用区域回收

    echo 0 | sudo tee /proc/sys/vm/zone_reclaim_mode
    sudo sysctl -w vm.zone_reclaim_mode=0
  2. Ensure that mongod and mongos are started by numactl. This is generally configured through your platform's init system. 确保mongodmongos是由numactl启动的。这通常是通过平台的init系统进行配置的。Run the following command to determine which init system is in use on your platform:运行以下命令以确定平台上正在使用哪个init系统:

    ps --no-headers -o comm 1
    • If "systemd", your platform uses the systemd init system, and you must follow the steps in the systemd tab below to edit your MongoDB service file(s).如果是“systemd”,则您的平台使用systemd-init系统,您必须按照下面systemd选项卡中的步骤编辑MongoDB服务文件。
    • If "init", your platform uses the SysV Init system, and you do not need to perform this step. 如果“init”,则您的平台使用SysV init系统,并且您不需要执行此步骤。The default MongoDB init script for SysV Init includes the necessary steps to start MongoDB instances via numactl by default.SysV init的默认MongoDB init脚本包括默认情况下通过numactl启动MongoDB实例的必要步骤。
    • If you manage your own init scripts (i.e. you are not using either of these init systems), you must follow the steps in the Custom init scripts tab below to edit your custom init script(s).如果您管理自己的init脚本(即,您没有使用这两个init系统中的任何一个),则必须按照下面的Custom init scripts选项卡中的步骤编辑您的自定义init脚本。

    You must use numactl to start each of your mongod instances, including all config servers, mongos instances, and clients. Edit the default systemd service file for each as follows:您必须使用numactl来启动每个mongod实例,包括所有配置服务器mongos实例和客户端。按如下方式编辑每个的默认systemd服务文件:

    1. Copy the default MongoDB service file:复制默认的MongoDB服务文件:

      sudo cp /lib/systemd/system/mongod.service /etc/systemd/system/
    2. Edit the /etc/systemd/system/mongod.service file, and update the ExecStart statement to begin with:编辑/etc/systemd/system/mongod.service文件,并更新ExecStart语句,使其以以下开头:

      /usr/bin/numactl --interleave=all
      Example

      If your existing ExecStart statement reads:如果现有的ExecStart语句为:

      ExecStart=/usr/bin/mongod --config /etc/mongod.conf

      Update that statement to read:将该声明更新为:

      ExecStart=/usr/bin/numactl --interleave=all /usr/bin/mongod --config /etc/mongod.conf
    3. Apply the change to systemd:将更改应用于systemd

      sudo systemctl daemon-reload
    4. Restart any running mongod instances:重新启动任何正在运行的mongod实例:

      sudo systemctl stop mongod
      sudo systemctl start mongod
    5. If applicable, repeat these steps for any mongos instances.如果适用,请对任何mongos实例重复这些步骤。

    You must use numactl to start each of your mongod instances, including all config servers, mongos instances, and clients.您必须使用numactl来启动每个mongod实例,包括所有配置服务器mongos实例和客户端。

    1. Install numactl for your platform if not already installed. Refer to the documentation for your operating system for information on installing the numactl package.如果尚未安装,请为您的平台安装numactl。有关安装numactl软件包的信息,请参阅操作系统的文档。

    2. Configure each of your custom init scripts to start each MongoDB instance via numactl:配置每个自定义init脚本,通过numactl启动每个MongoDB实例:

      numactl --interleave=all <path> <options>

      Where <path> is the path to the program you are starting and <options> are any optional arguments to pass to that program.其中<path>是要启动的程序的路径,<options>是要传递给该程序的任何可选参数。

      Example
      numactl --interleave=all /usr/local/bin/mongod -f /etc/mongod.conf

For more information, see the Documentation for /proc/sys/vm/*.有关更多信息,请参阅Documentation for /proc/sys/vm/*的文档。

Disk and Storage Systems磁盘和存储系统

Swap

MongoDB performs best where swapping can be avoided or kept to a minimum, as retrieving data from swap will always be slower than accessing data in RAM. MongoDB在可以避免或尽量减少交换的地方表现最好,因为从交换中检索数据总是比访问RAM中的数据慢。However, if the system hosting MongoDB runs out of RAM, swapping can prevent the Linux OOM Killer from terminating the mongod process.然而,如果托管MongoDB的系统内存不足,交换可以阻止Linux OOM Killer终止mongod进程。

Generally, you should choose one of the following swap strategies:通常,您应该选择以下交换策略之一:

  1. Assign swap space on your system, and configure the kernel to only permit swapping under high memory load, or在系统上分配交换空间,并将内核配置为只允许在高内存负载下进行交换,或者
  2. Do not assign swap space on your system, and configure the kernel to disable swapping entirely不要在系统上分配交换空间,并将内核配置为完全禁用交换

See Set vm.swappiness for instructions on configuring swap on your Linux system following these guidelines.请参阅设置vms.wappiness,以获取有关按照这些准则在Linux系统上配置交换的说明。

Note

If your MongoDB instance is hosted on a system that also runs other software, such as a webserver, you should choose the first swap strategy. Do not disable swap in this case. 如果您的MongoDB实例托管在同时运行其他软件(如Web服务器)的系统上,则应选择第一种交换策略。在这种情况下,不要禁用交换。If possible, it is highly recommended that you run MongoDB on its own dedicated system.如果可能的话,强烈建议您在自己的专用系统上运行MongoDB。

RAID

For optimal performance in terms of the storage layer, use disks backed by RAID-10. RAID-5 and RAID-6 do not typically provide sufficient performance to support a MongoDB deployment.为了在存储层方面获得最佳性能,请使用由RAID-10支持的磁盘。RAID-5和RAID-6通常不能提供足够的性能来支持MongoDB部署。

Remote Filesystems (NFS)远程文件系统(NFS)

With the WiredTiger storage engine, WiredTiger objects may be stored on remote file systems if the remote file system conforms to ISO/IEC 9945-1:1996 (POSIX.1). 使用WiredTiger存储引擎,如果远程文件系统符合ISO/IEC 9945-1:1996(POSIX.1),则WiredTige对象可以存储在远程文件系统上。Because remote file systems are often slower than local file systems, using a remote file system for storage may degrade performance.由于远程文件系统通常比本地文件系统慢,因此使用远程文件系统进行存储可能会降低性能。

If you decide to use NFS, add the following NFS options to your /etc/fstab file:如果您决定使用NFS,请将以下NFS选项添加到/etc/fstab文件中:

  • bg
  • hard
  • nolock
  • noatime
  • nointr

Depending on your kernel version, some of these values may already be set as the default. Consult your platform's documentation for more information.根据您的内核版本,其中一些值可能已经设置为默认值。有关详细信息,请参阅您的平台文档。

Separate Components onto Different Storage Devices将组件分离到不同的存储设备上

For improved performance, consider separating your database's data, journal, and logs onto different storage devices, based on your application's access and write pattern. 为了提高性能,请考虑根据应用程序的访问和写入模式,将数据库的数据、日志和日志分离到不同的存储设备上。Mount the components as separate filesystems and use symbolic links to map each component's path to the device storing it.将组件装载为单独的文件系统,并使用符号链接将每个组件的路径映射到存储它的设备。

For the WiredTiger storage engine, you can also store the indexes on a different storage device. 对于WiredTiger存储引擎,您还可以将索引存储在不同的存储设备上。See storage.wiredTiger.engineConfig.directoryForIndexes.请参阅storage.wiredTiger.engineConfig.directoryForIndexes

Note

Using different storage devices will affect your ability to create snapshot-style backups of your data, since the files will be on different devices and volumes.使用不同的存储设备会影响您创建数据快照式备份的能力,因为文件将位于不同的设备和卷上。

Scheduling日程安排

Scheduling for Virtual or Cloud Hosted Devices虚拟或云托管设备的计划

For local block devices attached to a virtual machine instance via the hypervisor or hosted by a cloud hosting provider, the guest operating system should use a noop scheduler for best performance. 对于通过虚拟机监控程序连接到虚拟机实例或由云托管提供商托管的本地块设备,来宾操作系统应使用noop调度器以获得最佳性能。The noop scheduler allows the operating system to defer I/O scheduling to the underlying hypervisor.noop调度程序允许操作系统将I/O调度推迟到底层系统管理程序。

Scheduling for Physical Servers物理服务器的计划

For physical servers, the operating system should use a deadline scheduler. 对于物理服务器,操作系统应该使用截止日期调度程序。The deadline scheduler caps maximum latency per request and maintains a good disk throughput that is best for disk-intensive database applications.截止日期调度程序限制了每个请求的最大延迟,并保持了良好的磁盘吞吐量,这最适合磁盘密集型数据库应用程序。

Architecture体系结构

Replica Sets复制集

See the Replica Set Architectures document for an overview of architectural considerations for replica set deployments.有关复制副本集部署的体系结构注意事项的概述,请参阅复制副本集体系结构文档。

Sharded Clusters分片集群

See Sharded Cluster Production Architecture for an overview of recommended sharded cluster architectures for production deployments.有关推荐用于生产部署的分片集群体系结构的概述,请参阅分片集群生产体系结构

Tip

See also: 另请参阅:

Development Checklist开发检查表

Compression压缩

WiredTiger can compress collection data using one of the following compression library:WiredTiger可以使用以下压缩库之一压缩采集数据:

snappy
Provides a lower compression rate than zlib or zstd but has a lower CPU cost than either.提供比zlibzstd更低的压缩率,但CPU成本比两者都低。
zlib
Provides better compression rate than snappy but has a higher CPU cost than both snappy and zstd.提供比snappy更好的压缩率,但CPU成本比snappyzstd都高。
zstd
Provides better compression rate than both snappy and zlib and has a lower CPU cost than zlib.提供比snappyzlib更好的压缩率,并且CPU成本比zlib更低。

By default, WiredTiger uses snappy compression library. 默认情况下,WiredTiger使用snappy压缩库。To change the compression setting, see storage.wiredTiger.collectionConfig.blockCompressor.要更改压缩设置,请参阅storage.wiredTiger.collectionConfig.blockCompressor

WiredTiger uses prefix compression on all indexes by default.WiredTiger默认情况下对所有索引使用前缀压缩

Clock Synchronization时钟同步

MongoDB components keep logical clocks for supporting time-dependent operations. MongoDB组件保持逻辑时钟,以支持与时间相关的操作。Using NTP to synchronize host machine clocks mitigates the risk of clock drift between components. 使用NTP同步主机时钟可以降低组件之间时钟漂移的风险。Clock drift between components increases the likelihood of incorrect or abnormal behavior of time-dependent operations like the following:组件之间的时钟漂移增加了时间相关操作出现错误或异常行为的可能性,如以下情况:

  • If the underlying system clock of any given MongoDB component drifts a year or more from other components in the same deployment, communication between those members may become unreliable or halt altogether.如果任何给定MongoDB组件的底层系统时钟与同一部署中的其他组件相差一年或更长时间,那么这些成员之间的通信可能会变得不可靠或完全停止。

    The maxAcceptableLogicalClockDriftSecs parameter controls the amount of acceptable clock drift between components. maxAcceptableLogicalClockDriftSecs参数控制组件之间可接受的时钟漂移量。Clusters with a lower value of maxAcceptableLogicalClockDriftSecs have a correspondingly lower tolerance for clock drift.maxAcceptableLogicalClockDriftSecs值较低的集群对时钟漂移的容忍度相应较低。

  • Two cluster members with different system clocks may return different values for operations that return the current cluster or system time, such as Date(), NOW, and CLUSTER_TIME.具有不同系统时钟的两个集群成员可能会为返回当前集群或系统时间的操作返回不同的值,例如Date()NOWCLUSTER_TIME
  • Features which rely on timekeeping may have inconsistent or unpredictable behavior in clusters with clock drift between MongoDB components.依赖于计时的功能在集群中可能具有不一致或不可预测的行为,MongoDB组件之间的时钟漂移。

Platform Specific Considerations平台特定注意事项

MongoDB on LinuxLinux上的MongoDB

Kernel and File Systems内核和文件系统

When running MongoDB in production on Linux, you should use Linux kernel version 2.6.36 or later, with either the XFS or EXT4 filesystem. 当在Linux上的生产环境中运行MongoDB时,您应该使用Linux内核2.6.36或更高版本,以及XFS或EXT4文件系统。If possible, use XFS as it generally performs better with MongoDB.如果可能的话,使用XFS,因为它通常在MongoDB中表现更好。

With the WiredTiger storage engine, using XFS is strongly recommended for data bearing nodes to avoid performance issues that may occur when using EXT4 with WiredTiger.对于WiredTiger存储引擎强烈建议数据承载节点使用XFS,以避免将EXT4与WiredTigeer一起使用时可能出现的性能问题。

  • In general, if you use the XFS file system, use at least version 2.6.25 of the Linux Kernel.通常,如果使用XFS文件系统,则至少要使用2.6.25版本的Linux内核。
  • If you use the EXT4 file system, use at least version 2.6.28 of the Linux Kernel.如果使用EXT4文件系统,请至少使用2.6.28版本的Linux内核。
  • On Red Hat Enterprise Linux and CentOS, use at least version 2.6.18-194 of the Linux kernel.在Red Hat Enterprise Linux和CentOS上,请至少使用2.6.18-194版本的Linux内核。

System C LibrarySystem C库

MongoDB uses the GNU C Library (glibc) on Linux. MongoDB在Linux上使用GNU C库(glibc)。Generally, each Linux distro provides its own vetted version of this library. 一般来说,每个Linux发行版都提供这个库的经过审查的版本。For best results, use the latest update available for this system-provided version. 为了获得最佳效果,请使用此系统提供的版本的最新更新。You can check whether you have the latest version installed by using your system's package manager. 您可以使用系统的软件包管理器检查是否安装了最新版本。For example:例如:

  • On RHEL / CentOS, the following command updates the system-provided GNU C Library:在RHEL/CNTOS上,以下命令更新系统提供的GNU C库:

    sudo yum update glibc
  • On Ubuntu / Debian, the following command updates the system-provided GNU C Library:在Ubuntu/Debian上,以下命令更新系统提供的GNU C库:

    sudo apt-get install libc6

fsync() on Directories关于目录

Important

MongoDB requires a filesystem that supports fsync() on directories. MongoDB需要一个在目录上支持fsync()的文件系统。For example, HGFS and Virtual Box's shared folders do not support this operation.例如,HGFS和Virtual Box的共享文件夹支持此操作。

Set vm.swappiness to 1 or 0

“Swappiness” is a Linux kernel setting that influences the behavior of the Virtual Memory manager. “Swappiness”是影响虚拟内存管理器行为的Linux内核设置。The vm.swappiness setting ranges from 0 to 100: the higher the value, the more strongly it prefers swapping memory pages to disk over dropping pages from RAM.

  • A setting of 0 disables swapping entirely [7].
  • A setting of 1 permits the kernel to swap only to avoid out-of-memory problems.
  • A setting of 60 tells the kernel to swap to disk often, and is the default value on many Linux distributions.
  • A setting of 100 tells the kernel to swap aggressively to disk.

MongoDB performs best where swapping can be avoided or kept to a minimum. As such you should set vm.swappiness to either 1 or 0 depending on your application needs and cluster configuration.MongoDB在可以避免或尽量减少交换的地方表现最好。因此,您应该根据应用程序需求和集群配置将vm.swappiness设置为10

[7] With Linux kernel versions previous to 3.5, or RHEL / CentOS kernel versions previous to 2.6.32-303, a vm.swappiness setting of 0 would still allow the kernel to swap in certain emergency situations.
Note

If your MongoDB instance is hosted on a system that also runs other software, such as a webserver, you should set vm.swappiness to 1. 如果您的MongoDB实例托管在同时运行其他软件(如Web服务器)的系统上,则应将vm.swappiness设置为1If possible, it is highly recommended that you run MongoDB on its own dedicated system.如果可能的话,强烈建议您在自己的专用系统上运行MongoDB。

  • To check the current swappiness setting on your system, run:要检查系统上的当前摇摆度设置,请运行:

    cat /proc/sys/vm/swappiness
  • To change swappiness on your system:要更改系统的时髦度,请执行以下操作:

    1. Edit the /etc/sysctl.conf file and add the following line:编辑/etc/sysctl.conf文件并添加以下行:

      vm.swappiness = 1
    2. Run the following command to apply the setting:运行以下命令以应用设置:

      sudo sysctl -p
Note

If you are running RHEL / CentOS and using a tuned performance profile, you must also edit your chosen profile to set vm.swappiness to 1 or 0.

Recommended Configuration推荐配置

For all MongoDB deployments:对于所有MongoDB部署:

  • Use the Network Time Protocol (NTP) to synchronize time among your hosts. 使用网络时间协议(NTP)在主机之间同步时间。This is especially important in sharded clusters.这在分片集群中尤为重要。

For the WiredTiger storage engines, consider the following recommendations:

  • Turn off atime for the storage volume containing the database files.
  • Adjust the ulimit settings for your platform according to the recommendations in the ulimit reference. Low ulimit values will negatively affect MongoDB when under heavy use and can lead to failed connections to MongoDB processes and loss of service.

    Note

    Starting in MongoDB 4.4, a startup error is generated if the ulimit value for number of open files is under 64000. 从MongoDB 4.4开始,如果打开文件数的ulimit值低于64000,则会生成启动错误。

  • Disable Transparent Huge Pages. MongoDB performs better with normal (4096 bytes) virtual memory pages. 禁用透明大页面。MongoDB在使用普通(4096字节)虚拟内存页面时表现更好。See Transparent Huge Pages Settings.请参阅透明大页面设置
  • Disable NUMA in your BIOS. If that is not possible, see MongoDB on NUMA Hardware.在BIOS中禁用NUMA。如果这不可能,请参阅NUMA硬件上的MongoDB
  • Configure SELinux for MongoDB if you are not using the default MongoDB directory paths or ports.
    Note

    If you are using SELinux, any MongoDB operation that requires server-side JavaScript will result in segfault errors. Disable Server-Side Execution of JavaScript describes how to disable execution of server-side JavaScript.

For the WiredTiger storage engine:

  • Set the readahead setting between 8 and 32 regardless of storage media type (spinning disk, SSD, etc.).将预读设置设置在8和32之间,而不考虑存储介质类型(旋转磁盘、SSD等)。

    Higher readahead commonly benefits sequential I/O operations. 更高的预读通常有利于顺序I/O操作。Since MongoDB disk access patterns are generally random, using higher readahead settings provides limited benefit or potential performance degradation. 由于MongoDB磁盘访问模式通常是随机的,因此使用更高的预读设置提供的好处有限或潜在的性能下降。As such, for optimal MongoDB performance, set readahead between 8 and 32, unless testing shows a measurable, repeatable, and reliable benefit in a higher readahead value. 因此,为了获得最佳的MongoDB性能,请将预读设置在8到32之间,除非测试显示预读值较高会带来可衡量、可重复和可靠的好处。MongoDB commercial support can provide advice and guidance on alternate readahead configurations.MongoDB的商业支持可以为备用预读配置提供建议和指导。

MongoDB and TLS/SSL LibrariesMongoDB和TLS/SSL库

On Linux platforms, you may observe one of the following statements in the MongoDB log:在Linux平台上,您可能会在MongoDB日志中看到以下语句之一:

<path to TLS/SSL libs>/libssl.so.<version>: no version information available (required by /usr/bin/mongod)
<path to TLS/SSL libs>/libcrypto.so.<version>: no version information available (required by /usr/bin/mongod)

These warnings indicate that the system's TLS/SSL libraries are different from the TLS/SSL libraries that the mongod was compiled against. 这些警告表明系统的TLS/SSL库与mongod编译时使用的TLS/SSL库不同。Typically these messages do not require intervention; however, you can use the following operations to determine the symbol versions that mongod expects:通常,这些信息不需要干预;但是,您可以使用以下操作来确定mongod期望的符号版本:

objdump -T <path to mongod>/mongod | grep " SSL_"
objdump -T <path to mongod>/mongod | grep " CRYPTO_"

These operations will return output that resembles one the of the following lines:这些操作将返回类似于以下行之一的输出:

0000000000000000      DF *UND*       0000000000000000  libssl.so.10 SSL_write
0000000000000000 DF *UND* 0000000000000000 OPENSSL_1.0.0 SSL_write

The last two strings in this output are the symbol version and symbol name. Compare these values with the values returned by the following operations to detect symbol version mismatches:

objdump -T <path to TLS/SSL libs>/libssl.so.1*
objdump -T <path to TLS/SSL libs>/libcrypto.so.1*

This procedure is neither exact nor exhaustive: many symbols used by mongod from the libcrypto library do not begin with CRYPTO_.

MongoDB on Windows

For MongoDB instances using the WiredTiger storage engine, performance on Windows is comparable to performance on Linux.对于使用WiredTiger存储引擎的MongoDB实例,Windows上的性能与Linux上的性能相当。

MongoDB on Virtual Environments

This section describes considerations when running MongoDB in some of the more common virtual environments.本节介绍在一些更常见的虚拟环境中运行MongoDB时的注意事项。

For all platforms, consider Scheduling.对于所有平台,请考虑调度

AWS EC2

There are two performance configurations to consider:有两种性能配置需要考虑:

  • Reproducible performance for performance testing or benchmarking, and性能测试或基准测试的可再现性能,以及
  • Raw maximum performance原始最大性能

To tune performance on EC2 for either configuration, you should:要为任一配置调整EC2的性能,您应该:

  • Enable AWS Enhanced Networking for your instance. Not all instance types support Enhanced Networking.

    To learn more about Enhanced Networking, see to the AWS documentation.

  • Set tcp_keepalive_time to 120.

If you are concerned more about reproducible performance on EC2, you should also:

  • Use provisioned IOPS for the storage, with separate devices for journal and data. Do not use the ephemeral (SSD) storage available on most instance types as their performance changes moment to moment. (The i series is a notable exception, but very expensive.)
  • Disable DVFS and CPU power saving modes.
  • Disable hyperthreading.
    Tip
  • Use numactl to bind memory locality to a single socket.

Azure

Use Premium Storage. Microsoft Azure offers two general types of storage: Standard storage, and Premium storage. MongoDB on Azure has better performance when using Premium storage than it does with Standard storage.

The TCP idle timeout on the Azure load balancer is 240 seconds by default, which can cause it to silently drop connections if the TCP keepalive on your Azure systems is greater than this value. You should set tcp_keepalive_time to 120 to ameliorate this problem.

Note

You will need to restart mongod and mongos processes for new system-wide keepalive settings to take effect.

  • To view the keepalive setting on Linux, use one of the following commands:要在Linux上查看保持活动设置,请使用以下命令之一:
    sysctl net.ipv4.tcp_keepalive_time
    Or:或者:
    cat /proc/sys/net/ipv4/tcp_keepalive_time
    The value is measured in seconds.该值以秒为单位进行测量。
    Note

    Although the setting name includes ipv4, the tcp_keepalive_time value applies to both IPv4 and IPv6.尽管设置名称包括ipv4tcp_keepalive_time值同时适用于ipv4和IPv6。

  • To change the tcp_keepalive_time value, you can use one of the following commands, supplying a <value> in seconds:要更改tcp_keepalive_time值,可以使用以下命令之一,以秒为单位提供<value>
    sudo sysctl -w net.ipv4.tcp_keepalive_time=<value>
    Or:或者:
    echo <value> | sudo tee /proc/sys/net/ipv4/tcp_keepalive_time

    These operations do not persist across system reboots. To persist the setting, add the following line to /etc/sysctl.conf, supplying a <value> in seconds, and reboot the machine:这些操作不会在系统重新启动时持续存在。要保持该设置,请在/etc/sysctl.conf中添加以下行,以秒为单位提供<value>,然后重新启动计算机:

    net.ipv4.tcp_keepalive_time = <value>

    Keepalive values greater than 300 seconds, (5 minutes) will be overridden on mongod and mongos sockets and set to 300 seconds.

  • To view the keepalive setting on Windows, issue the following command:要在Windows上查看保持活动设置,请发出以下命令:
    reg query HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters /v KeepAliveTime
    The registry value is not present by default. The system default, used if the value is absent, is 7200000 milliseconds or 0x6ddd00 in hexadecimal.
  • To change the KeepAliveTime value, use the following command in an Administrator Command Prompt, where <value> is expressed in hexadecimal (e.g. 120000 is 0x1d4c0):

    reg add HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\ /t REG_DWORD /v KeepAliveTime /d <value>

    Windows users should consider the Windows Server Technet Article on KeepAliveTime for more information on setting keepalive for MongoDB deployments on Windows systems. Keepalive values greater than or equal to 600000 milliseconds (10 minutes) will be ignored by mongod and mongos.

VMware

MongoDB is compatible with VMware.MongoDB与VMware兼容。

VMware supports memory overcommitment, where you can assign more memory to your virtual machines than the physical machine has available. When memory is overcommitted, the hypervisor reallocates memory between the virtual machines. VMware's balloon driver (vmmemctl) reclaims the pages that are considered least valuable.

The balloon driver resides inside the guest operating system. When the balloon driver expands, it may induce the guest operating system to reclaim memory from guest applications, which can interfere with MongoDB's memory management and affect MongoDB's performance.

Do not disable the balloon driver and memory overcommitment features. This can cause the hypervisor to use its swap which will affect performance. Instead, map and reserve the full amount of memory for the virtual machine running MongoDB. This ensures that the balloon will not be inflated in the local operating system if there is memory pressure in the hypervisor due to an overcommitted configuration.

Ensure that virtual machines stay on a specific ESX/ESXi host by setting VMware's affinity rules. If you must manually migrate a virtual machine to another host and the mongod instance on the virtual machine is the primary, you must first step down the primary and then shut down the instance.

Follow the networking best practices for vMotion and the VMKernel. Failure to follow the best practices can result in performance problems and affect replica set and sharded cluster high availability mechanisms.

It is possible to clone a virtual machine running MongoDB. You might use this function to spin up a new virtual host to add as a member of a replica set. If you clone a VM with journaling enabled, the clone snapshot will be valid. If not using journaling, first stop mongod, then clone the VM, and finally, restart mongod.

KVM

MongoDB is compatible with KVM.

KVM supports memory overcommitment, where you can assign more memory to your virtual machines than the physical machine has available. When memory is overcommitted, the hypervisor reallocates memory between the virtual machines. KVM's balloon driver reclaims the pages that are considered least valuable.

The balloon driver resides inside the guest operating system. When the balloon driver expands, it may induce the guest operating system to reclaim memory from guest applications, which can interfere with MongoDB's memory management and affect MongoDB's performance.

Do not disable the balloon driver and memory overcommitment features. This can cause the hypervisor to use its swap which will affect performance. Instead, map and reserve the full amount of memory for the virtual machine running MongoDB. This ensures that the balloon will not be inflated in the local operating system if there is memory pressure in the hypervisor due to an overcommitted configuration.

Performance Monitoring

iostat

On Linux, use the iostat command to check if disk I/O is a bottleneck for your database. Specify a number of seconds when running iostat to avoid displaying stats covering the time since server boot.

For example, the following command will display extended statistics and the time for each displayed report, with traffic in MB/s, at one second intervals:

iostat -xmt 1

Key fields from iostat:

  • %util: this is the most useful field for a quick check, it indicates what percent of the time the device/drive is in use.
  • avgrq-sz: average request size. Smaller number for this value reflect more random IO operations.

bwm-ng

bwm-ng is a command-line tool for monitoring network use. If you suspect a network-based bottleneck, you may use bwm-ng to begin your diagnostic process.

Backups

To make backups of your MongoDB database, please refer to MongoDB Backup Methods Overview.