`
fantaxy025025
  • 浏览: 1279056 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类

mongodb 避免Out of semaphores to get db connection error

 
阅读更多

 

参考1: http://blog.csdn.net/JIESA/article/details/49891673

错误描述:com.mongodb.DBPortPool$SemaphoresOut: Out of semaphores to get db

MongoDB 并发测试,报出上述错误。究其原因,是数据库连接数太少,资源耗尽。查看com.mongodb.MongoOptions源代码,其中有 connectionsPerHost和threadsAllowedToBlockForConnectionMultiplier两个重要的属性。

   connectionsPerHost:每个主机的连接数

   threadsAllowedToBlockForConnectionMultiplier:线程队列数,它以上面connectionsPerHost值相乘的结果就是线程队列最大值。如果连接线程排满了队列就会抛出“Out of semaphores to get db”错误。

   connectionsPerHost默认是10,threadsAllowedToBlockForConnectionMultiplier默认是5,也就是线程池有50个连接数可供使用。因此只要将这个属性的值加大就可以避免上述错误。

 

   其它属性设置:

   maxWaitTime:最大等待连接的线程阻塞时间

   connectTimeout:连接超时的毫秒。0是默认和无限

   socketTimeout:socket超时。0是默认和无限

   autoConnectRetry:这个控制是否在一个连接时,系统会自动重试

 

java设置方法:

MongoOptions options = new MongoOptions();
        options.connectionsPerHost = 100;//链接池数量 默认10 。避免Out of semaphores to get db connection error
        options.autoConnectRetry = true;
        options.threadsAllowedToBlockForConnectionMultiplier=5;
        options.slaveOk = true;
        mongo = new Mongo(replicaSetSeeds, options);

 

 参考2:Error using mongodb with java

参考3:【mongodb】Out of semaphores to get db connection

 

d

d

e

e

w

w

 

分享到:
评论

相关推荐

    Big.Data.NoSQL.Architecting.MongoDB.epub

    The book covers the necessary features of MongoDB which is needed to get up to speed in knowing about the database. The book covers details on Architecting, Developing and Administering MongoDB. Big ...

    MongoDB connection timeout(解决方案).md

    MongoDB connection timeout(解决方案).md

    Mastering MongoDB 3.x

    You will get an overview of MongoDB and how to play to its strengths, with relevant use cases. After that, you will learn how to query MongoDB effectively and make use of indexes as much as possible. ...

    MongoDB的JavaScript驱动Narwhal.zip

    var db = new MongoDB.Mongo().getDB("mydb"); var colls = db.getCollectionNames(); colls.forEach(function(el) { print(el); }); var coll = db.getCollection("testCollection"); coll.drop(); var doc = { ...

    MongoDb db.createUser用户权限

    MongoDB 是一个流行的开源文档型数据库,以其灵活性和高性能而受到许多开发者的青睐。在MongoDB中,管理用户权限是数据库安全的重要环节。`db.createUser` 方法就是用于创建具有特定权限的用户的。以下是对 `db....

    Practical MongoDB 无水印破地方 0分

    With so many companies opting for MongoDB as their NoSQL database of choice, there's a need for a practical how-to combined with expert advice for getting the most out of the software. Beginning ...

    Practical MongoDB(Apress,2015)

    Practical Guide to MongoDB: Architecting, Developing, and Administering MongoDB begins with a short introduction to the basics of NoSQL databases and then introduces readers to MongoDB—the leading ...

    MongoDB4.2.21 Linux版本安装包

    8. **安全注意事项**:安装完成后,强烈建议执行`mongo` shell中的`use admin`和`db.runCommand({keyFile:"/path/to/keyfile"})`来启用身份验证,并创建用户账户,以增强安全性。 至此,MongoDB 4.2.21已经在Linux...

    MongoDB与传统DB的异同

    本文将深入探讨MongoDB与传统DB的异同,并解析它们各自的特点。 首先,从架构层面来看,MongoDB摒弃了关系数据库中的表格结构,采用了一种更加灵活的数据模型。在传统DB中,数据以表格形式存储,每个表格有预定义的...

    Mongodb连接池JAVA

    MongoDB是一种流行的开源文档数据库系统,以其灵活性、可扩展性和高性能而受到开发者的青睐。在Java应用程序中,当处理大量并发请求时,有效地管理数据库连接是至关重要的。这就是MongoDB连接池的作用,它能帮助优化...

    The.Definitive.Guide.to.MongoDB.pdf

    《MongoDB:终极指南》是Eelco Plugge、Peter Membrey和Tim Hawkins三位作者共同编写的关于MongoDB数据库的权威指南。本书详细介绍了MongoDB作为一种非关系型(NoSQL)数据库在云计算和桌面计算领域的应用,为读者...

    linux安装mongodb教程

    /usr/local/mongodb/mongodb-linux-2.0.7/bin/mongod --dbpath=/usr/local/mongodb/data/db --logpath=/usr/local/mongodb/mongodb-linux-2.0.7/logs/mongodb.log --logappend --port=27017 --fork 知识点 6:配置...

    MongoDB Basics

    MongoDB Basics, from The Definitive Guide to MongoDB, 2E, shows you how a document-oriented database system differs from a relational database, and how to install and get started using it. You'll ...

    mongodb数据库

    相比于传统的关系型数据库,MongoDB避免了复杂的多表关联,可以在单一文档中存储完整的业务数据,如电影、影评和影评回复,大大减少了数据模型设计的复杂性。 MongoDB的安装过程相对简单,主要步骤包括下载最新稳定...

Global site tag (gtag.js) - Google Analytics