django mysql 连接池,Django数据库连接池

安装

pip install django-db-connection-pool

修改Django的配置文件

# change django.db.backends.mysql to dj_db_conn_pool.backends.mysql:

DATABASES = {

'default': {

...

'ENGINE': 'dj_db_conn_pool.backends.mysql'

...

}

}

连接池选项

# 方式一:

DATABASES = {

'default': {

...

'POOL_OPTIONS' : {

'POOL_SIZE': 10,

'MAX_OVERFLOW': 10

}

...

}

}

# 方式二:

import dj_db_conn_pool

dj_db_conn_pool.setup(pool_size=100, max_overflow=50)

参数介绍

pool_size: The size of the pool to be maintained, defaults to 5. This is the largest number of connections that will be kept persistently in the pool. Note that the pool begins with no connections; once this number of connections is requested, that number of connections will remain. pool_size can be set to 0 to indicate no size limit; to disable pooling, use a :class:~sqlalchemy.pool.NullPool instead.

max_overflow: The maximum overflow size of the pool. When the number of checked-out connections reaches the size set in pool_size, additional connections will be returned up to this limit. When those additional connections are returned to the pool, they are disconnected and discarded. It follows then that the total number of simultaneous connections the pool will allow is pool_size + max_overflow, and the total number of "sleeping" connections the pool will allow is pool_size. max_overflow can be set to -1 to indicate no overflow limit; no limit will be placed on the total number of concurrent connections. Defaults to 10.

标签:数据库,db,number,Django,connections,连接池,overflow,pool,size

来源: https://www.cnblogs.com/wangruixing/p/13030755.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值