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;

MongoDB点滴的更多相关文章

  1. java 对mongodb的操作

    java 对mongodb的操作 1.1连单台mongodb Mongo mg = newMongo();//默认连本机127.0.0.1  端口为27017 Mongo mg = newMongo( ...

  2. java下执行mongodb

    1.1连单台mongodb Mongo mg = newMongo();//默认连本机127.0.0.1  端口为27017 Mongo mg = newMongo(ip);//可以指定ip 端口默认 ...

  3. 创新手机游戏《3L》开发点滴(3)——道具、物品、装备表设计 V2(最终版)

    我们正在开发一款新手游,里面有道具,之前也写了一篇博文记录了下我们的设计思路,但是国庆到了,于是我有了时间继续纠结这个问题. 其实我主要是在到底是用mysql还是mongodb上纠结.这个复杂.痛苦. ...

  4. MongoDB 分片规则

    每日一句 生命本身毫无意义,只有死亡才能让你邃晓人性的真谛! 每日一句 Ideal is the beacon. Without ideal, there is no secure direction ...

  5. MongoDB 常用启动参数

    每日一句 Once you choose your way of life, be brave to stick it out and never return. 生活的道路一旦选定,就要勇敢地走到底 ...

  6. MongoDB 体系结构与数据模型

    每日一句 If no one else guards the world, then I will come forward. 如果没有别人保卫这个世界,那么我将挺身而出. 概述 MongoDB主要是 ...

  7. MongoDB 各项命名规范

    每日一句 Progress is the result of a bunch of failures. 进步是不断失败的成果. 概述 MongoDB涉及到的一些比如集合啥的命令规范. 集合的命名规范 ...

  8. MongoDB 主节点的选举原则

    每日一句 Life is like a shower. One wrong turn and you're in hot water. 生活就像淋浴,方向转错,水深火热. 概述 MongoDB在副本集 ...

  9. MongoDB 分片集群

    每日一句 Medalist don't grow on trees, you have to nurture them with love, with hard work, with dedicati ...

随机推荐

  1. PHP ftp_put() 函数

    定义和用法 ftp_put() 函数上传本地一个文件到 FTP 服务器上. 如果成功,该函数返回 TRUE.如果失败,则返回 FALSE. 语法 ftp_put(ftp_connection,remo ...

  2. Windows注册表的学习

    什么是注册表 注册表是Windows在Win95/98系统开始引入的一种核心数据库,里面存放着各类的配置信息.参数等.直接控制着系统的启动.硬件的装载以及Winodws程序的运行 手册表的功能 记录用 ...

  3. ionic学习使用笔记(一) 版本更新及创建项目时遇到的问题解决

    最近开始用ionic开发项目,虽然去年的时候用ionic 2.0 开发过公司的项目,不过现在的ionic已经升级到了ionic framework 3.0 了.而且还有个 ionic-cli . 使用 ...

  4. js滚动到顶部底部代码

    <!DOCTYPE HTML> <html> <head> <meta charset=UTF-8> <title>SCROLL</t ...

  5. php开发面试题---Linux常用命令大全

    php开发面试题---Linux常用命令大全 一.总结 一句话总结: ls 查看目录中的文件 cd .. 返回上一级目录 cat 查看文件内容 touch 新建文件或修改时间 1.linux 系统信息 ...

  6. kmalloc vs vmalloc

    kmalloc分配物理上连续的空间,可以不是整页大小的. vmalloc分配逻辑上连接的空间,可以不是物理上连接的.

  7. PAT_A1016#Phone Bills

    Source: PAT A1016 Phone Bills (25 分) Description: A long-distance telephone company charges its cust ...

  8. 20140725 快速排序时间复杂度 sTL入门

    1.快速排序的时间复杂度(平均时间复杂度为) 数组本身就有序时,效果很差为O(n^2) 2.STl入门 (1) C++内联函数(inline)和C中宏(#define)区别 内联函数有类型检查,宏定义 ...

  9. WSGI是什么?

    WSGI是什么? WSGI,全称 Web Server Gateway Interface,或者 Python Web Server Gateway Interface ,是为 Python 语言定义 ...

  10. 并发编程之Android中AsyncTask使用详解(四)

    更多Android高级架构进阶视频免费学习请点击:[https://space.bilibili.com/474380680] 在Android中我们可以通过Thread+Handler实现多线程通信 ...