MongoDB点滴

0 http://blog.csdn.net/mydeman/article/details/6652387

1 MongoDB 内置连接池,不需要使用额外的连接池驱动

Note: The Mongo object instance actually represents a pool of connections to the database; you will only need one object of class Mongo even with multiple threads.  See the concurrency doc page for more information.

The Mongo class is designed to be thread safe and shared among threads. Typically you create only 1 instance for a given DB cluster and use it across your app. If for some reason you decide to create many mongo intances, note that:

  • all resource usage limits (max connections, etc) apply per mongo instance
  • to dispose of an instance, make sure you call mongo.close() to clean up resource

2 连接池配置如下:

  内置连接池有多个重要参数,分别是:

    • 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 ;

 

 

 

 

转载于:https://www.cnblogs.com/dogharry/p/4453754.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值