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 开发时, 我们避免不了与数据库打交道. 当并发量低的时候, 不会有任何问题. 但一旦并发量达到一定数量, 就会导致 数据库的连接数会被瞬时占满. 这将导致 ...
随机推荐
- Java compiler level does not match the version of the instal
一.问题描述 新建了一个项目,workspace默认jdk编译版本是1.7的,新建项目使用的是jdk1.5的版本,肯定会报@override错误.这个时候,修改项目的compilor即可. 这时候,你 ...
- mysql Communications link failure,C3p0的参数详解
MySQL默认一个连接空闲8小时候就会自动断开,而这时程序以为连接还能使用,然后在使用的时候就会出现Communications link failure异常. 这时需要进行两步设置,有时候只设置My ...
- VC++之GetLastError()使用说明
VC中GetLastError()获取错误信息的使用 在VC中编写应用程序时,经常需要涉及到错误处理问题.许多函数调用只用TRUE和FALSE来表明函数的运行结果.一旦出现错误,MSDN中往往会指出请 ...
- JS中showModalDialog 详细使用(转)
基本介绍: showModalDialog() (IE 4+ 支持) showModelessDialog() (IE 5+ 支持) window.showModalDial ...
- 一张思维导图说明jQuery的AJAX请求机制
比文字描述清晰多了吧?而且越是复杂的逻辑,思维导图的作用就越大,同时对阅读源码也是一种快捷的方法. 看不清楚的话可以右键,在新标签页中打开图片,或者保存本地.
- 斌哥的 Docker 进阶指南—监控方案的实现
过去的一年中,关于 Docker 的话题从未断过,而如今,从尝试 Docker 到最终决定使用 Docker 的转化率依然在逐步升高,关于 Docker 的讨论更是有增无减.另一方面,大家的注意力也渐 ...
- 在线API文档
http://www.ostools.net/apidocs A Ace akka2.0.2 Android Ant Apache CXF Apache HTTP服务器 ASM字节码操作 AutoCo ...
- 简约的单页应用引擎:sonnyJS
点这里 SonnyJS是一个简约的单页应用引擎和HTML预处理器,旨在帮助开发人员和设计人员创建难以置信的强大和快速的单页网站. 主要特性: 模板嵌套,模板继承 动态同步模板路由(非Ajax) 跨窗口 ...
- C++引用变量(转)
引用变量 c++中引用变量的使用: 定义: int rate=80; int & pt=rate 1.pt 是引用变量,申明引用变量时必须将其初始化.pt 和rate 的值指向相同的内存变量 ...
- MONO常用快捷键
Action Mac OS X Win/Linux 注释代码(//) Cmd + / Ctrl + / 注释代码(/**/) Cmd + Option + / Ctrl + Shift + / 格 ...