PooledDB 有这么几个参数

  • mincached : the initial number of idle connections in the pool (the default of 0 means no connections are made at startup)

  • maxcached: the maximum number of idle connections in the pool (the default value of 0 or None means unlimited pool size)

  • maxconnections: maximum number of connections generally allowed (the default value of 0 or None means any number of connections)

  • blocking: determines behavior when exceeding the maximum

其中 maxconnections 的描述有点奇怪,它说 generally allowed,为什么是 generally ?

设定 blocking=True,使用 MySQLdb 试验的结果如下:

1. 如果 maxconnections 参数不存在,那么连接数可以无限大,直至打满 mysql

2. 如果 maxcached < maxconnections,那么最大连接数就是 maxconnections, 但是奇怪的是,并不是所有 connections 都被复用了,pool 还是会创建新的连接

3. 如果 maxcached > maxconnections,那么最大连接数就是 maxcached, 同样存在 connections 可以复用但是还是会创建新连接的问题

测试代码

from threading import Thread
from DBUtils.PooledDB import PooledDB
from datetime import datetime
import MySQLdb pool = PooledDB(creator=MySQLdb,
mincached=1,
maxcached=3,
maxconnections=3,
blocking=True,
user="test",
passwd="test",
db="test") def test1(pool):
print("start: %s" % datetime.now())
conn = pool.connection()
print conn
cursor = conn.cursor()
print("select: %s" % datetime.now())
cursor.execute("select sleep(10)")
cursor.close()
conn.close()
print("end: %s" % datetime.now()) def main():
for i in xrange(15):
Thread(target=test1, args=(pool,)).start() if __name__ == "__main__":
main()

python DBUtils.PooledDB 中 maxcached 和 maxconnections的更多相关文章

  1. Python数据库连接池DBUtils.PooledDB

    DBUtils 是一套用于管理数据库连接池的包,为高频度高并发的数据库访问提供更好的性能,可以自动管理连接对象的创建和释放.最常用的两个外部接口是 PersistentDB 和 PooledDB,前者 ...

  2. Python DBUtils 连接池对象 (PooledDB)

    数据处理框架用到 mysql, 需要在多进程中的多线程中使用 mysql 的连接 使用到的模块: DBUtils 实现: 使用 DBUtils 中的 PooledDB 类来实现. 自己写一个类, 继承 ...

  3. Python DBUtils

    1 简介 DBUtils是一套Python数据库连接池包,并允许对非线程安全的数据库接口进行线程安全包装.DBUtils来自Webware for Python. DBUtils提供两种外部接口: P ...

  4. python DBUtils 线程池 连接 Postgresql(多线程公用线程池,DB-API : psycopg2)

    一.DBUtils DBUtils 是一套允许线程化 Python 程序可以安全和有效的访问数据库的模块,DBUtils提供两种外部接口: PersistentDB :提供线程专用的数据库连接,并自动 ...

  5. python - DBUtils 连接池减少oracle数据库的连接数

    问题: 接到需求,告知项目的oracle连接次数过多,对系统造成太过大的负担,要求减少oracle数据库的连接次数 分析: 仔细分析代码以后,发现产生问题的原因,在于之前要求提升oracle监控的监控 ...

  6. 使用Python将Excel中的数据导入到MySQL

    使用Python将Excel中的数据导入到MySQL 工具 Python 2.7 xlrd MySQLdb 安装 Python 对于不同的系统安装方式不同,Windows平台有exe安装包,Ubunt ...

  7. 【python】类中的self

    在python的类中,经常会写self,代表对象自己.如下例: #coding=utf-8 class Foo: def __init__(self, name): self.name = name ...

  8. paip.编程语言方法重载实现的原理及python,php,js中实现方法重载

    paip.编程语言方法重载实现的原理及python,php,js中实现方法重载 有些语言,在方法的重载上,形式上不支持函数重载,但可以通过模拟实现.. 主要原理:根据参数个数进行重载,或者使用默认值 ...

  9. 关于python多线程编程中join()和setDaemon()的一点儿探究

    关于python多线程编程中join()和setDaemon()的用法,这两天我看网上的资料看得头晕脑涨也没看懂,干脆就做一个实验来看看吧. 首先是编写实验的基础代码,创建一个名为MyThread的  ...

随机推荐

  1. 12款经典的白富美型—jquery图片轮播插件—前端开发必备

    图片轮播是网站中的常用功能,用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果.本文向大家推荐12款实用的 jQuery 图片轮播效果插件,帮助你在你的项目中加入一些效果精美 ...

  2. ModernUI教程:独立显示器DPI感知

             独立显示器DPI感知,是在Windows 8.1中新增的特性,这个特性针对拥有多个显示器同时各个显示器的DPI设定又不同的人.对这个新特性做了优化支持的软件能够在一个高DPI的显示器 ...

  3. Linux 下配置php开发环境

    windows下有一键安装的环境很方便,不过现实中常常服务器是linux系统.想要搭建环境怎么搞呢? 边学变发直播博客,不定期更新.

  4. 如何用命令检查Linux服务器性能

    1.查看系统负载 (1)uptime 这个命令可以快速查看机器的负载情况. 在Linux系统中,这些数据表示等待CPU资源的进程和阻塞在不可中断IO进程(进程状态为D)的数量. 命令的输出,load ...

  5. Bioinformatics Glossary

    原文:http://homepages.ulb.ac.be/~dgonze/TEACHING/bioinfo_glossary.html Affine gap costs: A scoring sys ...

  6. MVC复杂模型绑定

    当初遇到业务需求ajax提交一组对象数组到服务器.但是苦于mvc的默认绑定器.绑定不上去.好吧只有靠自己了. 当初就是参考这个大大的博客:http://www.cnblogs.com/xfrog/ar ...

  7. DefaultAnnotationHandlerMapping 和 AnnotationMethodHandlerAdapter 的使用已经过时!

    DefaultAnnotationHandlerMapping 和 AnnotationMethodHandlerAdapter 的使用已经过时! 请使用..spring 3.1 开始我们应该用 Re ...

  8. log4Net控制台输出

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...

  9. ArcGIS将Nodata区设置为0

    两个栅格进行叠加,有时会有一部分没有数据,即用identify点击该区域,Value为NoData,而不是像其他非空区域一样有值.此时注意nodata区域要赋予0值,因为nodata+任何数=noda ...

  10. [Unity3D] Normal map、Diffuse map 和 Speculer map

    Normal map : Normal map (法线贴图) 它的作用是模拟出高模上的一些细节纹理,特别是将高模上的圆滑和粗糙度投射到低模上,让低模也有高模的效果. 因为高模的面数非常多,导入引擎后电 ...