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 开发时, 我们避免不了与数据库打交道. 当并发量低的时候, 不会有任何问题. 但一旦并发量达到一定数量, 就会导致 数据库的连接数会被瞬时占满. 这将导致 ...
随机推荐
- Codeforces Round #277.5 (Div. 2)
题目链接:http://codeforces.com/contest/489 A:SwapSort In this problem your goal is to sort an array cons ...
- vertical sync
these days, I am compelting vertical sync https://msdn.microsoft.com/zh-cn/library/windows/desktop/b ...
- eclipse中本地项目怎么和svn中的项目关联?
网速不好,通过别的方式把项目下载到本地硬盘,然后导入eclipse,代码修改后怎么提交到svn呢? 这个纠结了好久的问题... 首先要确定eclipse中安装了svn插件. 然后在“svn资源库研究” ...
- js实用功能
//日期格式转换 Date.prototype.format = function (format) { /* * eg:format="yyyy-MM-dd hh:mm: ...
- JavaScript 文件上传类型判断
文件上传时用到一个功能,使用html元素的input标签实现, <input id="imageFile" name="imageFile1" accep ...
- Sqli-labs less 30
Less-30 Less-30与less-29原理是一致的,我们可以看到less-30的sql语句为: 所以payload为: http://127.0.0.1:8080/sqli-labs/Less ...
- DB2学习
1.为了使用ORG_ID,由于OCRM_F_MM_MKT_PLAN a 没有ORG_ID,但是OCRM_F_MM_EXECUTE_INST_DESC d 表里面有,可以使a表连接b表,创建临时表t. ...
- <?php $sql = <<<EOF 。。。。EOF;?>这种写法是什么意思
php里$sql = <<<EOF //有这样的语法??????//sql语句EOF;运行mysql_query($sql)?>这是什么语法?变量声明可以这样的结构?请解答,谢 ...
- 二、Android NDK编程预备之Java jni入门Hello World
转自: http://www.eoeandroid.com/forum.php?mod=viewthread&tid=264543&fromuid=588695 昨天已经简要介绍了J ...
- pku 1182(种类并查集)
题目链接:http://poj.org/problem?id=1182 解题思路来自discuss:http://poj.org/showmessage?message_id=152847 #incl ...