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.

最新文章

  1. [资料分享]Java35期基础班和就业班
  2. [skill] 进程 线程
  3. Logstash学习-plugin安装
  4. cell当中的按钮如何获得cell内容
  5. mysql主从复制(超简单)
  6. nodejs学习笔记<一>安装及环境搭建
  7. halcon,C# 学习
  8. linux取出某几行
  9. 纯CSS3实现的图片滑块程序,效果非常酷
  10. smarty实现缓存
  11. Java C# MD5 加密串一致性
  12. MVC-@html.ActionLink的几种参数格式
  13. Android - 硬件抽象层(HAL)
  14. Java中如何判断当前环境是大端字节顺序还是小端字节顺序
  15. mysql 索引管理原则
  16. js兼容性大全
  17. Android代码混淆和项目宣布步骤记录器
  18. List之Distinct()
  19. 记一次解决curl https证书问题
  20. 13.Linux键盘驱动 (详解)

热门文章

  1. Opencv 改进的外接矩形合并拼接方法
  2. SWF代码分析与破解之路 (YueTai VIP视频信息获取工具) Socket续篇
  3. mysql创建还原点
  4. Cadence SPB 16. 6 安装步骤
  5. caffe搭建--vs2015+caffe+python3.5编译环境的搭建
  6. Oracle比较时间大小
  7. STL_算法_查找算法(find、find_if)
  8. jquery 效果网址分享
  9. 解读OC中的load和initialize
  10. 51 NOD 1753 相似子串 字符串hash