python-MySQL学习笔记-第六章-Connector/Python连接池(Connection Pooling)

本文介绍了Python的MySQL Connector/Python库中连接池的使用,包括连接池的特性,如线程安全、配置连接池大小、命名及管理多个连接池。连接池在资源紧张时会抛出PoolError异常,且不支持对单个连接的重新配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. MySQL Connector/Python 1.1.1 and up supports simple connection pooling that has these characteristics

  2. 自1.1.1版本后就支持简单的连接池了,下面是它所具有的特性

    • The mysql.connector.pooling module implements pooling. 

    • mysql.connector.pooling 模块继承了pooling模块

    • A pool opens a number of connections and handles thread safety when providing connections to

      requesters.

    • 当为请求者提供连接的时候,连接池会打开大量的连接并且会处理线程安全

    • The size of a connection pool is configurable at pool creation time. It cannot be resized thereafter.

    • 连接池的大小在连接池创建的时候是可以指明的,这点跟python的进程池操作一致,而且在创建以后大小不能再被更改

    • A connection pool can be named at pool creation time. If no name is given, one is generated using the connection parameters.

    • 在连接池创建的时候可以给其命名,否则,它会用连接参数生成一个名字

    • The connection pool name can be retrieved from the connection pool or connections obtained from it.

    • 连接池的名字可以从连接池中取回或者从和它建立的连接那里得到

    • It is possible to have multiple connection pools. This enables applications to support pools of connections to different MySQL servers, for example.

    • 你可以应用多个连接池,比如:这可以使应用可以支持不同的MySQL服务器的连接池

    • For each connection request, the pool provides the next available connection. No round-robin or other scheduling algorithm is used. If a pool is exhausted, a PoolError is raised.

    • 对每一个不同的连接请求,连接池都提供了下一个可用的连接,并没有应用轮询或者调度算法,如果一个进程池连接耗尽了,它会报出一个PoolError异常

    • It is possible to reconfigure the connection parameters used by a pool. These apply to connections obtained from the pool thereafter. Reconfiguring individual connections obtained from the pool by calling the connection config() method is not supported.

      Applications that can benefit from connection-pooling capability include: 你的应用可以从连接池的包含的方法中受益

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值