python DBUtils.PooledDB 中 maxcached 和 maxconnections
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的更多相关文章
- Python数据库连接池DBUtils.PooledDB
DBUtils 是一套用于管理数据库连接池的包,为高频度高并发的数据库访问提供更好的性能,可以自动管理连接对象的创建和释放.最常用的两个外部接口是 PersistentDB 和 PooledDB,前者 ...
- Python DBUtils 连接池对象 (PooledDB)
数据处理框架用到 mysql, 需要在多进程中的多线程中使用 mysql 的连接 使用到的模块: DBUtils 实现: 使用 DBUtils 中的 PooledDB 类来实现. 自己写一个类, 继承 ...
- Python DBUtils
1 简介 DBUtils是一套Python数据库连接池包,并允许对非线程安全的数据库接口进行线程安全包装.DBUtils来自Webware for Python. DBUtils提供两种外部接口: P ...
- python DBUtils 线程池 连接 Postgresql(多线程公用线程池,DB-API : psycopg2)
一.DBUtils DBUtils 是一套允许线程化 Python 程序可以安全和有效的访问数据库的模块,DBUtils提供两种外部接口: PersistentDB :提供线程专用的数据库连接,并自动 ...
- python - DBUtils 连接池减少oracle数据库的连接数
问题: 接到需求,告知项目的oracle连接次数过多,对系统造成太过大的负担,要求减少oracle数据库的连接次数 分析: 仔细分析代码以后,发现产生问题的原因,在于之前要求提升oracle监控的监控 ...
- 使用Python将Excel中的数据导入到MySQL
使用Python将Excel中的数据导入到MySQL 工具 Python 2.7 xlrd MySQLdb 安装 Python 对于不同的系统安装方式不同,Windows平台有exe安装包,Ubunt ...
- 【python】类中的self
在python的类中,经常会写self,代表对象自己.如下例: #coding=utf-8 class Foo: def __init__(self, name): self.name = name ...
- paip.编程语言方法重载实现的原理及python,php,js中实现方法重载
paip.编程语言方法重载实现的原理及python,php,js中实现方法重载 有些语言,在方法的重载上,形式上不支持函数重载,但可以通过模拟实现.. 主要原理:根据参数个数进行重载,或者使用默认值 ...
- 关于python多线程编程中join()和setDaemon()的一点儿探究
关于python多线程编程中join()和setDaemon()的用法,这两天我看网上的资料看得头晕脑涨也没看懂,干脆就做一个实验来看看吧. 首先是编写实验的基础代码,创建一个名为MyThread的 ...
随机推荐
- React基础知识
学习文档(按优先级排列)http://reactjs.cn/react/docs/tutorial-zh-CN.htmlhttp://www.cnblogs.com/Mrs-cc/p/4969755. ...
- Memcached telnet端命令
Command Description Example get Reads a value get mykey set Set a key unconditionally set mykey 0 60 ...
- 内存溢出VS内存泄漏
内存溢出是指用户在对其数据缓冲区操作时,超过了其缓冲区的边界,尤其是对缓冲区进行写操作缓冲区的溢出很可能导致程序的异常. 内存泄露是指程序在运行过程中动态申请的内存空间不再使用后没有及时释放,从而很可 ...
- XRecyclerView Scrapped or attached views may not be recycled
将XRecyclerView布局设置为 android:layout_width="match_parent"android:layout_height="match_p ...
- 利用python合并两个文件
1格式如下 在做利用zabbix的api来批量添加主机的时候,需要处理ip和hostname,在借用别人写的py程序的基础上,自己有改装了以下脚本,为自己使用.需要时ip和hostname为一个统一格 ...
- 基于Spring4+Hibernate4的通用数据访问层+业务逻辑层(Dao层+Service层)设计与实现!
基于泛型的依赖注入.当我们的项目中有很多的Model时,相应的Dao(DaoImpl),Service(ServiceImpl)也会增多. 而我们对这些Model的操作很多都是类似的,下面是我举出的一 ...
- PyQt 自定义信号带参数
import sys from PyQt5.QtCore import pyqtSignal, QObject from PyQt5.QtWidgets import QMainWindow, QAp ...
- 如何判断自己的VPS是那种虚拟技术实现的
我们知道VPS的虚拟技术有许多种,如Openvz.Xen.VMware vSphere.Hyper-V.KVM及Xen的HVM与PV等.在Xen中pv是半虚拟化,hvm是全虚拟化,pv只能用于linu ...
- BZOJ3209 花神的数论题
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...
- js 时间戳转换成几分钟前,几小时前,几天前
formatMsgTime (timespan) { var dateTime = new Date(timespan); var year = dateTime.getFullYear(); var ...