Tuning Your Connection Pool Settings调整连接池设置
On this page本页内容
connectTimeoutMS to ensure the driver does not wait indefinitely during the connection phase.connectTimeoutMS 确保驱动程序在连接阶段不会无限期等待。connectTimeoutMS to a value greater than the longest network latency you have to a member of the set.connectTimeoutMS 设置为一个值,该值大于该集成员的最长网络延迟。connectTimeoutMS to 5000 (milliseconds) prevents the driver from connecting to that member. connectTimeoutMS 设置为5000 (毫秒)将阻止驱动程序连接到该成员。 | |
socketTimeoutMS to ensure that sockets are always closed.socketTimeoutMS 确保套接字始终处于关闭状态。socketTimeoutMS to two or three times the length of the slowest operation that the driver runs. socketTimeoutMS 设置为驱动程序运行的最慢操作长度的两到三倍。 | |
minPoolSize .minPoolSize 在池中分配连接。minPoolSize 设置为您希望在启动时可用的连接数。MongoClient instance ensures that number of connections exists at all times. MongoClient 实例确保在任何时候都存在一定数量的连接。 | |
maxPoolSize ,或增加应用程序或正在使用的框架中的活动线程数。 | |
maxPoolSize 或减少线程数。 |
Do not use 不要使用socketTimeoutMS
to prevent long-running server operations. socketTimeoutMS
来阻止长时间运行的服务器操作。Instead, use 相反,在查询中使用maxTimeMS()
with queries so that the server can cancel long-running operations.maxTimeMS()
,这样服务器就可以取消长时间运行的操作。
Calculate Maximum Number of Connections计算最大连接数
Calculate usage to find the number of operations running for each connection.计算使用率以查找每个连接运行的操作数。
Consider four application servers connecting to a replica set with three members. 考虑四个应用程序服务器连接到一个有三个成员的复制副本集。In this scenario, each of the four application servers creates a connection pool for each replica set member.在这种情况下,四个应用程序服务器中的每一个都为每个复制集成员创建一个连接池。
Calculate the maximum number of connections that are opened by each application server by multiplying 通过将maxPoolSize
by the number of members.maxPoolSize
乘以成员数,计算每个应用程序服务器打开的最大连接数。
Calculate outgoing connections from an application to a three-member replica set:计算从应用程序到三成员复制集的传出连接:
100 (maxPoolSize
default 100
) x 3 (replica set members) = 300 (outgoing connections from the application).
Calculate incoming connections from four application servers to a replica set:
100 (maxPoolSize
default 100
) x 4 (application servers) = 400 (incoming connections to each mongod).