zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    POJ3070 Fibonacci[矩阵乘法]【学习笔记】
    NOIP模拟赛20161023
    洛谷P2964 [USACO09NOV]硬币的游戏A Coin Game
    Jmeter之Bean shell使用
    jmeter 之 BeanShell PostProcessor跨线程全局变量使用
    详解JMeter函数和变量
    性能测试指标(图表)
    http协议基础(十一)http与https
    http协议进阶(六)代理
    http协议进阶(五)连接管理
  • 原文地址:https://www.cnblogs.com/ExMan/p/10170858.html
Copyright © 2011-2022 走看看