Persistent connections CONN_MAX_AGE django
Persistent connections¶
Persistent connections avoid the overhead of re-establishing a connection to the database in each request. They’re controlled by theCONN_MAX_AGE
parameter which defines the maximum lifetime of a connection. It can be set independently for each database.
The default value is 0
, preserving the historical behavior of closing the database connection at the end of each request. To enable persistent connections, set CONN_MAX_AGE
to a positive number of seconds. For unlimited persistent connections, set it to None
.
Connection management¶
Django opens a connection to the database when it first makes a database query. It keeps this connection open and reuses it in subsequent requests. Django closes the connection once it exceeds the maximum age defined by CONN_MAX_AGE
or when it isn’t usable any longer.
In detail, Django automatically opens a connection to the database whenever it needs one and doesn’t have one already — either because this is the first connection, or because the previous connection was closed.
At the beginning of each request, Django closes the connection if it has reached its maximum age. If your database terminates idle connections after some time, you should set CONN_MAX_AGE
to a lower value, so that Django doesn’t attempt to use a connection that has been terminated by the database server. (This problem may only affect very low traffic sites.)
At the end of each request, Django closes the connection if it has reached its maximum age or if it is in an unrecoverable error state. If any database errors have occurred while processing the requests, Django checks whether the connection still works, and closes it if it doesn’t. Thus, database errors affect at most one request; if the connection becomes unusable, the next request gets a fresh connection.
Persistent connections CONN_MAX_AGE django的更多相关文章
- django的mysql设置和mysql服务器闲置时间设置
服务器启动后,每个进程都会主动连接到mysql,要是长时间没有数据交互,mysql会自动断开连接. show variables like '%timeout%'; 闲置连接的超时时间由wait_t ...
- Django (2006, 'MySQL server has gone away') 本地重现与解决
最近我们的Django项目供Java Sofa应用进行tr调用时, 经常会出现一个异常: django.db.utils.OperationalError: (2006, 'MySQL server ...
- psycopg2.pool – Connections pooling / psycopg2.pool – 连接池 / postgresql 连接池
创建新的PostgreSQL连接可以是一个昂贵的操作.这个模块提供了一些纯Python类直接在客户端应用程序实现简单的连接池. class psycopg2.pool.AbstractCon ...
- 一步一步学习SignalR进行实时通信_2_Persistent Connections
原文:一步一步学习SignalR进行实时通信_2_Persistent Connections 一步一步学习SignalR进行实时通信\_2_Persistent Connections Signal ...
- [py]django上线部署-uwsgi+nginx+py3/django1.10
https://github.com/lannyMa/django-uwsgi-nginx.git 单机调试启动-确保项目代码没问题 - 克隆代码进入项目 git clone https://gith ...
- 透明 Transparent connections through HTTP proxies.
透明语境: 5.7层模型中数据链路层:透明传输: 谈谈如何使用Netty开发实现高性能的RPC服务器 - Newland - 博客园 http://www.cnblogs.com/jietang/p/ ...
- Django当中的sql查询
十二:在Django中使用sql 关键字: connection connections transaction insert/create/update/delete/sel ...
- Django API 为 D3 提供数据
在工作中见过有的人即便使用了Django,依然还在采取json或geojson的文件形式为页面提供数据,相当于嵌入数据而非加载.下面是个简单有效的例子: 先从 model.py 开始 # models ...
- Django中常用的那些模块路径
Django中常用的那些模块路径 from django.shortcuts import HttpResponse, render, redirect from django import temp ...
随机推荐
- win10拷贝文件卡顿的问题-竟然是winrar搞的
win10拷贝文件卡顿的问题-竟然是winrar搞的 学习了: http://www.w10zj.com/Win10xy/Win10xf_3378.html 没想到你竟然是这样的WinRAR 去除了s ...
- youtube-dl取代you-get?
以前了解到you-get这个项目,支持超多视频网站下载,不过偶尔会出各种问题. 今天看到依云的博客文章:放弃 you-get,转投 youtube-dl 然后特地看了youtube-dl的支持列表:h ...
- 更改 vux Tabbar TabbarItem标题下方的文字激活时的颜色
步骤一: 打开文件build/webpack.base.conf.js, 找到modeule.exports = vuxLoader, 修改如下(并保存) module.exports = vuxLo ...
- HDOJ题目2089 不要62(数位DP)
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- Irrlicht 3D Engine 笔记系列之 教程4 - Movement
作者: i_dovelemon 日期: 2014 / 12 / 16 来源: CSDN 主题: Event Receiver, Animator, Framerate independent move ...
- mysql: expire_logs_days设置后无效问题
Sina blog - MySQL的 expire_logs_days 和 PURGE MASTER LOGS 无效问题
- C# 利用ICSharpCode.SharpZipLib实现在线加密压缩和解密解压缩 C# 文件压缩加解密
C# 利用ICSharpCode.SharpZipLib实现在线加密压缩和解密解压缩 这里我们选用ICSharpCode.SharpZipLib这个类库来实现我们的需求. 下载地址:http:// ...
- ubuntu + lamp + laravel 环境配置
首先是LAMP 安装顺序是 A(Apache服务器) M(Mysql) P(Php) 安装apache sudo apt-get install apache2 安装mysql sudo apt-g ...
- Java 序列化Serializable具体解释(附具体样例)
Java 序列化Serializable具体解释(附具体样例) 1.什么是序列化和反序列化 Serialization(序列化)是一种将对象以一连串的字节描写叙述的过程:反序列化deserializa ...
- kubernetes高级之pod安全策略
系列目录 什么是pod安全策略 pod安全策略是集群级别的用于控制pod安全相关选项的一种资源.PodSecurityPolicy定义了一系列pod相要进行在系统中必须满足的约束条件,以衣一些默认的约 ...