Django persistent database connection

后端 未结 6 512
太阳男子
太阳男子 2020-11-28 18:22

I\'m using django with apache and mod_wsgi and PostgreSQL (all on same host), and I need to handle a lot of simple dynamic page requests (hundreds per second). I faced with

6条回答
  •  一整个雨季
    2020-11-28 18:56

    Disclaimer: I have not tried this.

    I believe you need to implement a custom database back end. There are a few examples on the web that shows how to implement a database back end with connection pooling.

    Using a connection pool would probably be a good solution for you case, as the network connections are kept open when connections are returned to the pool.

    • This post accomplishes this by patching Django (one of the comments points out that it is better to implement a custom back end outside of the core django code)
    • This post is an implementation of a custom db back end

    Both posts use MySQL - perhaps you are able to use similar techniques with Postgresql.

    Edit:

    • The Django Book mentions Postgresql connection pooling, using pgpool (tutorial).
    • Someone posted a patch for the psycopg2 backend that implements connection pooling. I suggest creating a copy of the existing back end in your own project and patching that one.

提交回复
热议问题