psycopg2.pool – Connections pooling / psycopg2.pool – 连接池 / postgresql 连接池
创建新的PostgreSQL连接可以是一个昂贵的操作。这个模块提供了一些纯Python类直接在客户端应用程序实现简单的连接池。
class psycopg2.pool.AbstractConnectionPool(minconn, maxconn, *args, **kwargs)
基类实现通用的基于密钥池代码。
自动创建新的minconn连接。池将支持的最大maxconn连接。* args,* * kwargs传递到connect()函数。
以下预计将由子类实现方法:
getconn(key=None)
得到一个空连接,并将其分配给key如果不是没有。
putconn(conn, key=None, close=False)
put away 一个连接。
如果关闭是真的,则放弃池中的连接。
closeall()
关闭池处理的所有连接。
请注意所有的连接都关闭,包括最终在应用程序中使用的连接。
下面的类,子类可以使用abstractconnectionpool。
class psycopg2.pool.SimpleConnectionPool(minconn, maxconn, *args, **kwargs)
不能在不同线程中共享的连接池。
请注意,这个池类仅用于单线程应用程序。
class psycopg2.pool.ThreadedConnectionPool(minconn, maxconn, *args, **kwargs)
一个连接池与线程模块一起工作。
注意这个 池 类 可以安全地应用在多线程应用程序中。
class psycopg2.pool.PersistentConnectionPool(minconn, maxconn, *args, **kwargs)
分配给不同线程的持久连接的池。
注意,这个连接池产生本身所需要的密钥使用当前线程ID。这意味着,直到一个线程把连接将永远得到一个相同的连接对象的连续getconn() calls。这也意味着一个线程不能使用从池中的一个以上的单个连接。
注意: 这个连接池类主要被设计去和Zope连接 ,在一些通用的应用程序中很可能不是实用的
下面是源代码
psycopg2.pool – Connections pooling
Creating new PostgreSQL connections can be an expensive operation. This module offers a few pure Python classes implementing simple connection pooling directly in the client application. class psycopg2.pool.AbstractConnectionPool(minconn, maxconn, *args, **kwargs)
Base class implementing generic key-based pooling code. New minconn connections are created automatically. The pool will support a maximum of about maxconn connections. *args and **kwargs are passed to the connect() function. The following methods are expected to be implemented by subclasses: getconn(key=None)
Get a free connection and assign it to key if not None. putconn(conn, key=None, close=False)
Put away a connection. If close is True, discard the connection from the pool. closeall()
Close all the connections handled by the pool. Note that all the connections are closed, including ones eventually in use by the application. The following classes are AbstractConnectionPool subclasses ready to be used. class psycopg2.pool.SimpleConnectionPool(minconn, maxconn, *args, **kwargs)
A connection pool that can’t be shared across different threads. Note This pool class is useful only for single-threaded applications.
class psycopg2.pool.ThreadedConnectionPool(minconn, maxconn, *args, **kwargs)
A connection pool that works with the threading module. Note This pool class can be safely used in multi-threaded applications.
class psycopg2.pool.PersistentConnectionPool(minconn, maxconn, *args, **kwargs)
A pool that assigns persistent connections to different threads. Note that this connection pool generates by itself the required keys using the current thread id. This means that until a thread puts away a connection it will always get the same connection object by successive getconn() calls. This also means that a thread can’t use more than one single connection from the pool. Note This pool class is mostly designed to interact with Zope and probably not useful in generic applications.
Previous topic
psycopg2.pool – Connections pooling / psycopg2.pool – 连接池 / postgresql 连接池的更多相关文章
- 帆软报表FineReport中数据连接的JDBC连接池属性问题
连接池原理 在帆软报表FineReport中,连接池主要由三部分组成:连接池的建立.连接池中连接使用的治理.连接池的关闭.下面就着重讨论这三部分及连接池的配置问题. 1. 连接池原理 连接池技术的核心 ...
- 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 数据库连接不释放测试 连接池 释放连接 关闭连接 有关 redis-py 连接池会导致服务器产生大量 CLOSE_WAIT 的再讨论以及一个解决方案
import pymysqlfrom redis import Redisimport time h, pt, u, p, db = '192.168.2.210', 3306, 'root', 'n ...
- commons-pool与commons-pool2连接池(Hadoop连接池)
commons-pool和commons-pool2是用来建立对象池的框架,提供了一些将对象池化必须要实现的接口和一些默认动作.对象池化之后可以通过pool的概念去管理其生命周期,例如对象的创建,使用 ...
- JDBC连接池-自定义连接池
JDBC连接池 java JDBC连接中用到Connection 在每次对数据进行增删查改 都要 开启 .关闭 ,在实例开发项目中 ,浪费了很大的资源 ,以下是之前连接JDBC的案例 pack ...
- Http持久连接与HttpClient连接池
一.背景 HTTP协议是无状态的协议,即每一次请求都是互相独立的.因此它的最初实现是,每一个http请求都会打开一个tcp socket连接,当交互完毕后会关闭这个连接. HTTP协议是全双工的协议, ...
- Http 持久连接与 HttpClient 连接池
一.背景 HTTP协议是无状态的协议,即每一次请求都是互相独立的.因此它的最初实现是,每一个http请求都会打开一个tcp socket连接,当交互完毕后会关闭这个连接. HTTP协议是全双工的协议, ...
- Mysql线程池系列一:什么是线程池和连接池( thread_pool 和 connection_pool)
thread_pool 和 connection_pool 当客户端请求的数据量比较大的时候,使用线程池可以节约大量的系统资源,使得更多的CPU时间和内存可以高效地利用起来.而数据库连接池的使用 ...
- (转)WebSphere 中池资源调优 - 线程池、连接池和 ORB
WebSphere 中池资源调优 - 线程池.连接池和 ORB 来自:https://www.ibm.com/developerworks/cn/websphere/library/techartic ...
- django更换ORM连接处理(连接池)转
1 概述 在使用 Django 进行 Web 开发时, 我们避免不了与数据库打交道. 当并发量低的时候, 不会有任何问题. 但一旦并发量达到一定数量, 就会导致 数据库的连接数会被瞬时占满. 这将导致 ...
随机推荐
- OpenSSL 1.0.0生成p12、jks、crt等格式证书的命令个过程(转)
OpenSSL 1.0.0生成p12.jks.crt等格式证书的命令个过程 此生成的证书可用于浏览器.java.tomcat.c++等.在此备忘! 1.创建根证私钥命令:openssl g ...
- 深入理解python之self
首先明确的是self只有在类的方法中才会有,独立的函数或方法是不必带有self的.self在定义类的方法时是必须有的,虽然在调用时不必传入相应的参数. self名称不是必须的,在python中self ...
- 跨站点端口攻击 – XSPA(SSPA)
许多Web应用程序提供的功能将数据从其他Web服务器,由于种种原因.下载XML提要,从远程服务器,Web应用程序可以使用用户指定的URL,获取图像,此功能可能会被滥用,使制作的查询使用易受攻击的Web ...
- UML建模类型(转载)
区分UML模型, UML建模用于不同类型的不同的图.有三个重要类型的UML建模: 结构建模: 系统结构建模捕捉静态功能.它们包括下列各项: 类图 对象图 部署图 包图 复合结构图 组件图 结构模型代表 ...
- python 小试牛刀之信息管理
这个是之前写的半成品,但是一直没有好好的写完,今晚我把它补充完整,并且贴出了遇到的问题 这个程序并没有处理中文,主要是python 2.7对于中文的支持太蛋疼了,虽然可以设置utf8编码,但是如果列表 ...
- Ajax HTML, JS
Ajax Request HTML <script></script>及外部的js文件,都需要 var scriptStrs = response.match(/\<[\ ...
- Linux 双线策略路由的三种实现方式总结+端口映射
Linux 双线策略路由的三种实现方式总结+端口映射 Linux 双线策略路由的三种实现方式总结+端口映射 网络环境 服务器(网关): eth0 为LAN口,IP为 LAN_IP = 192.168. ...
- 开源搜索引擎Solr的快速搭建及集成到企业门户最佳实施方案--转载
笔者经过研究查阅solr官方相关资料经过两周的研究实现了毫秒级百万数据的搜索引擎的搭建并引入到企业门户.现将实施心得和步骤分享一下. 1. jdk1.6 安装jdk1.6到系统默认目录下X: ...
- 40页PPT告诉你真正的"互联网+"
点这里 40页PPT告诉你真正的"互联网+" 2015-04-06 网站分析公会 超过50万名互联网从业人士关注 互联网运营领域最具影响力自媒体 本文根据和君赵大伟关于互联网思维大 ...
- 深入浅出ES6(十一):生成器 Generators,续篇
作者 Jason Orendorff github主页 https://github.com/jorendorff 欢迎回到深入浅出ES6专栏,望你在ES6探索之旅中收获知识与快乐!程序员们在工作 ...