mongodb连接池参数备忘

  • connectionsPerHost:每个主机的连接数
  • threadsAllowedToBlockForConnectionMultiplier:线程队列数,它以上面 connectionsPerHost值相乘的结果就是线程队列最大值。如果连接线程排满了队列就会抛出“Out of semaphores to get db”错误。
  • maxWaitTime:最大等待连接的线程阻塞时间
  • connectTimeout:连接超时的毫秒。0是默认和无限
  • socketTimeout:socket超时。0是默认和无限
  • autoConnectRetry:这个控制是否在一个连接时,系统会自动重试
MongoOptions opt = mongo.getMongoOptions();
opt.connectionsPerHost = 10 ; //poolsize
opt.threadsAllowedToBlockForConnectionMultiplier = 10 ;
//其他参数类似

Field Summary
 boolean autoConnectRetry  
          If true, the driver will keep trying to connect to the same server in case that the socket cannot be established.
 int connectionsPerHost  
          The maximum number of connections allowed per host for this Mongo instance.
 int connectTimeout  
          The connection timeout in milliseconds.
 DBDecoderFactory dbDecoderFactory  
          Override the DBCallback factory.
 DBEncoderFactory dbEncoderFactory  
          Override the encoding factory.
 String description  
          The description for Mongo  instances created with these options.
 boolean fsync  
          The "fsync" value of the global WriteConcern.
 boolean j  
          The "j" value of the global WriteConcern.
 long maxAutoConnectRetryTime  
          The maximum amount of time in MS to spend retrying to open connection to the same server.
 int maxWaitTime  
          The maximum wait time in ms that a thread may wait for a connection to become available.
 boolean safe  
          If true  the driver will use a WriteConcern of WriteConcern.SAFE for all operations.
 boolean slaveOk  
          Deprecated.  Replaced in MongoDB 2.0/Java Driver 2.7 with ReadPreference.SECONDARY
 SocketFactory socketFactory  
          sets the socket factory for creating sockets to mongod Default is SocketFactory.getDefault()
 boolean socketKeepAlive  
          This flag controls the socket keep alive feature that keeps a connection alive through firewalls Socket.setKeepAlive(boolean)  Default is false.
 int socketTimeout  
          The socket timeout in milliseconds It is used for I/O socket read and write operations Socket.setSoTimeout(int)  Default is 0 and means no timeout.
 int threadsAllowedToBlockForConnectionMultiplier  
          this multiplier, multiplied with the connectionsPerHost setting, gives the maximum number of threads that may be waiting for a connection to become available from the pool.
 int w  
          The "w" value of the global WriteConcern.
 int wtimeout  
          The "wtimeout" value of the global WriteConcern.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值